]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.3.6-201205191125.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.3.6-201205191125.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 9cd6941..92e68ff 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/thread_info.h b/arch/arm/include/asm/thread_info.h
1461 index d4c24d4..4ac53e8 100644
1462 --- a/arch/arm/include/asm/thread_info.h
1463 +++ b/arch/arm/include/asm/thread_info.h
1464 @@ -141,6 +141,12 @@ extern void vfp_flush_hwstate(struct thread_info *);
1465 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1466 #define TIF_SYSCALL_TRACE 8
1467 #define TIF_SYSCALL_AUDIT 9
1468 +
1469 +/* within 8 bits of TIF_SYSCALL_TRACE
1470 + to meet flexible second operand requirements
1471 +*/
1472 +#define TIF_GRSEC_SETXID 10
1473 +
1474 #define TIF_POLLING_NRFLAG 16
1475 #define TIF_USING_IWMMXT 17
1476 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1477 @@ -156,9 +162,11 @@ extern void vfp_flush_hwstate(struct thread_info *);
1478 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1479 #define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
1480 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1481 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1482
1483 /* Checks for any syscall work in entry-common.S */
1484 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1485 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1486 + _TIF_GRSEC_SETXID)
1487
1488 /*
1489 * Change these and you break ASM code in entry-common.S
1490 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1491 index 2958976..12ccac4 100644
1492 --- a/arch/arm/include/asm/uaccess.h
1493 +++ b/arch/arm/include/asm/uaccess.h
1494 @@ -22,6 +22,8 @@
1495 #define VERIFY_READ 0
1496 #define VERIFY_WRITE 1
1497
1498 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1499 +
1500 /*
1501 * The exception table consists of pairs of addresses: the first is the
1502 * address of an instruction that is allowed to fault, and the second is
1503 @@ -387,8 +389,23 @@ do { \
1504
1505
1506 #ifdef CONFIG_MMU
1507 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1508 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1509 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1510 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1511 +
1512 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1513 +{
1514 + if (!__builtin_constant_p(n))
1515 + check_object_size(to, n, false);
1516 + return ___copy_from_user(to, from, n);
1517 +}
1518 +
1519 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1520 +{
1521 + if (!__builtin_constant_p(n))
1522 + check_object_size(from, n, true);
1523 + return ___copy_to_user(to, from, n);
1524 +}
1525 +
1526 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1527 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1528 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1529 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1530
1531 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1532 {
1533 + if ((long)n < 0)
1534 + return n;
1535 +
1536 if (access_ok(VERIFY_READ, from, n))
1537 n = __copy_from_user(to, from, n);
1538 else /* security hole - plug it */
1539 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1540
1541 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1542 {
1543 + if ((long)n < 0)
1544 + return n;
1545 +
1546 if (access_ok(VERIFY_WRITE, to, n))
1547 n = __copy_to_user(to, from, n);
1548 return n;
1549 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1550 index 5b0bce6..becd81c 100644
1551 --- a/arch/arm/kernel/armksyms.c
1552 +++ b/arch/arm/kernel/armksyms.c
1553 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1554 #ifdef CONFIG_MMU
1555 EXPORT_SYMBOL(copy_page);
1556
1557 -EXPORT_SYMBOL(__copy_from_user);
1558 -EXPORT_SYMBOL(__copy_to_user);
1559 +EXPORT_SYMBOL(___copy_from_user);
1560 +EXPORT_SYMBOL(___copy_to_user);
1561 EXPORT_SYMBOL(__clear_user);
1562
1563 EXPORT_SYMBOL(__get_user_1);
1564 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1565 index 971d65c..cc936fb 100644
1566 --- a/arch/arm/kernel/process.c
1567 +++ b/arch/arm/kernel/process.c
1568 @@ -28,7 +28,6 @@
1569 #include <linux/tick.h>
1570 #include <linux/utsname.h>
1571 #include <linux/uaccess.h>
1572 -#include <linux/random.h>
1573 #include <linux/hw_breakpoint.h>
1574 #include <linux/cpuidle.h>
1575
1576 @@ -273,9 +272,10 @@ void machine_power_off(void)
1577 machine_shutdown();
1578 if (pm_power_off)
1579 pm_power_off();
1580 + BUG();
1581 }
1582
1583 -void machine_restart(char *cmd)
1584 +__noreturn void machine_restart(char *cmd)
1585 {
1586 machine_shutdown();
1587
1588 @@ -517,12 +517,6 @@ unsigned long get_wchan(struct task_struct *p)
1589 return 0;
1590 }
1591
1592 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1593 -{
1594 - unsigned long range_end = mm->brk + 0x02000000;
1595 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1596 -}
1597 -
1598 #ifdef CONFIG_MMU
1599 /*
1600 * The vectors page is always readable from user space for the
1601 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1602 index f5ce8ab..4b73893 100644
1603 --- a/arch/arm/kernel/ptrace.c
1604 +++ b/arch/arm/kernel/ptrace.c
1605 @@ -905,10 +905,19 @@ long arch_ptrace(struct task_struct *child, long request,
1606 return ret;
1607 }
1608
1609 +#ifdef CONFIG_GRKERNSEC_SETXID
1610 +extern void gr_delayed_cred_worker(void);
1611 +#endif
1612 +
1613 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1614 {
1615 unsigned long ip;
1616
1617 +#ifdef CONFIG_GRKERNSEC_SETXID
1618 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1619 + gr_delayed_cred_worker();
1620 +#endif
1621 +
1622 if (why)
1623 audit_syscall_exit(regs);
1624 else
1625 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1626 index a255c39..4a19b25 100644
1627 --- a/arch/arm/kernel/setup.c
1628 +++ b/arch/arm/kernel/setup.c
1629 @@ -109,13 +109,13 @@ struct processor processor __read_mostly;
1630 struct cpu_tlb_fns cpu_tlb __read_mostly;
1631 #endif
1632 #ifdef MULTI_USER
1633 -struct cpu_user_fns cpu_user __read_mostly;
1634 +struct cpu_user_fns cpu_user __read_only;
1635 #endif
1636 #ifdef MULTI_CACHE
1637 -struct cpu_cache_fns cpu_cache __read_mostly;
1638 +struct cpu_cache_fns cpu_cache __read_only;
1639 #endif
1640 #ifdef CONFIG_OUTER_CACHE
1641 -struct outer_cache_fns outer_cache __read_mostly;
1642 +struct outer_cache_fns outer_cache __read_only;
1643 EXPORT_SYMBOL(outer_cache);
1644 #endif
1645
1646 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1647 index f84dfe6..13e94f7 100644
1648 --- a/arch/arm/kernel/traps.c
1649 +++ b/arch/arm/kernel/traps.c
1650 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1651
1652 static DEFINE_RAW_SPINLOCK(die_lock);
1653
1654 +extern void gr_handle_kernel_exploit(void);
1655 +
1656 /*
1657 * This function is protected against re-entrancy.
1658 */
1659 @@ -291,6 +293,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1660 panic("Fatal exception in interrupt");
1661 if (panic_on_oops)
1662 panic("Fatal exception");
1663 +
1664 + gr_handle_kernel_exploit();
1665 +
1666 if (ret != NOTIFY_STOP)
1667 do_exit(SIGSEGV);
1668 }
1669 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1670 index 66a477a..bee61d3 100644
1671 --- a/arch/arm/lib/copy_from_user.S
1672 +++ b/arch/arm/lib/copy_from_user.S
1673 @@ -16,7 +16,7 @@
1674 /*
1675 * Prototype:
1676 *
1677 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1678 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1679 *
1680 * Purpose:
1681 *
1682 @@ -84,11 +84,11 @@
1683
1684 .text
1685
1686 -ENTRY(__copy_from_user)
1687 +ENTRY(___copy_from_user)
1688
1689 #include "copy_template.S"
1690
1691 -ENDPROC(__copy_from_user)
1692 +ENDPROC(___copy_from_user)
1693
1694 .pushsection .fixup,"ax"
1695 .align 0
1696 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1697 index 6ee2f67..d1cce76 100644
1698 --- a/arch/arm/lib/copy_page.S
1699 +++ b/arch/arm/lib/copy_page.S
1700 @@ -10,6 +10,7 @@
1701 * ASM optimised string functions
1702 */
1703 #include <linux/linkage.h>
1704 +#include <linux/const.h>
1705 #include <asm/assembler.h>
1706 #include <asm/asm-offsets.h>
1707 #include <asm/cache.h>
1708 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1709 index d066df6..df28194 100644
1710 --- a/arch/arm/lib/copy_to_user.S
1711 +++ b/arch/arm/lib/copy_to_user.S
1712 @@ -16,7 +16,7 @@
1713 /*
1714 * Prototype:
1715 *
1716 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1717 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1718 *
1719 * Purpose:
1720 *
1721 @@ -88,11 +88,11 @@
1722 .text
1723
1724 ENTRY(__copy_to_user_std)
1725 -WEAK(__copy_to_user)
1726 +WEAK(___copy_to_user)
1727
1728 #include "copy_template.S"
1729
1730 -ENDPROC(__copy_to_user)
1731 +ENDPROC(___copy_to_user)
1732 ENDPROC(__copy_to_user_std)
1733
1734 .pushsection .fixup,"ax"
1735 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1736 index 5c908b1..e712687 100644
1737 --- a/arch/arm/lib/uaccess.S
1738 +++ b/arch/arm/lib/uaccess.S
1739 @@ -20,7 +20,7 @@
1740
1741 #define PAGE_SHIFT 12
1742
1743 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1744 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1745 * Purpose : copy a block to user memory from kernel memory
1746 * Params : to - user memory
1747 * : from - kernel memory
1748 @@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1749 sub r2, r2, ip
1750 b .Lc2u_dest_aligned
1751
1752 -ENTRY(__copy_to_user)
1753 +ENTRY(___copy_to_user)
1754 stmfd sp!, {r2, r4 - r7, lr}
1755 cmp r2, #4
1756 blt .Lc2u_not_enough
1757 @@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1758 ldrgtb r3, [r1], #0
1759 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1760 b .Lc2u_finished
1761 -ENDPROC(__copy_to_user)
1762 +ENDPROC(___copy_to_user)
1763
1764 .pushsection .fixup,"ax"
1765 .align 0
1766 9001: ldmfd sp!, {r0, r4 - r7, pc}
1767 .popsection
1768
1769 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1770 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1771 * Purpose : copy a block from user memory to kernel memory
1772 * Params : to - kernel memory
1773 * : from - user memory
1774 @@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1775 sub r2, r2, ip
1776 b .Lcfu_dest_aligned
1777
1778 -ENTRY(__copy_from_user)
1779 +ENTRY(___copy_from_user)
1780 stmfd sp!, {r0, r2, r4 - r7, lr}
1781 cmp r2, #4
1782 blt .Lcfu_not_enough
1783 @@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1784 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1785 strgtb r3, [r0], #1
1786 b .Lcfu_finished
1787 -ENDPROC(__copy_from_user)
1788 +ENDPROC(___copy_from_user)
1789
1790 .pushsection .fixup,"ax"
1791 .align 0
1792 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1793 index 025f742..8432b08 100644
1794 --- a/arch/arm/lib/uaccess_with_memcpy.c
1795 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1796 @@ -104,7 +104,7 @@ out:
1797 }
1798
1799 unsigned long
1800 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1801 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1802 {
1803 /*
1804 * This test is stubbed out of the main function above to keep
1805 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1806 index 6722627..8f97548c 100644
1807 --- a/arch/arm/mach-omap2/board-n8x0.c
1808 +++ b/arch/arm/mach-omap2/board-n8x0.c
1809 @@ -597,7 +597,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1810 }
1811 #endif
1812
1813 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1814 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1815 .late_init = n8x0_menelaus_late_init,
1816 };
1817
1818 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1819 index 2b2d51c..0127490 100644
1820 --- a/arch/arm/mach-ux500/mbox-db5500.c
1821 +++ b/arch/arm/mach-ux500/mbox-db5500.c
1822 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1823 return sprintf(buf, "0x%X\n", mbox_value);
1824 }
1825
1826 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1827 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1828
1829 static int mbox_show(struct seq_file *s, void *data)
1830 {
1831 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1832 index bb7eac3..3bade16 100644
1833 --- a/arch/arm/mm/fault.c
1834 +++ b/arch/arm/mm/fault.c
1835 @@ -172,6 +172,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1836 }
1837 #endif
1838
1839 +#ifdef CONFIG_PAX_PAGEEXEC
1840 + if (fsr & FSR_LNX_PF) {
1841 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1842 + do_group_exit(SIGKILL);
1843 + }
1844 +#endif
1845 +
1846 tsk->thread.address = addr;
1847 tsk->thread.error_code = fsr;
1848 tsk->thread.trap_no = 14;
1849 @@ -393,6 +400,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1850 }
1851 #endif /* CONFIG_MMU */
1852
1853 +#ifdef CONFIG_PAX_PAGEEXEC
1854 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1855 +{
1856 + long i;
1857 +
1858 + printk(KERN_ERR "PAX: bytes at PC: ");
1859 + for (i = 0; i < 20; i++) {
1860 + unsigned char c;
1861 + if (get_user(c, (__force unsigned char __user *)pc+i))
1862 + printk(KERN_CONT "?? ");
1863 + else
1864 + printk(KERN_CONT "%02x ", c);
1865 + }
1866 + printk("\n");
1867 +
1868 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1869 + for (i = -1; i < 20; i++) {
1870 + unsigned long c;
1871 + if (get_user(c, (__force unsigned long __user *)sp+i))
1872 + printk(KERN_CONT "???????? ");
1873 + else
1874 + printk(KERN_CONT "%08lx ", c);
1875 + }
1876 + printk("\n");
1877 +}
1878 +#endif
1879 +
1880 /*
1881 * First Level Translation Fault Handler
1882 *
1883 @@ -573,6 +607,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1884 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1885 struct siginfo info;
1886
1887 +#ifdef CONFIG_PAX_REFCOUNT
1888 + if (fsr_fs(ifsr) == 2) {
1889 + unsigned int bkpt;
1890 +
1891 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1892 + current->thread.error_code = ifsr;
1893 + current->thread.trap_no = 0;
1894 + pax_report_refcount_overflow(regs);
1895 + fixup_exception(regs);
1896 + return;
1897 + }
1898 + }
1899 +#endif
1900 +
1901 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1902 return;
1903
1904 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1905 index ce8cb19..3ec539d 100644
1906 --- a/arch/arm/mm/mmap.c
1907 +++ b/arch/arm/mm/mmap.c
1908 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1909 if (len > TASK_SIZE)
1910 return -ENOMEM;
1911
1912 +#ifdef CONFIG_PAX_RANDMMAP
1913 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1914 +#endif
1915 +
1916 if (addr) {
1917 if (do_align)
1918 addr = COLOUR_ALIGN(addr, pgoff);
1919 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1920 addr = PAGE_ALIGN(addr);
1921
1922 vma = find_vma(mm, addr);
1923 - if (TASK_SIZE - len >= addr &&
1924 - (!vma || addr + len <= vma->vm_start))
1925 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1926 return addr;
1927 }
1928 if (len > mm->cached_hole_size) {
1929 - start_addr = addr = mm->free_area_cache;
1930 + start_addr = addr = mm->free_area_cache;
1931 } else {
1932 - start_addr = addr = mm->mmap_base;
1933 - mm->cached_hole_size = 0;
1934 + start_addr = addr = mm->mmap_base;
1935 + mm->cached_hole_size = 0;
1936 }
1937
1938 full_search:
1939 @@ -124,14 +127,14 @@ full_search:
1940 * Start a new search - just in case we missed
1941 * some holes.
1942 */
1943 - if (start_addr != TASK_UNMAPPED_BASE) {
1944 - start_addr = addr = TASK_UNMAPPED_BASE;
1945 + if (start_addr != mm->mmap_base) {
1946 + start_addr = addr = mm->mmap_base;
1947 mm->cached_hole_size = 0;
1948 goto full_search;
1949 }
1950 return -ENOMEM;
1951 }
1952 - if (!vma || addr + len <= vma->vm_start) {
1953 + if (check_heap_stack_gap(vma, addr, len)) {
1954 /*
1955 * Remember the place where we stopped the search:
1956 */
1957 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1958
1959 if (mmap_is_legacy()) {
1960 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1961 +
1962 +#ifdef CONFIG_PAX_RANDMMAP
1963 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1964 + mm->mmap_base += mm->delta_mmap;
1965 +#endif
1966 +
1967 mm->get_unmapped_area = arch_get_unmapped_area;
1968 mm->unmap_area = arch_unmap_area;
1969 } else {
1970 mm->mmap_base = mmap_base(random_factor);
1971 +
1972 +#ifdef CONFIG_PAX_RANDMMAP
1973 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1974 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1975 +#endif
1976 +
1977 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1978 mm->unmap_area = arch_unmap_area_topdown;
1979 }
1980 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
1981 index 71a6827..e7fbc23 100644
1982 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
1983 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
1984 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
1985 int (*started)(unsigned ch);
1986 int (*flush)(unsigned ch);
1987 int (*stop)(unsigned ch);
1988 -};
1989 +} __no_const;
1990
1991 extern void *samsung_dmadev_get_ops(void);
1992 extern void *s3c_dma_get_ops(void);
1993 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
1994 index 5f28cae..3d23723 100644
1995 --- a/arch/arm/plat-samsung/include/plat/ehci.h
1996 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
1997 @@ -14,7 +14,7 @@
1998 struct s5p_ehci_platdata {
1999 int (*phy_init)(struct platform_device *pdev, int type);
2000 int (*phy_exit)(struct platform_device *pdev, int type);
2001 -};
2002 +} __no_const;
2003
2004 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2005
2006 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2007 index c3a58a1..78fbf54 100644
2008 --- a/arch/avr32/include/asm/cache.h
2009 +++ b/arch/avr32/include/asm/cache.h
2010 @@ -1,8 +1,10 @@
2011 #ifndef __ASM_AVR32_CACHE_H
2012 #define __ASM_AVR32_CACHE_H
2013
2014 +#include <linux/const.h>
2015 +
2016 #define L1_CACHE_SHIFT 5
2017 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2018 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2019
2020 /*
2021 * Memory returned by kmalloc() may be used for DMA, so we must make
2022 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2023 index 3b3159b..425ea94 100644
2024 --- a/arch/avr32/include/asm/elf.h
2025 +++ b/arch/avr32/include/asm/elf.h
2026 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2027 the loader. We need to make sure that it is out of the way of the program
2028 that it will "exec", and that there is sufficient room for the brk. */
2029
2030 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2031 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2032
2033 +#ifdef CONFIG_PAX_ASLR
2034 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2035 +
2036 +#define PAX_DELTA_MMAP_LEN 15
2037 +#define PAX_DELTA_STACK_LEN 15
2038 +#endif
2039
2040 /* This yields a mask that user programs can use to figure out what
2041 instruction set this CPU supports. This could be done in user space,
2042 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2043 index b7f5c68..556135c 100644
2044 --- a/arch/avr32/include/asm/kmap_types.h
2045 +++ b/arch/avr32/include/asm/kmap_types.h
2046 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2047 D(11) KM_IRQ1,
2048 D(12) KM_SOFTIRQ0,
2049 D(13) KM_SOFTIRQ1,
2050 -D(14) KM_TYPE_NR
2051 +D(14) KM_CLEARPAGE,
2052 +D(15) KM_TYPE_NR
2053 };
2054
2055 #undef D
2056 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2057 index f7040a1..db9f300 100644
2058 --- a/arch/avr32/mm/fault.c
2059 +++ b/arch/avr32/mm/fault.c
2060 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2061
2062 int exception_trace = 1;
2063
2064 +#ifdef CONFIG_PAX_PAGEEXEC
2065 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2066 +{
2067 + unsigned long i;
2068 +
2069 + printk(KERN_ERR "PAX: bytes at PC: ");
2070 + for (i = 0; i < 20; i++) {
2071 + unsigned char c;
2072 + if (get_user(c, (unsigned char *)pc+i))
2073 + printk(KERN_CONT "???????? ");
2074 + else
2075 + printk(KERN_CONT "%02x ", c);
2076 + }
2077 + printk("\n");
2078 +}
2079 +#endif
2080 +
2081 /*
2082 * This routine handles page faults. It determines the address and the
2083 * problem, and then passes it off to one of the appropriate routines.
2084 @@ -156,6 +173,16 @@ bad_area:
2085 up_read(&mm->mmap_sem);
2086
2087 if (user_mode(regs)) {
2088 +
2089 +#ifdef CONFIG_PAX_PAGEEXEC
2090 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2091 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2092 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2093 + do_group_exit(SIGKILL);
2094 + }
2095 + }
2096 +#endif
2097 +
2098 if (exception_trace && printk_ratelimit())
2099 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2100 "sp %08lx ecr %lu\n",
2101 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2102 index 568885a..f8008df 100644
2103 --- a/arch/blackfin/include/asm/cache.h
2104 +++ b/arch/blackfin/include/asm/cache.h
2105 @@ -7,6 +7,7 @@
2106 #ifndef __ARCH_BLACKFIN_CACHE_H
2107 #define __ARCH_BLACKFIN_CACHE_H
2108
2109 +#include <linux/const.h>
2110 #include <linux/linkage.h> /* for asmlinkage */
2111
2112 /*
2113 @@ -14,7 +15,7 @@
2114 * Blackfin loads 32 bytes for cache
2115 */
2116 #define L1_CACHE_SHIFT 5
2117 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2118 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2119 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2120
2121 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2122 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2123 index aea2718..3639a60 100644
2124 --- a/arch/cris/include/arch-v10/arch/cache.h
2125 +++ b/arch/cris/include/arch-v10/arch/cache.h
2126 @@ -1,8 +1,9 @@
2127 #ifndef _ASM_ARCH_CACHE_H
2128 #define _ASM_ARCH_CACHE_H
2129
2130 +#include <linux/const.h>
2131 /* Etrax 100LX have 32-byte cache-lines. */
2132 -#define L1_CACHE_BYTES 32
2133 #define L1_CACHE_SHIFT 5
2134 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2135
2136 #endif /* _ASM_ARCH_CACHE_H */
2137 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2138 index 1de779f..336fad3 100644
2139 --- a/arch/cris/include/arch-v32/arch/cache.h
2140 +++ b/arch/cris/include/arch-v32/arch/cache.h
2141 @@ -1,11 +1,12 @@
2142 #ifndef _ASM_CRIS_ARCH_CACHE_H
2143 #define _ASM_CRIS_ARCH_CACHE_H
2144
2145 +#include <linux/const.h>
2146 #include <arch/hwregs/dma.h>
2147
2148 /* A cache-line is 32 bytes. */
2149 -#define L1_CACHE_BYTES 32
2150 #define L1_CACHE_SHIFT 5
2151 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2152
2153 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2154
2155 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2156 index 0d8a7d6..d0c9ff5 100644
2157 --- a/arch/frv/include/asm/atomic.h
2158 +++ b/arch/frv/include/asm/atomic.h
2159 @@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
2160 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2161 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2162
2163 +#define atomic64_read_unchecked(v) atomic64_read(v)
2164 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2165 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2166 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2167 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2168 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2169 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2170 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2171 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2172 +
2173 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2174 {
2175 int c, old;
2176 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2177 index 2797163..c2a401d 100644
2178 --- a/arch/frv/include/asm/cache.h
2179 +++ b/arch/frv/include/asm/cache.h
2180 @@ -12,10 +12,11 @@
2181 #ifndef __ASM_CACHE_H
2182 #define __ASM_CACHE_H
2183
2184 +#include <linux/const.h>
2185
2186 /* bytes per L1 cache line */
2187 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2188 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2189 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2190
2191 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2192 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2193 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2194 index f8e16b2..c73ff79 100644
2195 --- a/arch/frv/include/asm/kmap_types.h
2196 +++ b/arch/frv/include/asm/kmap_types.h
2197 @@ -23,6 +23,7 @@ enum km_type {
2198 KM_IRQ1,
2199 KM_SOFTIRQ0,
2200 KM_SOFTIRQ1,
2201 + KM_CLEARPAGE,
2202 KM_TYPE_NR
2203 };
2204
2205 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2206 index 385fd30..6c3d97e 100644
2207 --- a/arch/frv/mm/elf-fdpic.c
2208 +++ b/arch/frv/mm/elf-fdpic.c
2209 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2210 if (addr) {
2211 addr = PAGE_ALIGN(addr);
2212 vma = find_vma(current->mm, addr);
2213 - if (TASK_SIZE - len >= addr &&
2214 - (!vma || addr + len <= vma->vm_start))
2215 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2216 goto success;
2217 }
2218
2219 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2220 for (; vma; vma = vma->vm_next) {
2221 if (addr > limit)
2222 break;
2223 - if (addr + len <= vma->vm_start)
2224 + if (check_heap_stack_gap(vma, addr, len))
2225 goto success;
2226 addr = vma->vm_end;
2227 }
2228 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2229 for (; vma; vma = vma->vm_next) {
2230 if (addr > limit)
2231 break;
2232 - if (addr + len <= vma->vm_start)
2233 + if (check_heap_stack_gap(vma, addr, len))
2234 goto success;
2235 addr = vma->vm_end;
2236 }
2237 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2238 index c635028..6d9445a 100644
2239 --- a/arch/h8300/include/asm/cache.h
2240 +++ b/arch/h8300/include/asm/cache.h
2241 @@ -1,8 +1,10 @@
2242 #ifndef __ARCH_H8300_CACHE_H
2243 #define __ARCH_H8300_CACHE_H
2244
2245 +#include <linux/const.h>
2246 +
2247 /* bytes per L1 cache line */
2248 -#define L1_CACHE_BYTES 4
2249 +#define L1_CACHE_BYTES _AC(4,UL)
2250
2251 /* m68k-elf-gcc 2.95.2 doesn't like these */
2252
2253 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2254 index 0f01de2..d37d309 100644
2255 --- a/arch/hexagon/include/asm/cache.h
2256 +++ b/arch/hexagon/include/asm/cache.h
2257 @@ -21,9 +21,11 @@
2258 #ifndef __ASM_CACHE_H
2259 #define __ASM_CACHE_H
2260
2261 +#include <linux/const.h>
2262 +
2263 /* Bytes per L1 cache line */
2264 -#define L1_CACHE_SHIFT (5)
2265 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2266 +#define L1_CACHE_SHIFT 5
2267 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2268
2269 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2270 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2271 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2272 index 3fad89e..3047da5 100644
2273 --- a/arch/ia64/include/asm/atomic.h
2274 +++ b/arch/ia64/include/asm/atomic.h
2275 @@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2276 #define atomic64_inc(v) atomic64_add(1, (v))
2277 #define atomic64_dec(v) atomic64_sub(1, (v))
2278
2279 +#define atomic64_read_unchecked(v) atomic64_read(v)
2280 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2281 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2282 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2283 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2284 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2285 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2286 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2287 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2288 +
2289 /* Atomic operations are already serializing */
2290 #define smp_mb__before_atomic_dec() barrier()
2291 #define smp_mb__after_atomic_dec() barrier()
2292 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2293 index 988254a..e1ee885 100644
2294 --- a/arch/ia64/include/asm/cache.h
2295 +++ b/arch/ia64/include/asm/cache.h
2296 @@ -1,6 +1,7 @@
2297 #ifndef _ASM_IA64_CACHE_H
2298 #define _ASM_IA64_CACHE_H
2299
2300 +#include <linux/const.h>
2301
2302 /*
2303 * Copyright (C) 1998-2000 Hewlett-Packard Co
2304 @@ -9,7 +10,7 @@
2305
2306 /* Bytes per L1 (data) cache line. */
2307 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2308 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2309 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2310
2311 #ifdef CONFIG_SMP
2312 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2313 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2314 index b5298eb..67c6e62 100644
2315 --- a/arch/ia64/include/asm/elf.h
2316 +++ b/arch/ia64/include/asm/elf.h
2317 @@ -42,6 +42,13 @@
2318 */
2319 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2320
2321 +#ifdef CONFIG_PAX_ASLR
2322 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2323 +
2324 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2325 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2326 +#endif
2327 +
2328 #define PT_IA_64_UNWIND 0x70000001
2329
2330 /* IA-64 relocations: */
2331 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2332 index 96a8d92..617a1cf 100644
2333 --- a/arch/ia64/include/asm/pgalloc.h
2334 +++ b/arch/ia64/include/asm/pgalloc.h
2335 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2336 pgd_val(*pgd_entry) = __pa(pud);
2337 }
2338
2339 +static inline void
2340 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2341 +{
2342 + pgd_populate(mm, pgd_entry, pud);
2343 +}
2344 +
2345 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2346 {
2347 return quicklist_alloc(0, GFP_KERNEL, NULL);
2348 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2349 pud_val(*pud_entry) = __pa(pmd);
2350 }
2351
2352 +static inline void
2353 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2354 +{
2355 + pud_populate(mm, pud_entry, pmd);
2356 +}
2357 +
2358 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2359 {
2360 return quicklist_alloc(0, GFP_KERNEL, NULL);
2361 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2362 index 1a97af3..7529d31 100644
2363 --- a/arch/ia64/include/asm/pgtable.h
2364 +++ b/arch/ia64/include/asm/pgtable.h
2365 @@ -12,7 +12,7 @@
2366 * David Mosberger-Tang <davidm@hpl.hp.com>
2367 */
2368
2369 -
2370 +#include <linux/const.h>
2371 #include <asm/mman.h>
2372 #include <asm/page.h>
2373 #include <asm/processor.h>
2374 @@ -143,6 +143,17 @@
2375 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2376 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2377 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2378 +
2379 +#ifdef CONFIG_PAX_PAGEEXEC
2380 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2381 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2382 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2383 +#else
2384 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2385 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2386 +# define PAGE_COPY_NOEXEC PAGE_COPY
2387 +#endif
2388 +
2389 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2390 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2391 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2392 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2393 index b77768d..e0795eb 100644
2394 --- a/arch/ia64/include/asm/spinlock.h
2395 +++ b/arch/ia64/include/asm/spinlock.h
2396 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2397 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2398
2399 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2400 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2401 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2402 }
2403
2404 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2405 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2406 index 449c8c0..432a3d2 100644
2407 --- a/arch/ia64/include/asm/uaccess.h
2408 +++ b/arch/ia64/include/asm/uaccess.h
2409 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2410 const void *__cu_from = (from); \
2411 long __cu_len = (n); \
2412 \
2413 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2414 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2415 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2416 __cu_len; \
2417 })
2418 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2419 long __cu_len = (n); \
2420 \
2421 __chk_user_ptr(__cu_from); \
2422 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2423 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2424 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2425 __cu_len; \
2426 })
2427 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2428 index 24603be..948052d 100644
2429 --- a/arch/ia64/kernel/module.c
2430 +++ b/arch/ia64/kernel/module.c
2431 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2432 void
2433 module_free (struct module *mod, void *module_region)
2434 {
2435 - if (mod && mod->arch.init_unw_table &&
2436 - module_region == mod->module_init) {
2437 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2438 unw_remove_unwind_table(mod->arch.init_unw_table);
2439 mod->arch.init_unw_table = NULL;
2440 }
2441 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2442 }
2443
2444 static inline int
2445 +in_init_rx (const struct module *mod, uint64_t addr)
2446 +{
2447 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2448 +}
2449 +
2450 +static inline int
2451 +in_init_rw (const struct module *mod, uint64_t addr)
2452 +{
2453 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2454 +}
2455 +
2456 +static inline int
2457 in_init (const struct module *mod, uint64_t addr)
2458 {
2459 - return addr - (uint64_t) mod->module_init < mod->init_size;
2460 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2461 +}
2462 +
2463 +static inline int
2464 +in_core_rx (const struct module *mod, uint64_t addr)
2465 +{
2466 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2467 +}
2468 +
2469 +static inline int
2470 +in_core_rw (const struct module *mod, uint64_t addr)
2471 +{
2472 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2473 }
2474
2475 static inline int
2476 in_core (const struct module *mod, uint64_t addr)
2477 {
2478 - return addr - (uint64_t) mod->module_core < mod->core_size;
2479 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2480 }
2481
2482 static inline int
2483 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2484 break;
2485
2486 case RV_BDREL:
2487 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2488 + if (in_init_rx(mod, val))
2489 + val -= (uint64_t) mod->module_init_rx;
2490 + else if (in_init_rw(mod, val))
2491 + val -= (uint64_t) mod->module_init_rw;
2492 + else if (in_core_rx(mod, val))
2493 + val -= (uint64_t) mod->module_core_rx;
2494 + else if (in_core_rw(mod, val))
2495 + val -= (uint64_t) mod->module_core_rw;
2496 break;
2497
2498 case RV_LTV:
2499 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2500 * addresses have been selected...
2501 */
2502 uint64_t gp;
2503 - if (mod->core_size > MAX_LTOFF)
2504 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2505 /*
2506 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2507 * at the end of the module.
2508 */
2509 - gp = mod->core_size - MAX_LTOFF / 2;
2510 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2511 else
2512 - gp = mod->core_size / 2;
2513 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2514 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2515 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2516 mod->arch.gp = gp;
2517 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2518 }
2519 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2520 index 609d500..7dde2a8 100644
2521 --- a/arch/ia64/kernel/sys_ia64.c
2522 +++ b/arch/ia64/kernel/sys_ia64.c
2523 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2524 if (REGION_NUMBER(addr) == RGN_HPAGE)
2525 addr = 0;
2526 #endif
2527 +
2528 +#ifdef CONFIG_PAX_RANDMMAP
2529 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2530 + addr = mm->free_area_cache;
2531 + else
2532 +#endif
2533 +
2534 if (!addr)
2535 addr = mm->free_area_cache;
2536
2537 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2538 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2539 /* At this point: (!vma || addr < vma->vm_end). */
2540 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2541 - if (start_addr != TASK_UNMAPPED_BASE) {
2542 + if (start_addr != mm->mmap_base) {
2543 /* Start a new search --- just in case we missed some holes. */
2544 - addr = TASK_UNMAPPED_BASE;
2545 + addr = mm->mmap_base;
2546 goto full_search;
2547 }
2548 return -ENOMEM;
2549 }
2550 - if (!vma || addr + len <= vma->vm_start) {
2551 + if (check_heap_stack_gap(vma, addr, len)) {
2552 /* Remember the address where we stopped this search: */
2553 mm->free_area_cache = addr + len;
2554 return addr;
2555 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2556 index 53c0ba0..2accdde 100644
2557 --- a/arch/ia64/kernel/vmlinux.lds.S
2558 +++ b/arch/ia64/kernel/vmlinux.lds.S
2559 @@ -199,7 +199,7 @@ SECTIONS {
2560 /* Per-cpu data: */
2561 . = ALIGN(PERCPU_PAGE_SIZE);
2562 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2563 - __phys_per_cpu_start = __per_cpu_load;
2564 + __phys_per_cpu_start = per_cpu_load;
2565 /*
2566 * ensure percpu data fits
2567 * into percpu page size
2568 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2569 index 20b3593..1ce77f0 100644
2570 --- a/arch/ia64/mm/fault.c
2571 +++ b/arch/ia64/mm/fault.c
2572 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2573 return pte_present(pte);
2574 }
2575
2576 +#ifdef CONFIG_PAX_PAGEEXEC
2577 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2578 +{
2579 + unsigned long i;
2580 +
2581 + printk(KERN_ERR "PAX: bytes at PC: ");
2582 + for (i = 0; i < 8; i++) {
2583 + unsigned int c;
2584 + if (get_user(c, (unsigned int *)pc+i))
2585 + printk(KERN_CONT "???????? ");
2586 + else
2587 + printk(KERN_CONT "%08x ", c);
2588 + }
2589 + printk("\n");
2590 +}
2591 +#endif
2592 +
2593 void __kprobes
2594 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2595 {
2596 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2597 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2598 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2599
2600 - if ((vma->vm_flags & mask) != mask)
2601 + if ((vma->vm_flags & mask) != mask) {
2602 +
2603 +#ifdef CONFIG_PAX_PAGEEXEC
2604 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2605 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2606 + goto bad_area;
2607 +
2608 + up_read(&mm->mmap_sem);
2609 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2610 + do_group_exit(SIGKILL);
2611 + }
2612 +#endif
2613 +
2614 goto bad_area;
2615
2616 + }
2617 +
2618 /*
2619 * If for any reason at all we couldn't handle the fault, make
2620 * sure we exit gracefully rather than endlessly redo the
2621 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2622 index 5ca674b..e0e1b70 100644
2623 --- a/arch/ia64/mm/hugetlbpage.c
2624 +++ b/arch/ia64/mm/hugetlbpage.c
2625 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2626 /* At this point: (!vmm || addr < vmm->vm_end). */
2627 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2628 return -ENOMEM;
2629 - if (!vmm || (addr + len) <= vmm->vm_start)
2630 + if (check_heap_stack_gap(vmm, addr, len))
2631 return addr;
2632 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2633 }
2634 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2635 index 13df239d..cb52116 100644
2636 --- a/arch/ia64/mm/init.c
2637 +++ b/arch/ia64/mm/init.c
2638 @@ -121,6 +121,19 @@ ia64_init_addr_space (void)
2639 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2640 vma->vm_end = vma->vm_start + PAGE_SIZE;
2641 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2642 +
2643 +#ifdef CONFIG_PAX_PAGEEXEC
2644 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2645 + vma->vm_flags &= ~VM_EXEC;
2646 +
2647 +#ifdef CONFIG_PAX_MPROTECT
2648 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2649 + vma->vm_flags &= ~VM_MAYEXEC;
2650 +#endif
2651 +
2652 + }
2653 +#endif
2654 +
2655 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2656 down_write(&current->mm->mmap_sem);
2657 if (insert_vm_struct(current->mm, vma)) {
2658 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2659 index 40b3ee9..8c2c112 100644
2660 --- a/arch/m32r/include/asm/cache.h
2661 +++ b/arch/m32r/include/asm/cache.h
2662 @@ -1,8 +1,10 @@
2663 #ifndef _ASM_M32R_CACHE_H
2664 #define _ASM_M32R_CACHE_H
2665
2666 +#include <linux/const.h>
2667 +
2668 /* L1 cache line size */
2669 #define L1_CACHE_SHIFT 4
2670 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2671 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2672
2673 #endif /* _ASM_M32R_CACHE_H */
2674 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2675 index 82abd15..d95ae5d 100644
2676 --- a/arch/m32r/lib/usercopy.c
2677 +++ b/arch/m32r/lib/usercopy.c
2678 @@ -14,6 +14,9 @@
2679 unsigned long
2680 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2681 {
2682 + if ((long)n < 0)
2683 + return n;
2684 +
2685 prefetch(from);
2686 if (access_ok(VERIFY_WRITE, to, n))
2687 __copy_user(to,from,n);
2688 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2689 unsigned long
2690 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2691 {
2692 + if ((long)n < 0)
2693 + return n;
2694 +
2695 prefetchw(to);
2696 if (access_ok(VERIFY_READ, from, n))
2697 __copy_user_zeroing(to,from,n);
2698 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2699 index 0395c51..5f26031 100644
2700 --- a/arch/m68k/include/asm/cache.h
2701 +++ b/arch/m68k/include/asm/cache.h
2702 @@ -4,9 +4,11 @@
2703 #ifndef __ARCH_M68K_CACHE_H
2704 #define __ARCH_M68K_CACHE_H
2705
2706 +#include <linux/const.h>
2707 +
2708 /* bytes per L1 cache line */
2709 #define L1_CACHE_SHIFT 4
2710 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2711 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2712
2713 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2714
2715 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2716 index 4efe96a..60e8699 100644
2717 --- a/arch/microblaze/include/asm/cache.h
2718 +++ b/arch/microblaze/include/asm/cache.h
2719 @@ -13,11 +13,12 @@
2720 #ifndef _ASM_MICROBLAZE_CACHE_H
2721 #define _ASM_MICROBLAZE_CACHE_H
2722
2723 +#include <linux/const.h>
2724 #include <asm/registers.h>
2725
2726 #define L1_CACHE_SHIFT 5
2727 /* word-granular cache in microblaze */
2728 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2729 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2730
2731 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2732
2733 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2734 index 1d93f81..67794d0 100644
2735 --- a/arch/mips/include/asm/atomic.h
2736 +++ b/arch/mips/include/asm/atomic.h
2737 @@ -21,6 +21,10 @@
2738 #include <asm/war.h>
2739 #include <asm/system.h>
2740
2741 +#ifdef CONFIG_GENERIC_ATOMIC64
2742 +#include <asm-generic/atomic64.h>
2743 +#endif
2744 +
2745 #define ATOMIC_INIT(i) { (i) }
2746
2747 /*
2748 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2749 */
2750 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2751
2752 +#define atomic64_read_unchecked(v) atomic64_read(v)
2753 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2754 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2755 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2756 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2757 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2758 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2759 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2760 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2761 +
2762 #endif /* CONFIG_64BIT */
2763
2764 /*
2765 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2766 index b4db69f..8f3b093 100644
2767 --- a/arch/mips/include/asm/cache.h
2768 +++ b/arch/mips/include/asm/cache.h
2769 @@ -9,10 +9,11 @@
2770 #ifndef _ASM_CACHE_H
2771 #define _ASM_CACHE_H
2772
2773 +#include <linux/const.h>
2774 #include <kmalloc.h>
2775
2776 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2777 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2778 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2779
2780 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2781 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2782 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2783 index 455c0ac..ad65fbe 100644
2784 --- a/arch/mips/include/asm/elf.h
2785 +++ b/arch/mips/include/asm/elf.h
2786 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2787 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2788 #endif
2789
2790 +#ifdef CONFIG_PAX_ASLR
2791 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2792 +
2793 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2794 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2795 +#endif
2796 +
2797 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2798 struct linux_binprm;
2799 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2800 int uses_interp);
2801
2802 -struct mm_struct;
2803 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2804 -#define arch_randomize_brk arch_randomize_brk
2805 -
2806 #endif /* _ASM_ELF_H */
2807 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2808 index da9bd7d..91aa7ab 100644
2809 --- a/arch/mips/include/asm/page.h
2810 +++ b/arch/mips/include/asm/page.h
2811 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2812 #ifdef CONFIG_CPU_MIPS32
2813 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2814 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2815 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2816 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2817 #else
2818 typedef struct { unsigned long long pte; } pte_t;
2819 #define pte_val(x) ((x).pte)
2820 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2821 index 881d18b..cea38bc 100644
2822 --- a/arch/mips/include/asm/pgalloc.h
2823 +++ b/arch/mips/include/asm/pgalloc.h
2824 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2825 {
2826 set_pud(pud, __pud((unsigned long)pmd));
2827 }
2828 +
2829 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2830 +{
2831 + pud_populate(mm, pud, pmd);
2832 +}
2833 #endif
2834
2835 /*
2836 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2837 index 6018c80..7c37203 100644
2838 --- a/arch/mips/include/asm/system.h
2839 +++ b/arch/mips/include/asm/system.h
2840 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2841 */
2842 #define __ARCH_WANT_UNLOCKED_CTXSW
2843
2844 -extern unsigned long arch_align_stack(unsigned long sp);
2845 +#define arch_align_stack(x) ((x) & ~0xfUL)
2846
2847 #endif /* _ASM_SYSTEM_H */
2848 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2849 index 0d85d8e..ec71487 100644
2850 --- a/arch/mips/include/asm/thread_info.h
2851 +++ b/arch/mips/include/asm/thread_info.h
2852 @@ -123,6 +123,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2853 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2854 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2855 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2856 +/* li takes a 32bit immediate */
2857 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2858 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2859
2860 #ifdef CONFIG_MIPS32_O32
2861 @@ -146,15 +148,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2862 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2863 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2864 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2865 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2866 +
2867 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2868
2869 /* work to do in syscall_trace_leave() */
2870 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2871 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2872
2873 /* work to do on interrupt/exception return */
2874 #define _TIF_WORK_MASK (0x0000ffef & \
2875 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2876 /* work to do on any return to u-space */
2877 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2878 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2879
2880 #endif /* __KERNEL__ */
2881
2882 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2883 index 9fdd8bc..4bd7f1a 100644
2884 --- a/arch/mips/kernel/binfmt_elfn32.c
2885 +++ b/arch/mips/kernel/binfmt_elfn32.c
2886 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2887 #undef ELF_ET_DYN_BASE
2888 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2889
2890 +#ifdef CONFIG_PAX_ASLR
2891 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2892 +
2893 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2894 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2895 +#endif
2896 +
2897 #include <asm/processor.h>
2898 #include <linux/module.h>
2899 #include <linux/elfcore.h>
2900 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2901 index ff44823..97f8906 100644
2902 --- a/arch/mips/kernel/binfmt_elfo32.c
2903 +++ b/arch/mips/kernel/binfmt_elfo32.c
2904 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2905 #undef ELF_ET_DYN_BASE
2906 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2907
2908 +#ifdef CONFIG_PAX_ASLR
2909 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2910 +
2911 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2912 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2913 +#endif
2914 +
2915 #include <asm/processor.h>
2916
2917 /*
2918 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2919 index 7955409..ceaea7c 100644
2920 --- a/arch/mips/kernel/process.c
2921 +++ b/arch/mips/kernel/process.c
2922 @@ -483,15 +483,3 @@ unsigned long get_wchan(struct task_struct *task)
2923 out:
2924 return pc;
2925 }
2926 -
2927 -/*
2928 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2929 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2930 - */
2931 -unsigned long arch_align_stack(unsigned long sp)
2932 -{
2933 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2934 - sp -= get_random_int() & ~PAGE_MASK;
2935 -
2936 - return sp & ALMASK;
2937 -}
2938 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2939 index 7786b60..3e38c72 100644
2940 --- a/arch/mips/kernel/ptrace.c
2941 +++ b/arch/mips/kernel/ptrace.c
2942 @@ -529,6 +529,10 @@ static inline int audit_arch(void)
2943 return arch;
2944 }
2945
2946 +#ifdef CONFIG_GRKERNSEC_SETXID
2947 +extern void gr_delayed_cred_worker(void);
2948 +#endif
2949 +
2950 /*
2951 * Notification of system call entry/exit
2952 * - triggered by current->work.syscall_trace
2953 @@ -538,6 +542,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2954 /* do the secure computing check first */
2955 secure_computing(regs->regs[2]);
2956
2957 +#ifdef CONFIG_GRKERNSEC_SETXID
2958 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2959 + gr_delayed_cred_worker();
2960 +#endif
2961 +
2962 if (!(current->ptrace & PT_PTRACED))
2963 goto out;
2964
2965 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
2966 index a632bc1..0b77c7c 100644
2967 --- a/arch/mips/kernel/scall32-o32.S
2968 +++ b/arch/mips/kernel/scall32-o32.S
2969 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
2970
2971 stack_done:
2972 lw t0, TI_FLAGS($28) # syscall tracing enabled?
2973 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
2974 + li t1, _TIF_SYSCALL_WORK
2975 and t0, t1
2976 bnez t0, syscall_trace_entry # -> yes
2977
2978 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
2979 index 3b5a5e9..e1ee86d 100644
2980 --- a/arch/mips/kernel/scall64-64.S
2981 +++ b/arch/mips/kernel/scall64-64.S
2982 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
2983
2984 sd a3, PT_R26(sp) # save a3 for syscall restarting
2985
2986 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
2987 + li t1, _TIF_SYSCALL_WORK
2988 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
2989 and t0, t1, t0
2990 bnez t0, syscall_trace_entry
2991 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
2992 index 6be6f70..1859577 100644
2993 --- a/arch/mips/kernel/scall64-n32.S
2994 +++ b/arch/mips/kernel/scall64-n32.S
2995 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
2996
2997 sd a3, PT_R26(sp) # save a3 for syscall restarting
2998
2999 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3000 + li t1, _TIF_SYSCALL_WORK
3001 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3002 and t0, t1, t0
3003 bnez t0, n32_syscall_trace_entry
3004 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3005 index 5422855..74e63a3 100644
3006 --- a/arch/mips/kernel/scall64-o32.S
3007 +++ b/arch/mips/kernel/scall64-o32.S
3008 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3009 PTR 4b, bad_stack
3010 .previous
3011
3012 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3013 + li t1, _TIF_SYSCALL_WORK
3014 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3015 and t0, t1, t0
3016 bnez t0, trace_a_syscall
3017 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3018 index 69ebd58..e4bff83 100644
3019 --- a/arch/mips/mm/fault.c
3020 +++ b/arch/mips/mm/fault.c
3021 @@ -28,6 +28,23 @@
3022 #include <asm/highmem.h> /* For VMALLOC_END */
3023 #include <linux/kdebug.h>
3024
3025 +#ifdef CONFIG_PAX_PAGEEXEC
3026 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3027 +{
3028 + unsigned long i;
3029 +
3030 + printk(KERN_ERR "PAX: bytes at PC: ");
3031 + for (i = 0; i < 5; i++) {
3032 + unsigned int c;
3033 + if (get_user(c, (unsigned int *)pc+i))
3034 + printk(KERN_CONT "???????? ");
3035 + else
3036 + printk(KERN_CONT "%08x ", c);
3037 + }
3038 + printk("\n");
3039 +}
3040 +#endif
3041 +
3042 /*
3043 * This routine handles page faults. It determines the address,
3044 * and the problem, and then passes it off to one of the appropriate
3045 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3046 index 302d779..7d35bf8 100644
3047 --- a/arch/mips/mm/mmap.c
3048 +++ b/arch/mips/mm/mmap.c
3049 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3050 do_color_align = 1;
3051
3052 /* requesting a specific address */
3053 +
3054 +#ifdef CONFIG_PAX_RANDMMAP
3055 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3056 +#endif
3057 +
3058 if (addr) {
3059 if (do_color_align)
3060 addr = COLOUR_ALIGN(addr, pgoff);
3061 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3062 addr = PAGE_ALIGN(addr);
3063
3064 vma = find_vma(mm, addr);
3065 - if (TASK_SIZE - len >= addr &&
3066 - (!vma || addr + len <= vma->vm_start))
3067 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3068 return addr;
3069 }
3070
3071 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3072 /* At this point: (!vma || addr < vma->vm_end). */
3073 if (TASK_SIZE - len < addr)
3074 return -ENOMEM;
3075 - if (!vma || addr + len <= vma->vm_start)
3076 + if (check_heap_stack_gap(vmm, addr, len))
3077 return addr;
3078 addr = vma->vm_end;
3079 if (do_color_align)
3080 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3081 /* make sure it can fit in the remaining address space */
3082 if (likely(addr > len)) {
3083 vma = find_vma(mm, addr - len);
3084 - if (!vma || addr <= vma->vm_start) {
3085 + if (check_heap_stack_gap(vmm, addr - len, len))
3086 /* cache the address as a hint for next time */
3087 return mm->free_area_cache = addr - len;
3088 }
3089 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3090 * return with success:
3091 */
3092 vma = find_vma(mm, addr);
3093 - if (likely(!vma || addr + len <= vma->vm_start)) {
3094 + if (check_heap_stack_gap(vmm, addr, len)) {
3095 /* cache the address as a hint for next time */
3096 return mm->free_area_cache = addr;
3097 }
3098 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3099 mm->unmap_area = arch_unmap_area_topdown;
3100 }
3101 }
3102 -
3103 -static inline unsigned long brk_rnd(void)
3104 -{
3105 - unsigned long rnd = get_random_int();
3106 -
3107 - rnd = rnd << PAGE_SHIFT;
3108 - /* 8MB for 32bit, 256MB for 64bit */
3109 - if (TASK_IS_32BIT_ADDR)
3110 - rnd = rnd & 0x7ffffful;
3111 - else
3112 - rnd = rnd & 0xffffffful;
3113 -
3114 - return rnd;
3115 -}
3116 -
3117 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3118 -{
3119 - unsigned long base = mm->brk;
3120 - unsigned long ret;
3121 -
3122 - ret = PAGE_ALIGN(base + brk_rnd());
3123 -
3124 - if (ret < mm->brk)
3125 - return mm->brk;
3126 -
3127 - return ret;
3128 -}
3129 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3130 index 967d144..db12197 100644
3131 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3132 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3133 @@ -11,12 +11,14 @@
3134 #ifndef _ASM_PROC_CACHE_H
3135 #define _ASM_PROC_CACHE_H
3136
3137 +#include <linux/const.h>
3138 +
3139 /* L1 cache */
3140
3141 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3142 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3143 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3144 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3145 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3146 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3147
3148 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3149 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3150 index bcb5df2..84fabd2 100644
3151 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3152 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3153 @@ -16,13 +16,15 @@
3154 #ifndef _ASM_PROC_CACHE_H
3155 #define _ASM_PROC_CACHE_H
3156
3157 +#include <linux/const.h>
3158 +
3159 /*
3160 * L1 cache
3161 */
3162 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3163 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3164 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3165 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3166 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3167 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3168
3169 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3170 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3171 index 4ce7a01..449202a 100644
3172 --- a/arch/openrisc/include/asm/cache.h
3173 +++ b/arch/openrisc/include/asm/cache.h
3174 @@ -19,11 +19,13 @@
3175 #ifndef __ASM_OPENRISC_CACHE_H
3176 #define __ASM_OPENRISC_CACHE_H
3177
3178 +#include <linux/const.h>
3179 +
3180 /* FIXME: How can we replace these with values from the CPU...
3181 * they shouldn't be hard-coded!
3182 */
3183
3184 -#define L1_CACHE_BYTES 16
3185 #define L1_CACHE_SHIFT 4
3186 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3187
3188 #endif /* __ASM_OPENRISC_CACHE_H */
3189 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3190 index 4054b31..a10c105 100644
3191 --- a/arch/parisc/include/asm/atomic.h
3192 +++ b/arch/parisc/include/asm/atomic.h
3193 @@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3194
3195 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3196
3197 +#define atomic64_read_unchecked(v) atomic64_read(v)
3198 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3199 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3200 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3201 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3202 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3203 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3204 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3205 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3206 +
3207 #endif /* !CONFIG_64BIT */
3208
3209
3210 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3211 index 47f11c7..3420df2 100644
3212 --- a/arch/parisc/include/asm/cache.h
3213 +++ b/arch/parisc/include/asm/cache.h
3214 @@ -5,6 +5,7 @@
3215 #ifndef __ARCH_PARISC_CACHE_H
3216 #define __ARCH_PARISC_CACHE_H
3217
3218 +#include <linux/const.h>
3219
3220 /*
3221 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3222 @@ -15,13 +16,13 @@
3223 * just ruin performance.
3224 */
3225 #ifdef CONFIG_PA20
3226 -#define L1_CACHE_BYTES 64
3227 #define L1_CACHE_SHIFT 6
3228 #else
3229 -#define L1_CACHE_BYTES 32
3230 #define L1_CACHE_SHIFT 5
3231 #endif
3232
3233 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3234 +
3235 #ifndef __ASSEMBLY__
3236
3237 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3238 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3239 index 19f6cb1..6c78cf2 100644
3240 --- a/arch/parisc/include/asm/elf.h
3241 +++ b/arch/parisc/include/asm/elf.h
3242 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3243
3244 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3245
3246 +#ifdef CONFIG_PAX_ASLR
3247 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3248 +
3249 +#define PAX_DELTA_MMAP_LEN 16
3250 +#define PAX_DELTA_STACK_LEN 16
3251 +#endif
3252 +
3253 /* This yields a mask that user programs can use to figure out what
3254 instruction set this CPU supports. This could be done in user space,
3255 but it's not easy, and we've already done it here. */
3256 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3257 index fc987a1..6e068ef 100644
3258 --- a/arch/parisc/include/asm/pgalloc.h
3259 +++ b/arch/parisc/include/asm/pgalloc.h
3260 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3261 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3262 }
3263
3264 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3265 +{
3266 + pgd_populate(mm, pgd, pmd);
3267 +}
3268 +
3269 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3270 {
3271 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3272 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3273 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3274 #define pmd_free(mm, x) do { } while (0)
3275 #define pgd_populate(mm, pmd, pte) BUG()
3276 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3277
3278 #endif
3279
3280 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3281 index 22dadeb..f6c2be4 100644
3282 --- a/arch/parisc/include/asm/pgtable.h
3283 +++ b/arch/parisc/include/asm/pgtable.h
3284 @@ -210,6 +210,17 @@ struct vm_area_struct;
3285 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3286 #define PAGE_COPY PAGE_EXECREAD
3287 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3288 +
3289 +#ifdef CONFIG_PAX_PAGEEXEC
3290 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3291 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3292 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3293 +#else
3294 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3295 +# define PAGE_COPY_NOEXEC PAGE_COPY
3296 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3297 +#endif
3298 +
3299 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3300 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3301 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3302 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3303 index 5e34ccf..672bc9c 100644
3304 --- a/arch/parisc/kernel/module.c
3305 +++ b/arch/parisc/kernel/module.c
3306 @@ -98,16 +98,38 @@
3307
3308 /* three functions to determine where in the module core
3309 * or init pieces the location is */
3310 +static inline int in_init_rx(struct module *me, void *loc)
3311 +{
3312 + return (loc >= me->module_init_rx &&
3313 + loc < (me->module_init_rx + me->init_size_rx));
3314 +}
3315 +
3316 +static inline int in_init_rw(struct module *me, void *loc)
3317 +{
3318 + return (loc >= me->module_init_rw &&
3319 + loc < (me->module_init_rw + me->init_size_rw));
3320 +}
3321 +
3322 static inline int in_init(struct module *me, void *loc)
3323 {
3324 - return (loc >= me->module_init &&
3325 - loc <= (me->module_init + me->init_size));
3326 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3327 +}
3328 +
3329 +static inline int in_core_rx(struct module *me, void *loc)
3330 +{
3331 + return (loc >= me->module_core_rx &&
3332 + loc < (me->module_core_rx + me->core_size_rx));
3333 +}
3334 +
3335 +static inline int in_core_rw(struct module *me, void *loc)
3336 +{
3337 + return (loc >= me->module_core_rw &&
3338 + loc < (me->module_core_rw + me->core_size_rw));
3339 }
3340
3341 static inline int in_core(struct module *me, void *loc)
3342 {
3343 - return (loc >= me->module_core &&
3344 - loc <= (me->module_core + me->core_size));
3345 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3346 }
3347
3348 static inline int in_local(struct module *me, void *loc)
3349 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3350 }
3351
3352 /* align things a bit */
3353 - me->core_size = ALIGN(me->core_size, 16);
3354 - me->arch.got_offset = me->core_size;
3355 - me->core_size += gots * sizeof(struct got_entry);
3356 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3357 + me->arch.got_offset = me->core_size_rw;
3358 + me->core_size_rw += gots * sizeof(struct got_entry);
3359
3360 - me->core_size = ALIGN(me->core_size, 16);
3361 - me->arch.fdesc_offset = me->core_size;
3362 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3363 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3364 + me->arch.fdesc_offset = me->core_size_rw;
3365 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3366
3367 me->arch.got_max = gots;
3368 me->arch.fdesc_max = fdescs;
3369 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3370
3371 BUG_ON(value == 0);
3372
3373 - got = me->module_core + me->arch.got_offset;
3374 + got = me->module_core_rw + me->arch.got_offset;
3375 for (i = 0; got[i].addr; i++)
3376 if (got[i].addr == value)
3377 goto out;
3378 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3379 #ifdef CONFIG_64BIT
3380 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3381 {
3382 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3383 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3384
3385 if (!value) {
3386 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3387 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3388
3389 /* Create new one */
3390 fdesc->addr = value;
3391 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3392 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3393 return (Elf_Addr)fdesc;
3394 }
3395 #endif /* CONFIG_64BIT */
3396 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3397
3398 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3399 end = table + sechdrs[me->arch.unwind_section].sh_size;
3400 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3401 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3402
3403 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3404 me->arch.unwind_section, table, end, gp);
3405 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3406 index c9b9322..02d8940 100644
3407 --- a/arch/parisc/kernel/sys_parisc.c
3408 +++ b/arch/parisc/kernel/sys_parisc.c
3409 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3410 /* At this point: (!vma || addr < vma->vm_end). */
3411 if (TASK_SIZE - len < addr)
3412 return -ENOMEM;
3413 - if (!vma || addr + len <= vma->vm_start)
3414 + if (check_heap_stack_gap(vma, addr, len))
3415 return addr;
3416 addr = vma->vm_end;
3417 }
3418 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3419 /* At this point: (!vma || addr < vma->vm_end). */
3420 if (TASK_SIZE - len < addr)
3421 return -ENOMEM;
3422 - if (!vma || addr + len <= vma->vm_start)
3423 + if (check_heap_stack_gap(vma, addr, len))
3424 return addr;
3425 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3426 if (addr < vma->vm_end) /* handle wraparound */
3427 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3428 if (flags & MAP_FIXED)
3429 return addr;
3430 if (!addr)
3431 - addr = TASK_UNMAPPED_BASE;
3432 + addr = current->mm->mmap_base;
3433
3434 if (filp) {
3435 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3436 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3437 index f19e660..414fe24 100644
3438 --- a/arch/parisc/kernel/traps.c
3439 +++ b/arch/parisc/kernel/traps.c
3440 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3441
3442 down_read(&current->mm->mmap_sem);
3443 vma = find_vma(current->mm,regs->iaoq[0]);
3444 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3445 - && (vma->vm_flags & VM_EXEC)) {
3446 -
3447 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3448 fault_address = regs->iaoq[0];
3449 fault_space = regs->iasq[0];
3450
3451 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3452 index 18162ce..94de376 100644
3453 --- a/arch/parisc/mm/fault.c
3454 +++ b/arch/parisc/mm/fault.c
3455 @@ -15,6 +15,7 @@
3456 #include <linux/sched.h>
3457 #include <linux/interrupt.h>
3458 #include <linux/module.h>
3459 +#include <linux/unistd.h>
3460
3461 #include <asm/uaccess.h>
3462 #include <asm/traps.h>
3463 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3464 static unsigned long
3465 parisc_acctyp(unsigned long code, unsigned int inst)
3466 {
3467 - if (code == 6 || code == 16)
3468 + if (code == 6 || code == 7 || code == 16)
3469 return VM_EXEC;
3470
3471 switch (inst & 0xf0000000) {
3472 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3473 }
3474 #endif
3475
3476 +#ifdef CONFIG_PAX_PAGEEXEC
3477 +/*
3478 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3479 + *
3480 + * returns 1 when task should be killed
3481 + * 2 when rt_sigreturn trampoline was detected
3482 + * 3 when unpatched PLT trampoline was detected
3483 + */
3484 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3485 +{
3486 +
3487 +#ifdef CONFIG_PAX_EMUPLT
3488 + int err;
3489 +
3490 + do { /* PaX: unpatched PLT emulation */
3491 + unsigned int bl, depwi;
3492 +
3493 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3494 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3495 +
3496 + if (err)
3497 + break;
3498 +
3499 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3500 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3501 +
3502 + err = get_user(ldw, (unsigned int *)addr);
3503 + err |= get_user(bv, (unsigned int *)(addr+4));
3504 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3505 +
3506 + if (err)
3507 + break;
3508 +
3509 + if (ldw == 0x0E801096U &&
3510 + bv == 0xEAC0C000U &&
3511 + ldw2 == 0x0E881095U)
3512 + {
3513 + unsigned int resolver, map;
3514 +
3515 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3516 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3517 + if (err)
3518 + break;
3519 +
3520 + regs->gr[20] = instruction_pointer(regs)+8;
3521 + regs->gr[21] = map;
3522 + regs->gr[22] = resolver;
3523 + regs->iaoq[0] = resolver | 3UL;
3524 + regs->iaoq[1] = regs->iaoq[0] + 4;
3525 + return 3;
3526 + }
3527 + }
3528 + } while (0);
3529 +#endif
3530 +
3531 +#ifdef CONFIG_PAX_EMUTRAMP
3532 +
3533 +#ifndef CONFIG_PAX_EMUSIGRT
3534 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3535 + return 1;
3536 +#endif
3537 +
3538 + do { /* PaX: rt_sigreturn emulation */
3539 + unsigned int ldi1, ldi2, bel, nop;
3540 +
3541 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3542 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3543 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3544 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3545 +
3546 + if (err)
3547 + break;
3548 +
3549 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3550 + ldi2 == 0x3414015AU &&
3551 + bel == 0xE4008200U &&
3552 + nop == 0x08000240U)
3553 + {
3554 + regs->gr[25] = (ldi1 & 2) >> 1;
3555 + regs->gr[20] = __NR_rt_sigreturn;
3556 + regs->gr[31] = regs->iaoq[1] + 16;
3557 + regs->sr[0] = regs->iasq[1];
3558 + regs->iaoq[0] = 0x100UL;
3559 + regs->iaoq[1] = regs->iaoq[0] + 4;
3560 + regs->iasq[0] = regs->sr[2];
3561 + regs->iasq[1] = regs->sr[2];
3562 + return 2;
3563 + }
3564 + } while (0);
3565 +#endif
3566 +
3567 + return 1;
3568 +}
3569 +
3570 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3571 +{
3572 + unsigned long i;
3573 +
3574 + printk(KERN_ERR "PAX: bytes at PC: ");
3575 + for (i = 0; i < 5; i++) {
3576 + unsigned int c;
3577 + if (get_user(c, (unsigned int *)pc+i))
3578 + printk(KERN_CONT "???????? ");
3579 + else
3580 + printk(KERN_CONT "%08x ", c);
3581 + }
3582 + printk("\n");
3583 +}
3584 +#endif
3585 +
3586 int fixup_exception(struct pt_regs *regs)
3587 {
3588 const struct exception_table_entry *fix;
3589 @@ -192,8 +303,33 @@ good_area:
3590
3591 acc_type = parisc_acctyp(code,regs->iir);
3592
3593 - if ((vma->vm_flags & acc_type) != acc_type)
3594 + if ((vma->vm_flags & acc_type) != acc_type) {
3595 +
3596 +#ifdef CONFIG_PAX_PAGEEXEC
3597 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3598 + (address & ~3UL) == instruction_pointer(regs))
3599 + {
3600 + up_read(&mm->mmap_sem);
3601 + switch (pax_handle_fetch_fault(regs)) {
3602 +
3603 +#ifdef CONFIG_PAX_EMUPLT
3604 + case 3:
3605 + return;
3606 +#endif
3607 +
3608 +#ifdef CONFIG_PAX_EMUTRAMP
3609 + case 2:
3610 + return;
3611 +#endif
3612 +
3613 + }
3614 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3615 + do_group_exit(SIGKILL);
3616 + }
3617 +#endif
3618 +
3619 goto bad_area;
3620 + }
3621
3622 /*
3623 * If for any reason at all we couldn't handle the fault, make
3624 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3625 index 02e41b5..ec6e26c 100644
3626 --- a/arch/powerpc/include/asm/atomic.h
3627 +++ b/arch/powerpc/include/asm/atomic.h
3628 @@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3629
3630 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3631
3632 +#define atomic64_read_unchecked(v) atomic64_read(v)
3633 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3634 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3635 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3636 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3637 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3638 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3639 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3640 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3641 +
3642 #endif /* __powerpc64__ */
3643
3644 #endif /* __KERNEL__ */
3645 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3646 index 4b50941..5605819 100644
3647 --- a/arch/powerpc/include/asm/cache.h
3648 +++ b/arch/powerpc/include/asm/cache.h
3649 @@ -3,6 +3,7 @@
3650
3651 #ifdef __KERNEL__
3652
3653 +#include <linux/const.h>
3654
3655 /* bytes per L1 cache line */
3656 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3657 @@ -22,7 +23,7 @@
3658 #define L1_CACHE_SHIFT 7
3659 #endif
3660
3661 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3662 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3663
3664 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3665
3666 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3667 index 3bf9cca..e7457d0 100644
3668 --- a/arch/powerpc/include/asm/elf.h
3669 +++ b/arch/powerpc/include/asm/elf.h
3670 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3671 the loader. We need to make sure that it is out of the way of the program
3672 that it will "exec", and that there is sufficient room for the brk. */
3673
3674 -extern unsigned long randomize_et_dyn(unsigned long base);
3675 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3676 +#define ELF_ET_DYN_BASE (0x20000000)
3677 +
3678 +#ifdef CONFIG_PAX_ASLR
3679 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3680 +
3681 +#ifdef __powerpc64__
3682 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3683 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3684 +#else
3685 +#define PAX_DELTA_MMAP_LEN 15
3686 +#define PAX_DELTA_STACK_LEN 15
3687 +#endif
3688 +#endif
3689
3690 /*
3691 * Our registers are always unsigned longs, whether we're a 32 bit
3692 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3693 (0x7ff >> (PAGE_SHIFT - 12)) : \
3694 (0x3ffff >> (PAGE_SHIFT - 12)))
3695
3696 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3697 -#define arch_randomize_brk arch_randomize_brk
3698 -
3699 #endif /* __KERNEL__ */
3700
3701 /*
3702 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3703 index bca8fdc..61e9580 100644
3704 --- a/arch/powerpc/include/asm/kmap_types.h
3705 +++ b/arch/powerpc/include/asm/kmap_types.h
3706 @@ -27,6 +27,7 @@ enum km_type {
3707 KM_PPC_SYNC_PAGE,
3708 KM_PPC_SYNC_ICACHE,
3709 KM_KDB,
3710 + KM_CLEARPAGE,
3711 KM_TYPE_NR
3712 };
3713
3714 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3715 index d4a7f64..451de1c 100644
3716 --- a/arch/powerpc/include/asm/mman.h
3717 +++ b/arch/powerpc/include/asm/mman.h
3718 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3719 }
3720 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3721
3722 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3723 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3724 {
3725 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3726 }
3727 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3728 index f072e97..b436dee 100644
3729 --- a/arch/powerpc/include/asm/page.h
3730 +++ b/arch/powerpc/include/asm/page.h
3731 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3732 * and needs to be executable. This means the whole heap ends
3733 * up being executable.
3734 */
3735 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3736 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3737 +#define VM_DATA_DEFAULT_FLAGS32 \
3738 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3739 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3740
3741 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3742 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3743 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3744 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3745 #endif
3746
3747 +#define ktla_ktva(addr) (addr)
3748 +#define ktva_ktla(addr) (addr)
3749 +
3750 /*
3751 * Use the top bit of the higher-level page table entries to indicate whether
3752 * the entries we point to contain hugepages. This works because we know that
3753 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3754 index fed85e6..da5c71b 100644
3755 --- a/arch/powerpc/include/asm/page_64.h
3756 +++ b/arch/powerpc/include/asm/page_64.h
3757 @@ -146,15 +146,18 @@ do { \
3758 * stack by default, so in the absence of a PT_GNU_STACK program header
3759 * we turn execute permission off.
3760 */
3761 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3762 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3763 +#define VM_STACK_DEFAULT_FLAGS32 \
3764 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3765 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3766
3767 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3768 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3769
3770 +#ifndef CONFIG_PAX_PAGEEXEC
3771 #define VM_STACK_DEFAULT_FLAGS \
3772 (is_32bit_task() ? \
3773 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3774 +#endif
3775
3776 #include <asm-generic/getorder.h>
3777
3778 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3779 index 292725c..f87ae14 100644
3780 --- a/arch/powerpc/include/asm/pgalloc-64.h
3781 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3782 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3783 #ifndef CONFIG_PPC_64K_PAGES
3784
3785 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3786 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3787
3788 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3789 {
3790 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3791 pud_set(pud, (unsigned long)pmd);
3792 }
3793
3794 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3795 +{
3796 + pud_populate(mm, pud, pmd);
3797 +}
3798 +
3799 #define pmd_populate(mm, pmd, pte_page) \
3800 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3801 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3802 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3803 #else /* CONFIG_PPC_64K_PAGES */
3804
3805 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3806 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3807
3808 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3809 pte_t *pte)
3810 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3811 index 2e0e411..7899c68 100644
3812 --- a/arch/powerpc/include/asm/pgtable.h
3813 +++ b/arch/powerpc/include/asm/pgtable.h
3814 @@ -2,6 +2,7 @@
3815 #define _ASM_POWERPC_PGTABLE_H
3816 #ifdef __KERNEL__
3817
3818 +#include <linux/const.h>
3819 #ifndef __ASSEMBLY__
3820 #include <asm/processor.h> /* For TASK_SIZE */
3821 #include <asm/mmu.h>
3822 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3823 index 4aad413..85d86bf 100644
3824 --- a/arch/powerpc/include/asm/pte-hash32.h
3825 +++ b/arch/powerpc/include/asm/pte-hash32.h
3826 @@ -21,6 +21,7 @@
3827 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3828 #define _PAGE_USER 0x004 /* usermode access allowed */
3829 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3830 +#define _PAGE_EXEC _PAGE_GUARDED
3831 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3832 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3833 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3834 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3835 index 7fdc2c0..e47a9b02d3 100644
3836 --- a/arch/powerpc/include/asm/reg.h
3837 +++ b/arch/powerpc/include/asm/reg.h
3838 @@ -212,6 +212,7 @@
3839 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3840 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3841 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3842 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3843 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3844 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3845 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3846 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
3847 index c377457..3c69fbc 100644
3848 --- a/arch/powerpc/include/asm/system.h
3849 +++ b/arch/powerpc/include/asm/system.h
3850 @@ -539,7 +539,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3851 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3852 #endif
3853
3854 -extern unsigned long arch_align_stack(unsigned long sp);
3855 +#define arch_align_stack(x) ((x) & ~0xfUL)
3856
3857 /* Used in very early kernel initialization. */
3858 extern unsigned long reloc_offset(void);
3859 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3860 index 96471494..60ed5a2 100644
3861 --- a/arch/powerpc/include/asm/thread_info.h
3862 +++ b/arch/powerpc/include/asm/thread_info.h
3863 @@ -104,13 +104,15 @@ static inline struct thread_info *current_thread_info(void)
3864 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3865 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3866 #define TIF_SINGLESTEP 8 /* singlestepping active */
3867 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3868 #define TIF_SECCOMP 10 /* secure computing */
3869 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3870 #define TIF_NOERROR 12 /* Force successful syscall return */
3871 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3872 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3873 #define TIF_RUNLATCH 16 /* Is the runlatch enabled? */
3874 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
3875 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3876 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3877
3878 /* as above, but as bit values */
3879 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3880 @@ -128,8 +130,11 @@ static inline struct thread_info *current_thread_info(void)
3881 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3882 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3883 #define _TIF_RUNLATCH (1<<TIF_RUNLATCH)
3884 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3885 +
3886 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3887 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3888 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT \
3889 + _TIF_GRSEC_SETXID)
3890
3891 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3892 _TIF_NOTIFY_RESUME)
3893 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3894 index bd0fb84..a42a14b 100644
3895 --- a/arch/powerpc/include/asm/uaccess.h
3896 +++ b/arch/powerpc/include/asm/uaccess.h
3897 @@ -13,6 +13,8 @@
3898 #define VERIFY_READ 0
3899 #define VERIFY_WRITE 1
3900
3901 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3902 +
3903 /*
3904 * The fs value determines whether argument validity checking should be
3905 * performed or not. If get_fs() == USER_DS, checking is performed, with
3906 @@ -327,52 +329,6 @@ do { \
3907 extern unsigned long __copy_tofrom_user(void __user *to,
3908 const void __user *from, unsigned long size);
3909
3910 -#ifndef __powerpc64__
3911 -
3912 -static inline unsigned long copy_from_user(void *to,
3913 - const void __user *from, unsigned long n)
3914 -{
3915 - unsigned long over;
3916 -
3917 - if (access_ok(VERIFY_READ, from, n))
3918 - return __copy_tofrom_user((__force void __user *)to, from, n);
3919 - if ((unsigned long)from < TASK_SIZE) {
3920 - over = (unsigned long)from + n - TASK_SIZE;
3921 - return __copy_tofrom_user((__force void __user *)to, from,
3922 - n - over) + over;
3923 - }
3924 - return n;
3925 -}
3926 -
3927 -static inline unsigned long copy_to_user(void __user *to,
3928 - const void *from, unsigned long n)
3929 -{
3930 - unsigned long over;
3931 -
3932 - if (access_ok(VERIFY_WRITE, to, n))
3933 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3934 - if ((unsigned long)to < TASK_SIZE) {
3935 - over = (unsigned long)to + n - TASK_SIZE;
3936 - return __copy_tofrom_user(to, (__force void __user *)from,
3937 - n - over) + over;
3938 - }
3939 - return n;
3940 -}
3941 -
3942 -#else /* __powerpc64__ */
3943 -
3944 -#define __copy_in_user(to, from, size) \
3945 - __copy_tofrom_user((to), (from), (size))
3946 -
3947 -extern unsigned long copy_from_user(void *to, const void __user *from,
3948 - unsigned long n);
3949 -extern unsigned long copy_to_user(void __user *to, const void *from,
3950 - unsigned long n);
3951 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3952 - unsigned long n);
3953 -
3954 -#endif /* __powerpc64__ */
3955 -
3956 static inline unsigned long __copy_from_user_inatomic(void *to,
3957 const void __user *from, unsigned long n)
3958 {
3959 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
3960 if (ret == 0)
3961 return 0;
3962 }
3963 +
3964 + if (!__builtin_constant_p(n))
3965 + check_object_size(to, n, false);
3966 +
3967 return __copy_tofrom_user((__force void __user *)to, from, n);
3968 }
3969
3970 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
3971 if (ret == 0)
3972 return 0;
3973 }
3974 +
3975 + if (!__builtin_constant_p(n))
3976 + check_object_size(from, n, true);
3977 +
3978 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3979 }
3980
3981 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
3982 return __copy_to_user_inatomic(to, from, size);
3983 }
3984
3985 +#ifndef __powerpc64__
3986 +
3987 +static inline unsigned long __must_check copy_from_user(void *to,
3988 + const void __user *from, unsigned long n)
3989 +{
3990 + unsigned long over;
3991 +
3992 + if ((long)n < 0)
3993 + return n;
3994 +
3995 + if (access_ok(VERIFY_READ, from, n)) {
3996 + if (!__builtin_constant_p(n))
3997 + check_object_size(to, n, false);
3998 + return __copy_tofrom_user((__force void __user *)to, from, n);
3999 + }
4000 + if ((unsigned long)from < TASK_SIZE) {
4001 + over = (unsigned long)from + n - TASK_SIZE;
4002 + if (!__builtin_constant_p(n - over))
4003 + check_object_size(to, n - over, false);
4004 + return __copy_tofrom_user((__force void __user *)to, from,
4005 + n - over) + over;
4006 + }
4007 + return n;
4008 +}
4009 +
4010 +static inline unsigned long __must_check copy_to_user(void __user *to,
4011 + const void *from, unsigned long n)
4012 +{
4013 + unsigned long over;
4014 +
4015 + if ((long)n < 0)
4016 + return n;
4017 +
4018 + if (access_ok(VERIFY_WRITE, to, n)) {
4019 + if (!__builtin_constant_p(n))
4020 + check_object_size(from, n, true);
4021 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4022 + }
4023 + if ((unsigned long)to < TASK_SIZE) {
4024 + over = (unsigned long)to + n - TASK_SIZE;
4025 + if (!__builtin_constant_p(n))
4026 + check_object_size(from, n - over, true);
4027 + return __copy_tofrom_user(to, (__force void __user *)from,
4028 + n - over) + over;
4029 + }
4030 + return n;
4031 +}
4032 +
4033 +#else /* __powerpc64__ */
4034 +
4035 +#define __copy_in_user(to, from, size) \
4036 + __copy_tofrom_user((to), (from), (size))
4037 +
4038 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4039 +{
4040 + if ((long)n < 0 || n > INT_MAX)
4041 + return n;
4042 +
4043 + if (!__builtin_constant_p(n))
4044 + check_object_size(to, n, false);
4045 +
4046 + if (likely(access_ok(VERIFY_READ, from, n)))
4047 + n = __copy_from_user(to, from, n);
4048 + else
4049 + memset(to, 0, n);
4050 + return n;
4051 +}
4052 +
4053 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4054 +{
4055 + if ((long)n < 0 || n > INT_MAX)
4056 + return n;
4057 +
4058 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4059 + if (!__builtin_constant_p(n))
4060 + check_object_size(from, n, true);
4061 + n = __copy_to_user(to, from, n);
4062 + }
4063 + return n;
4064 +}
4065 +
4066 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4067 + unsigned long n);
4068 +
4069 +#endif /* __powerpc64__ */
4070 +
4071 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4072
4073 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4074 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4075 index 429983c..7af363b 100644
4076 --- a/arch/powerpc/kernel/exceptions-64e.S
4077 +++ b/arch/powerpc/kernel/exceptions-64e.S
4078 @@ -587,6 +587,7 @@ storage_fault_common:
4079 std r14,_DAR(r1)
4080 std r15,_DSISR(r1)
4081 addi r3,r1,STACK_FRAME_OVERHEAD
4082 + bl .save_nvgprs
4083 mr r4,r14
4084 mr r5,r15
4085 ld r14,PACA_EXGEN+EX_R14(r13)
4086 @@ -596,8 +597,7 @@ storage_fault_common:
4087 cmpdi r3,0
4088 bne- 1f
4089 b .ret_from_except_lite
4090 -1: bl .save_nvgprs
4091 - mr r5,r3
4092 +1: mr r5,r3
4093 addi r3,r1,STACK_FRAME_OVERHEAD
4094 ld r4,_DAR(r1)
4095 bl .bad_page_fault
4096 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4097 index 15c5a4f..22a4000 100644
4098 --- a/arch/powerpc/kernel/exceptions-64s.S
4099 +++ b/arch/powerpc/kernel/exceptions-64s.S
4100 @@ -1004,10 +1004,10 @@ handle_page_fault:
4101 11: ld r4,_DAR(r1)
4102 ld r5,_DSISR(r1)
4103 addi r3,r1,STACK_FRAME_OVERHEAD
4104 + bl .save_nvgprs
4105 bl .do_page_fault
4106 cmpdi r3,0
4107 beq+ 13f
4108 - bl .save_nvgprs
4109 mr r5,r3
4110 addi r3,r1,STACK_FRAME_OVERHEAD
4111 lwz r4,_DAR(r1)
4112 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
4113 index 01e2877..a1ba360 100644
4114 --- a/arch/powerpc/kernel/irq.c
4115 +++ b/arch/powerpc/kernel/irq.c
4116 @@ -560,9 +560,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
4117 host->ops = ops;
4118 host->of_node = of_node_get(of_node);
4119
4120 - if (host->ops->match == NULL)
4121 - host->ops->match = default_irq_host_match;
4122 -
4123 raw_spin_lock_irqsave(&irq_big_lock, flags);
4124
4125 /* If it's a legacy controller, check for duplicates and
4126 @@ -635,7 +632,12 @@ struct irq_host *irq_find_host(struct device_node *node)
4127 */
4128 raw_spin_lock_irqsave(&irq_big_lock, flags);
4129 list_for_each_entry(h, &irq_hosts, link)
4130 - if (h->ops->match(h, node)) {
4131 + if (h->ops->match) {
4132 + if (h->ops->match(h, node)) {
4133 + found = h;
4134 + break;
4135 + }
4136 + } else if (default_irq_host_match(h, node)) {
4137 found = h;
4138 break;
4139 }
4140 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4141 index 0b6d796..d760ddb 100644
4142 --- a/arch/powerpc/kernel/module_32.c
4143 +++ b/arch/powerpc/kernel/module_32.c
4144 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4145 me->arch.core_plt_section = i;
4146 }
4147 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4148 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4149 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4150 return -ENOEXEC;
4151 }
4152
4153 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4154
4155 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4156 /* Init, or core PLT? */
4157 - if (location >= mod->module_core
4158 - && location < mod->module_core + mod->core_size)
4159 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4160 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4161 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4162 - else
4163 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4164 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4165 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4166 + else {
4167 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4168 + return ~0UL;
4169 + }
4170
4171 /* Find this entry, or if that fails, the next avail. entry */
4172 while (entry->jump[0]) {
4173 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4174 index d817ab0..b23b18e 100644
4175 --- a/arch/powerpc/kernel/process.c
4176 +++ b/arch/powerpc/kernel/process.c
4177 @@ -676,8 +676,8 @@ void show_regs(struct pt_regs * regs)
4178 * Lookup NIP late so we have the best change of getting the
4179 * above info out without failing
4180 */
4181 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4182 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4183 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4184 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4185 #endif
4186 show_stack(current, (unsigned long *) regs->gpr[1]);
4187 if (!user_mode(regs))
4188 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4189 newsp = stack[0];
4190 ip = stack[STACK_FRAME_LR_SAVE];
4191 if (!firstframe || ip != lr) {
4192 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4193 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4194 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4195 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4196 - printk(" (%pS)",
4197 + printk(" (%pA)",
4198 (void *)current->ret_stack[curr_frame].ret);
4199 curr_frame--;
4200 }
4201 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4202 struct pt_regs *regs = (struct pt_regs *)
4203 (sp + STACK_FRAME_OVERHEAD);
4204 lr = regs->link;
4205 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4206 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4207 regs->trap, (void *)regs->nip, (void *)lr);
4208 firstframe = 1;
4209 }
4210 @@ -1279,58 +1279,3 @@ void thread_info_cache_init(void)
4211 }
4212
4213 #endif /* THREAD_SHIFT < PAGE_SHIFT */
4214 -
4215 -unsigned long arch_align_stack(unsigned long sp)
4216 -{
4217 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4218 - sp -= get_random_int() & ~PAGE_MASK;
4219 - return sp & ~0xf;
4220 -}
4221 -
4222 -static inline unsigned long brk_rnd(void)
4223 -{
4224 - unsigned long rnd = 0;
4225 -
4226 - /* 8MB for 32bit, 1GB for 64bit */
4227 - if (is_32bit_task())
4228 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4229 - else
4230 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4231 -
4232 - return rnd << PAGE_SHIFT;
4233 -}
4234 -
4235 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4236 -{
4237 - unsigned long base = mm->brk;
4238 - unsigned long ret;
4239 -
4240 -#ifdef CONFIG_PPC_STD_MMU_64
4241 - /*
4242 - * If we are using 1TB segments and we are allowed to randomise
4243 - * the heap, we can put it above 1TB so it is backed by a 1TB
4244 - * segment. Otherwise the heap will be in the bottom 1TB
4245 - * which always uses 256MB segments and this may result in a
4246 - * performance penalty.
4247 - */
4248 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4249 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4250 -#endif
4251 -
4252 - ret = PAGE_ALIGN(base + brk_rnd());
4253 -
4254 - if (ret < mm->brk)
4255 - return mm->brk;
4256 -
4257 - return ret;
4258 -}
4259 -
4260 -unsigned long randomize_et_dyn(unsigned long base)
4261 -{
4262 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4263 -
4264 - if (ret < base)
4265 - return base;
4266 -
4267 - return ret;
4268 -}
4269 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4270 index 5b43325..94a5bb4 100644
4271 --- a/arch/powerpc/kernel/ptrace.c
4272 +++ b/arch/powerpc/kernel/ptrace.c
4273 @@ -1702,6 +1702,10 @@ long arch_ptrace(struct task_struct *child, long request,
4274 return ret;
4275 }
4276
4277 +#ifdef CONFIG_GRKERNSEC_SETXID
4278 +extern void gr_delayed_cred_worker(void);
4279 +#endif
4280 +
4281 /*
4282 * We must return the syscall number to actually look up in the table.
4283 * This can be -1L to skip running any syscall at all.
4284 @@ -1712,6 +1716,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4285
4286 secure_computing(regs->gpr[0]);
4287
4288 +#ifdef CONFIG_GRKERNSEC_SETXID
4289 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4290 + gr_delayed_cred_worker();
4291 +#endif
4292 +
4293 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4294 tracehook_report_syscall_entry(regs))
4295 /*
4296 @@ -1746,6 +1755,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4297 {
4298 int step;
4299
4300 +#ifdef CONFIG_GRKERNSEC_SETXID
4301 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4302 + gr_delayed_cred_worker();
4303 +#endif
4304 +
4305 audit_syscall_exit(regs);
4306
4307 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4308 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4309 index 836a5a1..27289a3 100644
4310 --- a/arch/powerpc/kernel/signal_32.c
4311 +++ b/arch/powerpc/kernel/signal_32.c
4312 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4313 /* Save user registers on the stack */
4314 frame = &rt_sf->uc.uc_mcontext;
4315 addr = frame;
4316 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4317 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4318 if (save_user_regs(regs, frame, 0, 1))
4319 goto badframe;
4320 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4321 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4322 index a50b5ec..547078a 100644
4323 --- a/arch/powerpc/kernel/signal_64.c
4324 +++ b/arch/powerpc/kernel/signal_64.c
4325 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4326 current->thread.fpscr.val = 0;
4327
4328 /* Set up to return from userspace. */
4329 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4330 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4331 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4332 } else {
4333 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4334 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4335 index c091527..5592625 100644
4336 --- a/arch/powerpc/kernel/traps.c
4337 +++ b/arch/powerpc/kernel/traps.c
4338 @@ -131,6 +131,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4339 return flags;
4340 }
4341
4342 +extern void gr_handle_kernel_exploit(void);
4343 +
4344 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4345 int signr)
4346 {
4347 @@ -178,6 +180,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4348 panic("Fatal exception in interrupt");
4349 if (panic_on_oops)
4350 panic("Fatal exception");
4351 +
4352 + gr_handle_kernel_exploit();
4353 +
4354 do_exit(signr);
4355 }
4356
4357 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4358 index 7d14bb6..1305601 100644
4359 --- a/arch/powerpc/kernel/vdso.c
4360 +++ b/arch/powerpc/kernel/vdso.c
4361 @@ -35,6 +35,7 @@
4362 #include <asm/firmware.h>
4363 #include <asm/vdso.h>
4364 #include <asm/vdso_datapage.h>
4365 +#include <asm/mman.h>
4366
4367 #include "setup.h"
4368
4369 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4370 vdso_base = VDSO32_MBASE;
4371 #endif
4372
4373 - current->mm->context.vdso_base = 0;
4374 + current->mm->context.vdso_base = ~0UL;
4375
4376 /* vDSO has a problem and was disabled, just don't "enable" it for the
4377 * process
4378 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4379 vdso_base = get_unmapped_area(NULL, vdso_base,
4380 (vdso_pages << PAGE_SHIFT) +
4381 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4382 - 0, 0);
4383 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4384 if (IS_ERR_VALUE(vdso_base)) {
4385 rc = vdso_base;
4386 goto fail_mmapsem;
4387 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4388 index 5eea6f3..5d10396 100644
4389 --- a/arch/powerpc/lib/usercopy_64.c
4390 +++ b/arch/powerpc/lib/usercopy_64.c
4391 @@ -9,22 +9,6 @@
4392 #include <linux/module.h>
4393 #include <asm/uaccess.h>
4394
4395 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4396 -{
4397 - if (likely(access_ok(VERIFY_READ, from, n)))
4398 - n = __copy_from_user(to, from, n);
4399 - else
4400 - memset(to, 0, n);
4401 - return n;
4402 -}
4403 -
4404 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4405 -{
4406 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4407 - n = __copy_to_user(to, from, n);
4408 - return n;
4409 -}
4410 -
4411 unsigned long copy_in_user(void __user *to, const void __user *from,
4412 unsigned long n)
4413 {
4414 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4415 return n;
4416 }
4417
4418 -EXPORT_SYMBOL(copy_from_user);
4419 -EXPORT_SYMBOL(copy_to_user);
4420 EXPORT_SYMBOL(copy_in_user);
4421
4422 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4423 index 2f0d1b0..36fb5cc 100644
4424 --- a/arch/powerpc/mm/fault.c
4425 +++ b/arch/powerpc/mm/fault.c
4426 @@ -32,6 +32,10 @@
4427 #include <linux/perf_event.h>
4428 #include <linux/magic.h>
4429 #include <linux/ratelimit.h>
4430 +#include <linux/slab.h>
4431 +#include <linux/pagemap.h>
4432 +#include <linux/compiler.h>
4433 +#include <linux/unistd.h>
4434
4435 #include <asm/firmware.h>
4436 #include <asm/page.h>
4437 @@ -43,6 +47,7 @@
4438 #include <asm/tlbflush.h>
4439 #include <asm/siginfo.h>
4440 #include <mm/mmu_decl.h>
4441 +#include <asm/ptrace.h>
4442
4443 #include "icswx.h"
4444
4445 @@ -68,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4446 }
4447 #endif
4448
4449 +#ifdef CONFIG_PAX_PAGEEXEC
4450 +/*
4451 + * PaX: decide what to do with offenders (regs->nip = fault address)
4452 + *
4453 + * returns 1 when task should be killed
4454 + */
4455 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4456 +{
4457 + return 1;
4458 +}
4459 +
4460 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4461 +{
4462 + unsigned long i;
4463 +
4464 + printk(KERN_ERR "PAX: bytes at PC: ");
4465 + for (i = 0; i < 5; i++) {
4466 + unsigned int c;
4467 + if (get_user(c, (unsigned int __user *)pc+i))
4468 + printk(KERN_CONT "???????? ");
4469 + else
4470 + printk(KERN_CONT "%08x ", c);
4471 + }
4472 + printk("\n");
4473 +}
4474 +#endif
4475 +
4476 /*
4477 * Check whether the instruction at regs->nip is a store using
4478 * an update addressing form which will update r1.
4479 @@ -138,7 +170,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4480 * indicate errors in DSISR but can validly be set in SRR1.
4481 */
4482 if (trap == 0x400)
4483 - error_code &= 0x48200000;
4484 + error_code &= 0x58200000;
4485 else
4486 is_write = error_code & DSISR_ISSTORE;
4487 #else
4488 @@ -276,7 +308,7 @@ good_area:
4489 * "undefined". Of those that can be set, this is the only
4490 * one which seems bad.
4491 */
4492 - if (error_code & 0x10000000)
4493 + if (error_code & DSISR_GUARDED)
4494 /* Guarded storage error. */
4495 goto bad_area;
4496 #endif /* CONFIG_8xx */
4497 @@ -291,7 +323,7 @@ good_area:
4498 * processors use the same I/D cache coherency mechanism
4499 * as embedded.
4500 */
4501 - if (error_code & DSISR_PROTFAULT)
4502 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4503 goto bad_area;
4504 #endif /* CONFIG_PPC_STD_MMU */
4505
4506 @@ -360,6 +392,23 @@ bad_area:
4507 bad_area_nosemaphore:
4508 /* User mode accesses cause a SIGSEGV */
4509 if (user_mode(regs)) {
4510 +
4511 +#ifdef CONFIG_PAX_PAGEEXEC
4512 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4513 +#ifdef CONFIG_PPC_STD_MMU
4514 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4515 +#else
4516 + if (is_exec && regs->nip == address) {
4517 +#endif
4518 + switch (pax_handle_fetch_fault(regs)) {
4519 + }
4520 +
4521 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4522 + do_group_exit(SIGKILL);
4523 + }
4524 + }
4525 +#endif
4526 +
4527 _exception(SIGSEGV, regs, code, address);
4528 return 0;
4529 }
4530 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4531 index 67a42ed..1c7210c 100644
4532 --- a/arch/powerpc/mm/mmap_64.c
4533 +++ b/arch/powerpc/mm/mmap_64.c
4534 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4535 */
4536 if (mmap_is_legacy()) {
4537 mm->mmap_base = TASK_UNMAPPED_BASE;
4538 +
4539 +#ifdef CONFIG_PAX_RANDMMAP
4540 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4541 + mm->mmap_base += mm->delta_mmap;
4542 +#endif
4543 +
4544 mm->get_unmapped_area = arch_get_unmapped_area;
4545 mm->unmap_area = arch_unmap_area;
4546 } else {
4547 mm->mmap_base = mmap_base();
4548 +
4549 +#ifdef CONFIG_PAX_RANDMMAP
4550 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4551 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4552 +#endif
4553 +
4554 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4555 mm->unmap_area = arch_unmap_area_topdown;
4556 }
4557 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4558 index 73709f7..6b90313 100644
4559 --- a/arch/powerpc/mm/slice.c
4560 +++ b/arch/powerpc/mm/slice.c
4561 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4562 if ((mm->task_size - len) < addr)
4563 return 0;
4564 vma = find_vma(mm, addr);
4565 - return (!vma || (addr + len) <= vma->vm_start);
4566 + return check_heap_stack_gap(vma, addr, len);
4567 }
4568
4569 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4570 @@ -256,7 +256,7 @@ full_search:
4571 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4572 continue;
4573 }
4574 - if (!vma || addr + len <= vma->vm_start) {
4575 + if (check_heap_stack_gap(vma, addr, len)) {
4576 /*
4577 * Remember the place where we stopped the search:
4578 */
4579 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4580 }
4581 }
4582
4583 - addr = mm->mmap_base;
4584 - while (addr > len) {
4585 + if (mm->mmap_base < len)
4586 + addr = -ENOMEM;
4587 + else
4588 + addr = mm->mmap_base - len;
4589 +
4590 + while (!IS_ERR_VALUE(addr)) {
4591 /* Go down by chunk size */
4592 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4593 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4594
4595 /* Check for hit with different page size */
4596 mask = slice_range_to_mask(addr, len);
4597 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4598 * return with success:
4599 */
4600 vma = find_vma(mm, addr);
4601 - if (!vma || (addr + len) <= vma->vm_start) {
4602 + if (check_heap_stack_gap(vma, addr, len)) {
4603 /* remember the address as a hint for next time */
4604 if (use_cache)
4605 mm->free_area_cache = addr;
4606 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4607 mm->cached_hole_size = vma->vm_start - addr;
4608
4609 /* try just below the current vma->vm_start */
4610 - addr = vma->vm_start;
4611 + addr = skip_heap_stack_gap(vma, len);
4612 }
4613
4614 /*
4615 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4616 if (fixed && addr > (mm->task_size - len))
4617 return -EINVAL;
4618
4619 +#ifdef CONFIG_PAX_RANDMMAP
4620 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4621 + addr = 0;
4622 +#endif
4623 +
4624 /* If hint, make sure it matches our alignment restrictions */
4625 if (!fixed && addr) {
4626 addr = _ALIGN_UP(addr, 1ul << pshift);
4627 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4628 index 8517d2a..d2738d4 100644
4629 --- a/arch/s390/include/asm/atomic.h
4630 +++ b/arch/s390/include/asm/atomic.h
4631 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4632 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4633 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4634
4635 +#define atomic64_read_unchecked(v) atomic64_read(v)
4636 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4637 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4638 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4639 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4640 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4641 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4642 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4643 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4644 +
4645 #define smp_mb__before_atomic_dec() smp_mb()
4646 #define smp_mb__after_atomic_dec() smp_mb()
4647 #define smp_mb__before_atomic_inc() smp_mb()
4648 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4649 index 2a30d5a..5e5586f 100644
4650 --- a/arch/s390/include/asm/cache.h
4651 +++ b/arch/s390/include/asm/cache.h
4652 @@ -11,8 +11,10 @@
4653 #ifndef __ARCH_S390_CACHE_H
4654 #define __ARCH_S390_CACHE_H
4655
4656 -#define L1_CACHE_BYTES 256
4657 +#include <linux/const.h>
4658 +
4659 #define L1_CACHE_SHIFT 8
4660 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4661 #define NET_SKB_PAD 32
4662
4663 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4664 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4665 index 547f1a6..0b22b53 100644
4666 --- a/arch/s390/include/asm/elf.h
4667 +++ b/arch/s390/include/asm/elf.h
4668 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4669 the loader. We need to make sure that it is out of the way of the program
4670 that it will "exec", and that there is sufficient room for the brk. */
4671
4672 -extern unsigned long randomize_et_dyn(unsigned long base);
4673 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4674 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4675 +
4676 +#ifdef CONFIG_PAX_ASLR
4677 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4678 +
4679 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4680 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4681 +#endif
4682
4683 /* This yields a mask that user programs can use to figure out what
4684 instruction set this CPU supports. */
4685 @@ -211,7 +217,4 @@ struct linux_binprm;
4686 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4687 int arch_setup_additional_pages(struct linux_binprm *, int);
4688
4689 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4690 -#define arch_randomize_brk arch_randomize_brk
4691 -
4692 #endif
4693 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4694 index d73cc6b..1a296ad 100644
4695 --- a/arch/s390/include/asm/system.h
4696 +++ b/arch/s390/include/asm/system.h
4697 @@ -260,7 +260,7 @@ extern void (*_machine_restart)(char *command);
4698 extern void (*_machine_halt)(void);
4699 extern void (*_machine_power_off)(void);
4700
4701 -extern unsigned long arch_align_stack(unsigned long sp);
4702 +#define arch_align_stack(x) ((x) & ~0xfUL)
4703
4704 static inline int tprot(unsigned long addr)
4705 {
4706 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4707 index 2b23885..e136e31 100644
4708 --- a/arch/s390/include/asm/uaccess.h
4709 +++ b/arch/s390/include/asm/uaccess.h
4710 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
4711 copy_to_user(void __user *to, const void *from, unsigned long n)
4712 {
4713 might_fault();
4714 +
4715 + if ((long)n < 0)
4716 + return n;
4717 +
4718 if (access_ok(VERIFY_WRITE, to, n))
4719 n = __copy_to_user(to, from, n);
4720 return n;
4721 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4722 static inline unsigned long __must_check
4723 __copy_from_user(void *to, const void __user *from, unsigned long n)
4724 {
4725 + if ((long)n < 0)
4726 + return n;
4727 +
4728 if (__builtin_constant_p(n) && (n <= 256))
4729 return uaccess.copy_from_user_small(n, from, to);
4730 else
4731 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4732 unsigned int sz = __compiletime_object_size(to);
4733
4734 might_fault();
4735 +
4736 + if ((long)n < 0)
4737 + return n;
4738 +
4739 if (unlikely(sz != -1 && sz < n)) {
4740 copy_from_user_overflow();
4741 return n;
4742 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4743 index dfcb343..eda788a 100644
4744 --- a/arch/s390/kernel/module.c
4745 +++ b/arch/s390/kernel/module.c
4746 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4747
4748 /* Increase core size by size of got & plt and set start
4749 offsets for got and plt. */
4750 - me->core_size = ALIGN(me->core_size, 4);
4751 - me->arch.got_offset = me->core_size;
4752 - me->core_size += me->arch.got_size;
4753 - me->arch.plt_offset = me->core_size;
4754 - me->core_size += me->arch.plt_size;
4755 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4756 + me->arch.got_offset = me->core_size_rw;
4757 + me->core_size_rw += me->arch.got_size;
4758 + me->arch.plt_offset = me->core_size_rx;
4759 + me->core_size_rx += me->arch.plt_size;
4760 return 0;
4761 }
4762
4763 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4764 if (info->got_initialized == 0) {
4765 Elf_Addr *gotent;
4766
4767 - gotent = me->module_core + me->arch.got_offset +
4768 + gotent = me->module_core_rw + me->arch.got_offset +
4769 info->got_offset;
4770 *gotent = val;
4771 info->got_initialized = 1;
4772 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4773 else if (r_type == R_390_GOTENT ||
4774 r_type == R_390_GOTPLTENT)
4775 *(unsigned int *) loc =
4776 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4777 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4778 else if (r_type == R_390_GOT64 ||
4779 r_type == R_390_GOTPLT64)
4780 *(unsigned long *) loc = val;
4781 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4782 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4783 if (info->plt_initialized == 0) {
4784 unsigned int *ip;
4785 - ip = me->module_core + me->arch.plt_offset +
4786 + ip = me->module_core_rx + me->arch.plt_offset +
4787 info->plt_offset;
4788 #ifndef CONFIG_64BIT
4789 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4790 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4791 val - loc + 0xffffUL < 0x1ffffeUL) ||
4792 (r_type == R_390_PLT32DBL &&
4793 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4794 - val = (Elf_Addr) me->module_core +
4795 + val = (Elf_Addr) me->module_core_rx +
4796 me->arch.plt_offset +
4797 info->plt_offset;
4798 val += rela->r_addend - loc;
4799 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4800 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4801 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4802 val = val + rela->r_addend -
4803 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4804 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4805 if (r_type == R_390_GOTOFF16)
4806 *(unsigned short *) loc = val;
4807 else if (r_type == R_390_GOTOFF32)
4808 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4809 break;
4810 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4811 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4812 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4813 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4814 rela->r_addend - loc;
4815 if (r_type == R_390_GOTPC)
4816 *(unsigned int *) loc = val;
4817 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4818 index e795933..b32563c 100644
4819 --- a/arch/s390/kernel/process.c
4820 +++ b/arch/s390/kernel/process.c
4821 @@ -323,39 +323,3 @@ unsigned long get_wchan(struct task_struct *p)
4822 }
4823 return 0;
4824 }
4825 -
4826 -unsigned long arch_align_stack(unsigned long sp)
4827 -{
4828 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4829 - sp -= get_random_int() & ~PAGE_MASK;
4830 - return sp & ~0xf;
4831 -}
4832 -
4833 -static inline unsigned long brk_rnd(void)
4834 -{
4835 - /* 8MB for 32bit, 1GB for 64bit */
4836 - if (is_32bit_task())
4837 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4838 - else
4839 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4840 -}
4841 -
4842 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4843 -{
4844 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4845 -
4846 - if (ret < mm->brk)
4847 - return mm->brk;
4848 - return ret;
4849 -}
4850 -
4851 -unsigned long randomize_et_dyn(unsigned long base)
4852 -{
4853 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4854 -
4855 - if (!(current->flags & PF_RANDOMIZE))
4856 - return base;
4857 - if (ret < base)
4858 - return base;
4859 - return ret;
4860 -}
4861 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4862 index a0155c0..34cc491 100644
4863 --- a/arch/s390/mm/mmap.c
4864 +++ b/arch/s390/mm/mmap.c
4865 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4866 */
4867 if (mmap_is_legacy()) {
4868 mm->mmap_base = TASK_UNMAPPED_BASE;
4869 +
4870 +#ifdef CONFIG_PAX_RANDMMAP
4871 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4872 + mm->mmap_base += mm->delta_mmap;
4873 +#endif
4874 +
4875 mm->get_unmapped_area = arch_get_unmapped_area;
4876 mm->unmap_area = arch_unmap_area;
4877 } else {
4878 mm->mmap_base = mmap_base();
4879 +
4880 +#ifdef CONFIG_PAX_RANDMMAP
4881 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4882 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4883 +#endif
4884 +
4885 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4886 mm->unmap_area = arch_unmap_area_topdown;
4887 }
4888 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4889 */
4890 if (mmap_is_legacy()) {
4891 mm->mmap_base = TASK_UNMAPPED_BASE;
4892 +
4893 +#ifdef CONFIG_PAX_RANDMMAP
4894 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4895 + mm->mmap_base += mm->delta_mmap;
4896 +#endif
4897 +
4898 mm->get_unmapped_area = s390_get_unmapped_area;
4899 mm->unmap_area = arch_unmap_area;
4900 } else {
4901 mm->mmap_base = mmap_base();
4902 +
4903 +#ifdef CONFIG_PAX_RANDMMAP
4904 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4905 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4906 +#endif
4907 +
4908 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4909 mm->unmap_area = arch_unmap_area_topdown;
4910 }
4911 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4912 index ae3d59f..f65f075 100644
4913 --- a/arch/score/include/asm/cache.h
4914 +++ b/arch/score/include/asm/cache.h
4915 @@ -1,7 +1,9 @@
4916 #ifndef _ASM_SCORE_CACHE_H
4917 #define _ASM_SCORE_CACHE_H
4918
4919 +#include <linux/const.h>
4920 +
4921 #define L1_CACHE_SHIFT 4
4922 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4923 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4924
4925 #endif /* _ASM_SCORE_CACHE_H */
4926 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4927 index 589d5c7..669e274 100644
4928 --- a/arch/score/include/asm/system.h
4929 +++ b/arch/score/include/asm/system.h
4930 @@ -17,7 +17,7 @@ do { \
4931 #define finish_arch_switch(prev) do {} while (0)
4932
4933 typedef void (*vi_handler_t)(void);
4934 -extern unsigned long arch_align_stack(unsigned long sp);
4935 +#define arch_align_stack(x) (x)
4936
4937 #define mb() barrier()
4938 #define rmb() barrier()
4939 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4940 index 25d0803..d6c8e36 100644
4941 --- a/arch/score/kernel/process.c
4942 +++ b/arch/score/kernel/process.c
4943 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4944
4945 return task_pt_regs(task)->cp0_epc;
4946 }
4947 -
4948 -unsigned long arch_align_stack(unsigned long sp)
4949 -{
4950 - return sp;
4951 -}
4952 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4953 index ef9e555..331bd29 100644
4954 --- a/arch/sh/include/asm/cache.h
4955 +++ b/arch/sh/include/asm/cache.h
4956 @@ -9,10 +9,11 @@
4957 #define __ASM_SH_CACHE_H
4958 #ifdef __KERNEL__
4959
4960 +#include <linux/const.h>
4961 #include <linux/init.h>
4962 #include <cpu/cache.h>
4963
4964 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4965 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4966
4967 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4968
4969 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4970 index afeb710..d1d1289 100644
4971 --- a/arch/sh/mm/mmap.c
4972 +++ b/arch/sh/mm/mmap.c
4973 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4974 addr = PAGE_ALIGN(addr);
4975
4976 vma = find_vma(mm, addr);
4977 - if (TASK_SIZE - len >= addr &&
4978 - (!vma || addr + len <= vma->vm_start))
4979 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4980 return addr;
4981 }
4982
4983 @@ -106,7 +105,7 @@ full_search:
4984 }
4985 return -ENOMEM;
4986 }
4987 - if (likely(!vma || addr + len <= vma->vm_start)) {
4988 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4989 /*
4990 * Remember the place where we stopped the search:
4991 */
4992 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4993 addr = PAGE_ALIGN(addr);
4994
4995 vma = find_vma(mm, addr);
4996 - if (TASK_SIZE - len >= addr &&
4997 - (!vma || addr + len <= vma->vm_start))
4998 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4999 return addr;
5000 }
5001
5002 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5003 /* make sure it can fit in the remaining address space */
5004 if (likely(addr > len)) {
5005 vma = find_vma(mm, addr-len);
5006 - if (!vma || addr <= vma->vm_start) {
5007 + if (check_heap_stack_gap(vma, addr - len, len)) {
5008 /* remember the address as a hint for next time */
5009 return (mm->free_area_cache = addr-len);
5010 }
5011 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5012 if (unlikely(mm->mmap_base < len))
5013 goto bottomup;
5014
5015 - addr = mm->mmap_base-len;
5016 - if (do_colour_align)
5017 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5018 + addr = mm->mmap_base - len;
5019
5020 do {
5021 + if (do_colour_align)
5022 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5023 /*
5024 * Lookup failure means no vma is above this address,
5025 * else if new region fits below vma->vm_start,
5026 * return with success:
5027 */
5028 vma = find_vma(mm, addr);
5029 - if (likely(!vma || addr+len <= vma->vm_start)) {
5030 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5031 /* remember the address as a hint for next time */
5032 return (mm->free_area_cache = addr);
5033 }
5034 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5035 mm->cached_hole_size = vma->vm_start - addr;
5036
5037 /* try just below the current vma->vm_start */
5038 - addr = vma->vm_start-len;
5039 - if (do_colour_align)
5040 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5041 - } while (likely(len < vma->vm_start));
5042 + addr = skip_heap_stack_gap(vma, len);
5043 + } while (!IS_ERR_VALUE(addr));
5044
5045 bottomup:
5046 /*
5047 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
5048 index eddcfb3..b117d90 100644
5049 --- a/arch/sparc/Makefile
5050 +++ b/arch/sparc/Makefile
5051 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
5052 # Export what is needed by arch/sparc/boot/Makefile
5053 export VMLINUX_INIT VMLINUX_MAIN
5054 VMLINUX_INIT := $(head-y) $(init-y)
5055 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5056 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
5057 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
5058 VMLINUX_MAIN += $(drivers-y) $(net-y)
5059
5060 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5061 index 9f421df..b81fc12 100644
5062 --- a/arch/sparc/include/asm/atomic_64.h
5063 +++ b/arch/sparc/include/asm/atomic_64.h
5064 @@ -14,18 +14,40 @@
5065 #define ATOMIC64_INIT(i) { (i) }
5066
5067 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5068 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5069 +{
5070 + return v->counter;
5071 +}
5072 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5073 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5074 +{
5075 + return v->counter;
5076 +}
5077
5078 #define atomic_set(v, i) (((v)->counter) = i)
5079 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5080 +{
5081 + v->counter = i;
5082 +}
5083 #define atomic64_set(v, i) (((v)->counter) = i)
5084 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5085 +{
5086 + v->counter = i;
5087 +}
5088
5089 extern void atomic_add(int, atomic_t *);
5090 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5091 extern void atomic64_add(long, atomic64_t *);
5092 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5093 extern void atomic_sub(int, atomic_t *);
5094 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5095 extern void atomic64_sub(long, atomic64_t *);
5096 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5097
5098 extern int atomic_add_ret(int, atomic_t *);
5099 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5100 extern long atomic64_add_ret(long, atomic64_t *);
5101 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5102 extern int atomic_sub_ret(int, atomic_t *);
5103 extern long atomic64_sub_ret(long, atomic64_t *);
5104
5105 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5106 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5107
5108 #define atomic_inc_return(v) atomic_add_ret(1, v)
5109 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5110 +{
5111 + return atomic_add_ret_unchecked(1, v);
5112 +}
5113 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5114 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5115 +{
5116 + return atomic64_add_ret_unchecked(1, v);
5117 +}
5118
5119 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5120 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5121
5122 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5123 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5124 +{
5125 + return atomic_add_ret_unchecked(i, v);
5126 +}
5127 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5128 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5129 +{
5130 + return atomic64_add_ret_unchecked(i, v);
5131 +}
5132
5133 /*
5134 * atomic_inc_and_test - increment and test
5135 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5136 * other cases.
5137 */
5138 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5139 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5140 +{
5141 + return atomic_inc_return_unchecked(v) == 0;
5142 +}
5143 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5144
5145 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5146 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5147 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5148
5149 #define atomic_inc(v) atomic_add(1, v)
5150 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5151 +{
5152 + atomic_add_unchecked(1, v);
5153 +}
5154 #define atomic64_inc(v) atomic64_add(1, v)
5155 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5156 +{
5157 + atomic64_add_unchecked(1, v);
5158 +}
5159
5160 #define atomic_dec(v) atomic_sub(1, v)
5161 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5162 +{
5163 + atomic_sub_unchecked(1, v);
5164 +}
5165 #define atomic64_dec(v) atomic64_sub(1, v)
5166 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5167 +{
5168 + atomic64_sub_unchecked(1, v);
5169 +}
5170
5171 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5172 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5173
5174 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5175 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5176 +{
5177 + return cmpxchg(&v->counter, old, new);
5178 +}
5179 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5180 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5181 +{
5182 + return xchg(&v->counter, new);
5183 +}
5184
5185 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5186 {
5187 - int c, old;
5188 + int c, old, new;
5189 c = atomic_read(v);
5190 for (;;) {
5191 - if (unlikely(c == (u)))
5192 + if (unlikely(c == u))
5193 break;
5194 - old = atomic_cmpxchg((v), c, c + (a));
5195 +
5196 + asm volatile("addcc %2, %0, %0\n"
5197 +
5198 +#ifdef CONFIG_PAX_REFCOUNT
5199 + "tvs %%icc, 6\n"
5200 +#endif
5201 +
5202 + : "=r" (new)
5203 + : "0" (c), "ir" (a)
5204 + : "cc");
5205 +
5206 + old = atomic_cmpxchg(v, c, new);
5207 if (likely(old == c))
5208 break;
5209 c = old;
5210 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5211 #define atomic64_cmpxchg(v, o, n) \
5212 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5213 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5214 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5215 +{
5216 + return xchg(&v->counter, new);
5217 +}
5218
5219 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5220 {
5221 - long c, old;
5222 + long c, old, new;
5223 c = atomic64_read(v);
5224 for (;;) {
5225 - if (unlikely(c == (u)))
5226 + if (unlikely(c == u))
5227 break;
5228 - old = atomic64_cmpxchg((v), c, c + (a));
5229 +
5230 + asm volatile("addcc %2, %0, %0\n"
5231 +
5232 +#ifdef CONFIG_PAX_REFCOUNT
5233 + "tvs %%xcc, 6\n"
5234 +#endif
5235 +
5236 + : "=r" (new)
5237 + : "0" (c), "ir" (a)
5238 + : "cc");
5239 +
5240 + old = atomic64_cmpxchg(v, c, new);
5241 if (likely(old == c))
5242 break;
5243 c = old;
5244 }
5245 - return c != (u);
5246 + return c != u;
5247 }
5248
5249 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5250 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5251 index 69358b5..9d0d492 100644
5252 --- a/arch/sparc/include/asm/cache.h
5253 +++ b/arch/sparc/include/asm/cache.h
5254 @@ -7,10 +7,12 @@
5255 #ifndef _SPARC_CACHE_H
5256 #define _SPARC_CACHE_H
5257
5258 +#include <linux/const.h>
5259 +
5260 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5261
5262 #define L1_CACHE_SHIFT 5
5263 -#define L1_CACHE_BYTES 32
5264 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5265
5266 #ifdef CONFIG_SPARC32
5267 #define SMP_CACHE_BYTES_SHIFT 5
5268 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5269 index 4269ca6..e3da77f 100644
5270 --- a/arch/sparc/include/asm/elf_32.h
5271 +++ b/arch/sparc/include/asm/elf_32.h
5272 @@ -114,6 +114,13 @@ typedef struct {
5273
5274 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5275
5276 +#ifdef CONFIG_PAX_ASLR
5277 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5278 +
5279 +#define PAX_DELTA_MMAP_LEN 16
5280 +#define PAX_DELTA_STACK_LEN 16
5281 +#endif
5282 +
5283 /* This yields a mask that user programs can use to figure out what
5284 instruction set this cpu supports. This can NOT be done in userspace
5285 on Sparc. */
5286 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5287 index 7df8b7f..4946269 100644
5288 --- a/arch/sparc/include/asm/elf_64.h
5289 +++ b/arch/sparc/include/asm/elf_64.h
5290 @@ -180,6 +180,13 @@ typedef struct {
5291 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5292 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5293
5294 +#ifdef CONFIG_PAX_ASLR
5295 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5296 +
5297 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5298 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5299 +#endif
5300 +
5301 extern unsigned long sparc64_elf_hwcap;
5302 #define ELF_HWCAP sparc64_elf_hwcap
5303
5304 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5305 index ca2b344..c6084f89 100644
5306 --- a/arch/sparc/include/asm/pgalloc_32.h
5307 +++ b/arch/sparc/include/asm/pgalloc_32.h
5308 @@ -37,6 +37,7 @@ BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
5309 BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
5310 #define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
5311 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5312 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5313
5314 BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
5315 #define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
5316 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5317 index 40b2d7a..22a665b 100644
5318 --- a/arch/sparc/include/asm/pgalloc_64.h
5319 +++ b/arch/sparc/include/asm/pgalloc_64.h
5320 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5321 }
5322
5323 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5324 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5325
5326 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5327 {
5328 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5329 index a790cc6..091ed94 100644
5330 --- a/arch/sparc/include/asm/pgtable_32.h
5331 +++ b/arch/sparc/include/asm/pgtable_32.h
5332 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5333 BTFIXUPDEF_INT(page_none)
5334 BTFIXUPDEF_INT(page_copy)
5335 BTFIXUPDEF_INT(page_readonly)
5336 +
5337 +#ifdef CONFIG_PAX_PAGEEXEC
5338 +BTFIXUPDEF_INT(page_shared_noexec)
5339 +BTFIXUPDEF_INT(page_copy_noexec)
5340 +BTFIXUPDEF_INT(page_readonly_noexec)
5341 +#endif
5342 +
5343 BTFIXUPDEF_INT(page_kernel)
5344
5345 #define PMD_SHIFT SUN4C_PMD_SHIFT
5346 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
5347 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5348 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5349
5350 +#ifdef CONFIG_PAX_PAGEEXEC
5351 +extern pgprot_t PAGE_SHARED_NOEXEC;
5352 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5353 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5354 +#else
5355 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5356 +# define PAGE_COPY_NOEXEC PAGE_COPY
5357 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5358 +#endif
5359 +
5360 extern unsigned long page_kernel;
5361
5362 #ifdef MODULE
5363 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5364 index f6ae2b2..b03ffc7 100644
5365 --- a/arch/sparc/include/asm/pgtsrmmu.h
5366 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5367 @@ -115,6 +115,13 @@
5368 SRMMU_EXEC | SRMMU_REF)
5369 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5370 SRMMU_EXEC | SRMMU_REF)
5371 +
5372 +#ifdef CONFIG_PAX_PAGEEXEC
5373 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5374 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5375 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5376 +#endif
5377 +
5378 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5379 SRMMU_DIRTY | SRMMU_REF)
5380
5381 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5382 index 9689176..63c18ea 100644
5383 --- a/arch/sparc/include/asm/spinlock_64.h
5384 +++ b/arch/sparc/include/asm/spinlock_64.h
5385 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5386
5387 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5388
5389 -static void inline arch_read_lock(arch_rwlock_t *lock)
5390 +static inline void arch_read_lock(arch_rwlock_t *lock)
5391 {
5392 unsigned long tmp1, tmp2;
5393
5394 __asm__ __volatile__ (
5395 "1: ldsw [%2], %0\n"
5396 " brlz,pn %0, 2f\n"
5397 -"4: add %0, 1, %1\n"
5398 +"4: addcc %0, 1, %1\n"
5399 +
5400 +#ifdef CONFIG_PAX_REFCOUNT
5401 +" tvs %%icc, 6\n"
5402 +#endif
5403 +
5404 " cas [%2], %0, %1\n"
5405 " cmp %0, %1\n"
5406 " bne,pn %%icc, 1b\n"
5407 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5408 " .previous"
5409 : "=&r" (tmp1), "=&r" (tmp2)
5410 : "r" (lock)
5411 - : "memory");
5412 + : "memory", "cc");
5413 }
5414
5415 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5416 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5417 {
5418 int tmp1, tmp2;
5419
5420 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5421 "1: ldsw [%2], %0\n"
5422 " brlz,a,pn %0, 2f\n"
5423 " mov 0, %0\n"
5424 -" add %0, 1, %1\n"
5425 +" addcc %0, 1, %1\n"
5426 +
5427 +#ifdef CONFIG_PAX_REFCOUNT
5428 +" tvs %%icc, 6\n"
5429 +#endif
5430 +
5431 " cas [%2], %0, %1\n"
5432 " cmp %0, %1\n"
5433 " bne,pn %%icc, 1b\n"
5434 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5435 return tmp1;
5436 }
5437
5438 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5439 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5440 {
5441 unsigned long tmp1, tmp2;
5442
5443 __asm__ __volatile__(
5444 "1: lduw [%2], %0\n"
5445 -" sub %0, 1, %1\n"
5446 +" subcc %0, 1, %1\n"
5447 +
5448 +#ifdef CONFIG_PAX_REFCOUNT
5449 +" tvs %%icc, 6\n"
5450 +#endif
5451 +
5452 " cas [%2], %0, %1\n"
5453 " cmp %0, %1\n"
5454 " bne,pn %%xcc, 1b\n"
5455 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5456 : "memory");
5457 }
5458
5459 -static void inline arch_write_lock(arch_rwlock_t *lock)
5460 +static inline void arch_write_lock(arch_rwlock_t *lock)
5461 {
5462 unsigned long mask, tmp1, tmp2;
5463
5464 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5465 : "memory");
5466 }
5467
5468 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5469 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5470 {
5471 __asm__ __volatile__(
5472 " stw %%g0, [%0]"
5473 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5474 : "memory");
5475 }
5476
5477 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5478 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5479 {
5480 unsigned long mask, tmp1, tmp2, result;
5481
5482 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5483 index c2a1080..21ed218 100644
5484 --- a/arch/sparc/include/asm/thread_info_32.h
5485 +++ b/arch/sparc/include/asm/thread_info_32.h
5486 @@ -50,6 +50,8 @@ struct thread_info {
5487 unsigned long w_saved;
5488
5489 struct restart_block restart_block;
5490 +
5491 + unsigned long lowest_stack;
5492 };
5493
5494 /*
5495 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5496 index 01d057f..13a7d2f 100644
5497 --- a/arch/sparc/include/asm/thread_info_64.h
5498 +++ b/arch/sparc/include/asm/thread_info_64.h
5499 @@ -63,6 +63,8 @@ struct thread_info {
5500 struct pt_regs *kern_una_regs;
5501 unsigned int kern_una_insn;
5502
5503 + unsigned long lowest_stack;
5504 +
5505 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5506 };
5507
5508 @@ -214,10 +216,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5509 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5510 /* flag bit 6 is available */
5511 #define TIF_32BIT 7 /* 32-bit binary */
5512 -/* flag bit 8 is available */
5513 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5514 #define TIF_SECCOMP 9 /* secure computing */
5515 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5516 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5517 +
5518 /* NOTE: Thread flags >= 12 should be ones we have no interest
5519 * in using in assembly, else we can't use the mask as
5520 * an immediate value in instructions such as andcc.
5521 @@ -236,12 +239,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5522 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5523 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5524 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5525 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5526
5527 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5528 _TIF_DO_NOTIFY_RESUME_MASK | \
5529 _TIF_NEED_RESCHED)
5530 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5531
5532 +#define _TIF_WORK_SYSCALL \
5533 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5534 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5535 +
5536 +
5537 /*
5538 * Thread-synchronous status.
5539 *
5540 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5541 index e88fbe5..96b0ce5 100644
5542 --- a/arch/sparc/include/asm/uaccess.h
5543 +++ b/arch/sparc/include/asm/uaccess.h
5544 @@ -1,5 +1,13 @@
5545 #ifndef ___ASM_SPARC_UACCESS_H
5546 #define ___ASM_SPARC_UACCESS_H
5547 +
5548 +#ifdef __KERNEL__
5549 +#ifndef __ASSEMBLY__
5550 +#include <linux/types.h>
5551 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5552 +#endif
5553 +#endif
5554 +
5555 #if defined(__sparc__) && defined(__arch64__)
5556 #include <asm/uaccess_64.h>
5557 #else
5558 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5559 index 8303ac4..07f333d 100644
5560 --- a/arch/sparc/include/asm/uaccess_32.h
5561 +++ b/arch/sparc/include/asm/uaccess_32.h
5562 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5563
5564 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5565 {
5566 - if (n && __access_ok((unsigned long) to, n))
5567 + if ((long)n < 0)
5568 + return n;
5569 +
5570 + if (n && __access_ok((unsigned long) to, n)) {
5571 + if (!__builtin_constant_p(n))
5572 + check_object_size(from, n, true);
5573 return __copy_user(to, (__force void __user *) from, n);
5574 - else
5575 + } else
5576 return n;
5577 }
5578
5579 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5580 {
5581 + if ((long)n < 0)
5582 + return n;
5583 +
5584 + if (!__builtin_constant_p(n))
5585 + check_object_size(from, n, true);
5586 +
5587 return __copy_user(to, (__force void __user *) from, n);
5588 }
5589
5590 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5591 {
5592 - if (n && __access_ok((unsigned long) from, n))
5593 + if ((long)n < 0)
5594 + return n;
5595 +
5596 + if (n && __access_ok((unsigned long) from, n)) {
5597 + if (!__builtin_constant_p(n))
5598 + check_object_size(to, n, false);
5599 return __copy_user((__force void __user *) to, from, n);
5600 - else
5601 + } else
5602 return n;
5603 }
5604
5605 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5606 {
5607 + if ((long)n < 0)
5608 + return n;
5609 +
5610 return __copy_user((__force void __user *) to, from, n);
5611 }
5612
5613 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5614 index 3e1449f..5293a0e 100644
5615 --- a/arch/sparc/include/asm/uaccess_64.h
5616 +++ b/arch/sparc/include/asm/uaccess_64.h
5617 @@ -10,6 +10,7 @@
5618 #include <linux/compiler.h>
5619 #include <linux/string.h>
5620 #include <linux/thread_info.h>
5621 +#include <linux/kernel.h>
5622 #include <asm/asi.h>
5623 #include <asm/system.h>
5624 #include <asm/spitfire.h>
5625 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5626 static inline unsigned long __must_check
5627 copy_from_user(void *to, const void __user *from, unsigned long size)
5628 {
5629 - unsigned long ret = ___copy_from_user(to, from, size);
5630 + unsigned long ret;
5631
5632 + if ((long)size < 0 || size > INT_MAX)
5633 + return size;
5634 +
5635 + if (!__builtin_constant_p(size))
5636 + check_object_size(to, size, false);
5637 +
5638 + ret = ___copy_from_user(to, from, size);
5639 if (unlikely(ret))
5640 ret = copy_from_user_fixup(to, from, size);
5641
5642 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5643 static inline unsigned long __must_check
5644 copy_to_user(void __user *to, const void *from, unsigned long size)
5645 {
5646 - unsigned long ret = ___copy_to_user(to, from, size);
5647 + unsigned long ret;
5648
5649 + if ((long)size < 0 || size > INT_MAX)
5650 + return size;
5651 +
5652 + if (!__builtin_constant_p(size))
5653 + check_object_size(from, size, true);
5654 +
5655 + ret = ___copy_to_user(to, from, size);
5656 if (unlikely(ret))
5657 ret = copy_to_user_fixup(to, from, size);
5658 return ret;
5659 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5660 index cb85458..e063f17 100644
5661 --- a/arch/sparc/kernel/Makefile
5662 +++ b/arch/sparc/kernel/Makefile
5663 @@ -3,7 +3,7 @@
5664 #
5665
5666 asflags-y := -ansi
5667 -ccflags-y := -Werror
5668 +#ccflags-y := -Werror
5669
5670 extra-y := head_$(BITS).o
5671 extra-y += init_task.o
5672 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5673 index f793742..4d880af 100644
5674 --- a/arch/sparc/kernel/process_32.c
5675 +++ b/arch/sparc/kernel/process_32.c
5676 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
5677 rw->ins[4], rw->ins[5],
5678 rw->ins[6],
5679 rw->ins[7]);
5680 - printk("%pS\n", (void *) rw->ins[7]);
5681 + printk("%pA\n", (void *) rw->ins[7]);
5682 rw = (struct reg_window32 *) rw->ins[6];
5683 }
5684 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5685 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
5686
5687 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5688 r->psr, r->pc, r->npc, r->y, print_tainted());
5689 - printk("PC: <%pS>\n", (void *) r->pc);
5690 + printk("PC: <%pA>\n", (void *) r->pc);
5691 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5692 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5693 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5694 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5695 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5696 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5697 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5698 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5699
5700 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5701 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5702 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5703 rw = (struct reg_window32 *) fp;
5704 pc = rw->ins[7];
5705 printk("[%08lx : ", pc);
5706 - printk("%pS ] ", (void *) pc);
5707 + printk("%pA ] ", (void *) pc);
5708 fp = rw->ins[6];
5709 } while (++count < 16);
5710 printk("\n");
5711 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5712 index 39d8b05..d1a7d90 100644
5713 --- a/arch/sparc/kernel/process_64.c
5714 +++ b/arch/sparc/kernel/process_64.c
5715 @@ -182,14 +182,14 @@ static void show_regwindow(struct pt_regs *regs)
5716 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5717 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5718 if (regs->tstate & TSTATE_PRIV)
5719 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5720 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5721 }
5722
5723 void show_regs(struct pt_regs *regs)
5724 {
5725 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5726 regs->tpc, regs->tnpc, regs->y, print_tainted());
5727 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5728 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5729 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5730 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5731 regs->u_regs[3]);
5732 @@ -202,7 +202,7 @@ void show_regs(struct pt_regs *regs)
5733 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5734 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5735 regs->u_regs[15]);
5736 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5737 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5738 show_regwindow(regs);
5739 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5740 }
5741 @@ -287,7 +287,7 @@ void arch_trigger_all_cpu_backtrace(void)
5742 ((tp && tp->task) ? tp->task->pid : -1));
5743
5744 if (gp->tstate & TSTATE_PRIV) {
5745 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5746 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5747 (void *) gp->tpc,
5748 (void *) gp->o7,
5749 (void *) gp->i7,
5750 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5751 index 9388844..0075fd2 100644
5752 --- a/arch/sparc/kernel/ptrace_64.c
5753 +++ b/arch/sparc/kernel/ptrace_64.c
5754 @@ -1058,6 +1058,10 @@ long arch_ptrace(struct task_struct *child, long request,
5755 return ret;
5756 }
5757
5758 +#ifdef CONFIG_GRKERNSEC_SETXID
5759 +extern void gr_delayed_cred_worker(void);
5760 +#endif
5761 +
5762 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5763 {
5764 int ret = 0;
5765 @@ -1065,6 +1069,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5766 /* do the secure computing check first */
5767 secure_computing(regs->u_regs[UREG_G1]);
5768
5769 +#ifdef CONFIG_GRKERNSEC_SETXID
5770 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5771 + gr_delayed_cred_worker();
5772 +#endif
5773 +
5774 if (test_thread_flag(TIF_SYSCALL_TRACE))
5775 ret = tracehook_report_syscall_entry(regs);
5776
5777 @@ -1085,6 +1094,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5778
5779 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5780 {
5781 +#ifdef CONFIG_GRKERNSEC_SETXID
5782 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5783 + gr_delayed_cred_worker();
5784 +#endif
5785 +
5786 audit_syscall_exit(regs);
5787
5788 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5789 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5790 index 42b282f..28ce9f2 100644
5791 --- a/arch/sparc/kernel/sys_sparc_32.c
5792 +++ b/arch/sparc/kernel/sys_sparc_32.c
5793 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5794 if (ARCH_SUN4C && len > 0x20000000)
5795 return -ENOMEM;
5796 if (!addr)
5797 - addr = TASK_UNMAPPED_BASE;
5798 + addr = current->mm->mmap_base;
5799
5800 if (flags & MAP_SHARED)
5801 addr = COLOUR_ALIGN(addr);
5802 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5803 }
5804 if (TASK_SIZE - PAGE_SIZE - len < addr)
5805 return -ENOMEM;
5806 - if (!vmm || addr + len <= vmm->vm_start)
5807 + if (check_heap_stack_gap(vmm, addr, len))
5808 return addr;
5809 addr = vmm->vm_end;
5810 if (flags & MAP_SHARED)
5811 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5812 index 232df99..cee1f9c 100644
5813 --- a/arch/sparc/kernel/sys_sparc_64.c
5814 +++ b/arch/sparc/kernel/sys_sparc_64.c
5815 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5816 /* We do not accept a shared mapping if it would violate
5817 * cache aliasing constraints.
5818 */
5819 - if ((flags & MAP_SHARED) &&
5820 + if ((filp || (flags & MAP_SHARED)) &&
5821 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5822 return -EINVAL;
5823 return addr;
5824 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5825 if (filp || (flags & MAP_SHARED))
5826 do_color_align = 1;
5827
5828 +#ifdef CONFIG_PAX_RANDMMAP
5829 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5830 +#endif
5831 +
5832 if (addr) {
5833 if (do_color_align)
5834 addr = COLOUR_ALIGN(addr, pgoff);
5835 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5836 addr = PAGE_ALIGN(addr);
5837
5838 vma = find_vma(mm, addr);
5839 - if (task_size - len >= addr &&
5840 - (!vma || addr + len <= vma->vm_start))
5841 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5842 return addr;
5843 }
5844
5845 if (len > mm->cached_hole_size) {
5846 - start_addr = addr = mm->free_area_cache;
5847 + start_addr = addr = mm->free_area_cache;
5848 } else {
5849 - start_addr = addr = TASK_UNMAPPED_BASE;
5850 + start_addr = addr = mm->mmap_base;
5851 mm->cached_hole_size = 0;
5852 }
5853
5854 @@ -174,14 +177,14 @@ full_search:
5855 vma = find_vma(mm, VA_EXCLUDE_END);
5856 }
5857 if (unlikely(task_size < addr)) {
5858 - if (start_addr != TASK_UNMAPPED_BASE) {
5859 - start_addr = addr = TASK_UNMAPPED_BASE;
5860 + if (start_addr != mm->mmap_base) {
5861 + start_addr = addr = mm->mmap_base;
5862 mm->cached_hole_size = 0;
5863 goto full_search;
5864 }
5865 return -ENOMEM;
5866 }
5867 - if (likely(!vma || addr + len <= vma->vm_start)) {
5868 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5869 /*
5870 * Remember the place where we stopped the search:
5871 */
5872 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5873 /* We do not accept a shared mapping if it would violate
5874 * cache aliasing constraints.
5875 */
5876 - if ((flags & MAP_SHARED) &&
5877 + if ((filp || (flags & MAP_SHARED)) &&
5878 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5879 return -EINVAL;
5880 return addr;
5881 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5882 addr = PAGE_ALIGN(addr);
5883
5884 vma = find_vma(mm, addr);
5885 - if (task_size - len >= addr &&
5886 - (!vma || addr + len <= vma->vm_start))
5887 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5888 return addr;
5889 }
5890
5891 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5892 /* make sure it can fit in the remaining address space */
5893 if (likely(addr > len)) {
5894 vma = find_vma(mm, addr-len);
5895 - if (!vma || addr <= vma->vm_start) {
5896 + if (check_heap_stack_gap(vma, addr - len, len)) {
5897 /* remember the address as a hint for next time */
5898 return (mm->free_area_cache = addr-len);
5899 }
5900 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5901 if (unlikely(mm->mmap_base < len))
5902 goto bottomup;
5903
5904 - addr = mm->mmap_base-len;
5905 - if (do_color_align)
5906 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5907 + addr = mm->mmap_base - len;
5908
5909 do {
5910 + if (do_color_align)
5911 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5912 /*
5913 * Lookup failure means no vma is above this address,
5914 * else if new region fits below vma->vm_start,
5915 * return with success:
5916 */
5917 vma = find_vma(mm, addr);
5918 - if (likely(!vma || addr+len <= vma->vm_start)) {
5919 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5920 /* remember the address as a hint for next time */
5921 return (mm->free_area_cache = addr);
5922 }
5923 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5924 mm->cached_hole_size = vma->vm_start - addr;
5925
5926 /* try just below the current vma->vm_start */
5927 - addr = vma->vm_start-len;
5928 - if (do_color_align)
5929 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5930 - } while (likely(len < vma->vm_start));
5931 + addr = skip_heap_stack_gap(vma, len);
5932 + } while (!IS_ERR_VALUE(addr));
5933
5934 bottomup:
5935 /*
5936 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5937 gap == RLIM_INFINITY ||
5938 sysctl_legacy_va_layout) {
5939 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5940 +
5941 +#ifdef CONFIG_PAX_RANDMMAP
5942 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5943 + mm->mmap_base += mm->delta_mmap;
5944 +#endif
5945 +
5946 mm->get_unmapped_area = arch_get_unmapped_area;
5947 mm->unmap_area = arch_unmap_area;
5948 } else {
5949 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5950 gap = (task_size / 6 * 5);
5951
5952 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5953 +
5954 +#ifdef CONFIG_PAX_RANDMMAP
5955 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5956 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5957 +#endif
5958 +
5959 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5960 mm->unmap_area = arch_unmap_area_topdown;
5961 }
5962 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5963 index 1d7e274..b39c527 100644
5964 --- a/arch/sparc/kernel/syscalls.S
5965 +++ b/arch/sparc/kernel/syscalls.S
5966 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5967 #endif
5968 .align 32
5969 1: ldx [%g6 + TI_FLAGS], %l5
5970 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5971 + andcc %l5, _TIF_WORK_SYSCALL, %g0
5972 be,pt %icc, rtrap
5973 nop
5974 call syscall_trace_leave
5975 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
5976
5977 srl %i5, 0, %o5 ! IEU1
5978 srl %i2, 0, %o2 ! IEU0 Group
5979 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5980 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5981 bne,pn %icc, linux_syscall_trace32 ! CTI
5982 mov %i0, %l5 ! IEU1
5983 call %l7 ! CTI Group brk forced
5984 @@ -202,7 +202,7 @@ linux_sparc_syscall:
5985
5986 mov %i3, %o3 ! IEU1
5987 mov %i4, %o4 ! IEU0 Group
5988 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5989 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5990 bne,pn %icc, linux_syscall_trace ! CTI Group
5991 mov %i0, %l5 ! IEU0
5992 2: call %l7 ! CTI Group brk forced
5993 @@ -226,7 +226,7 @@ ret_sys_call:
5994
5995 cmp %o0, -ERESTART_RESTARTBLOCK
5996 bgeu,pn %xcc, 1f
5997 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
5998 + andcc %l0, _TIF_WORK_SYSCALL, %l6
5999 80:
6000 /* System call success, clear Carry condition code. */
6001 andn %g3, %g2, %g3
6002 @@ -241,7 +241,7 @@ ret_sys_call:
6003 /* System call failure, set Carry condition code.
6004 * Also, get abs(errno) to return to the process.
6005 */
6006 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6007 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6008 sub %g0, %o0, %o0
6009 or %g3, %g2, %g3
6010 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6011 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6012 index 591f20c..0f1b925 100644
6013 --- a/arch/sparc/kernel/traps_32.c
6014 +++ b/arch/sparc/kernel/traps_32.c
6015 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
6016 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6017 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6018
6019 +extern void gr_handle_kernel_exploit(void);
6020 +
6021 void die_if_kernel(char *str, struct pt_regs *regs)
6022 {
6023 static int die_counter;
6024 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6025 count++ < 30 &&
6026 (((unsigned long) rw) >= PAGE_OFFSET) &&
6027 !(((unsigned long) rw) & 0x7)) {
6028 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6029 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6030 (void *) rw->ins[7]);
6031 rw = (struct reg_window32 *)rw->ins[6];
6032 }
6033 }
6034 printk("Instruction DUMP:");
6035 instruction_dump ((unsigned long *) regs->pc);
6036 - if(regs->psr & PSR_PS)
6037 + if(regs->psr & PSR_PS) {
6038 + gr_handle_kernel_exploit();
6039 do_exit(SIGKILL);
6040 + }
6041 do_exit(SIGSEGV);
6042 }
6043
6044 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6045 index 0cbdaa4..438e4c9 100644
6046 --- a/arch/sparc/kernel/traps_64.c
6047 +++ b/arch/sparc/kernel/traps_64.c
6048 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6049 i + 1,
6050 p->trapstack[i].tstate, p->trapstack[i].tpc,
6051 p->trapstack[i].tnpc, p->trapstack[i].tt);
6052 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6053 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6054 }
6055 }
6056
6057 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6058
6059 lvl -= 0x100;
6060 if (regs->tstate & TSTATE_PRIV) {
6061 +
6062 +#ifdef CONFIG_PAX_REFCOUNT
6063 + if (lvl == 6)
6064 + pax_report_refcount_overflow(regs);
6065 +#endif
6066 +
6067 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6068 die_if_kernel(buffer, regs);
6069 }
6070 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6071 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6072 {
6073 char buffer[32];
6074 -
6075 +
6076 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6077 0, lvl, SIGTRAP) == NOTIFY_STOP)
6078 return;
6079
6080 +#ifdef CONFIG_PAX_REFCOUNT
6081 + if (lvl == 6)
6082 + pax_report_refcount_overflow(regs);
6083 +#endif
6084 +
6085 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6086
6087 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6088 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6089 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6090 printk("%s" "ERROR(%d): ",
6091 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6092 - printk("TPC<%pS>\n", (void *) regs->tpc);
6093 + printk("TPC<%pA>\n", (void *) regs->tpc);
6094 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6095 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6096 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6097 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6098 smp_processor_id(),
6099 (type & 0x1) ? 'I' : 'D',
6100 regs->tpc);
6101 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6102 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6103 panic("Irrecoverable Cheetah+ parity error.");
6104 }
6105
6106 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6107 smp_processor_id(),
6108 (type & 0x1) ? 'I' : 'D',
6109 regs->tpc);
6110 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6111 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6112 }
6113
6114 struct sun4v_error_entry {
6115 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6116
6117 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6118 regs->tpc, tl);
6119 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6120 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6121 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6122 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6123 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6124 (void *) regs->u_regs[UREG_I7]);
6125 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6126 "pte[%lx] error[%lx]\n",
6127 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6128
6129 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6130 regs->tpc, tl);
6131 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6132 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6133 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6134 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6135 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6136 (void *) regs->u_regs[UREG_I7]);
6137 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6138 "pte[%lx] error[%lx]\n",
6139 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6140 fp = (unsigned long)sf->fp + STACK_BIAS;
6141 }
6142
6143 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6144 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6145 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6146 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6147 int index = tsk->curr_ret_stack;
6148 if (tsk->ret_stack && index >= graph) {
6149 pc = tsk->ret_stack[index - graph].ret;
6150 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6151 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6152 graph++;
6153 }
6154 }
6155 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6156 return (struct reg_window *) (fp + STACK_BIAS);
6157 }
6158
6159 +extern void gr_handle_kernel_exploit(void);
6160 +
6161 void die_if_kernel(char *str, struct pt_regs *regs)
6162 {
6163 static int die_counter;
6164 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6165 while (rw &&
6166 count++ < 30 &&
6167 kstack_valid(tp, (unsigned long) rw)) {
6168 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6169 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6170 (void *) rw->ins[7]);
6171
6172 rw = kernel_stack_up(rw);
6173 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6174 }
6175 user_instruction_dump ((unsigned int __user *) regs->tpc);
6176 }
6177 - if (regs->tstate & TSTATE_PRIV)
6178 + if (regs->tstate & TSTATE_PRIV) {
6179 + gr_handle_kernel_exploit();
6180 do_exit(SIGKILL);
6181 + }
6182 do_exit(SIGSEGV);
6183 }
6184 EXPORT_SYMBOL(die_if_kernel);
6185 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6186 index 76e4ac1..78f8bb1 100644
6187 --- a/arch/sparc/kernel/unaligned_64.c
6188 +++ b/arch/sparc/kernel/unaligned_64.c
6189 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
6190 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6191
6192 if (__ratelimit(&ratelimit)) {
6193 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6194 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6195 regs->tpc, (void *) regs->tpc);
6196 }
6197 }
6198 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6199 index a3fc437..fea9957 100644
6200 --- a/arch/sparc/lib/Makefile
6201 +++ b/arch/sparc/lib/Makefile
6202 @@ -2,7 +2,7 @@
6203 #
6204
6205 asflags-y := -ansi -DST_DIV0=0x02
6206 -ccflags-y := -Werror
6207 +#ccflags-y := -Werror
6208
6209 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6210 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6211 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6212 index 59186e0..f747d7a 100644
6213 --- a/arch/sparc/lib/atomic_64.S
6214 +++ b/arch/sparc/lib/atomic_64.S
6215 @@ -18,7 +18,12 @@
6216 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6217 BACKOFF_SETUP(%o2)
6218 1: lduw [%o1], %g1
6219 - add %g1, %o0, %g7
6220 + addcc %g1, %o0, %g7
6221 +
6222 +#ifdef CONFIG_PAX_REFCOUNT
6223 + tvs %icc, 6
6224 +#endif
6225 +
6226 cas [%o1], %g1, %g7
6227 cmp %g1, %g7
6228 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6229 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6230 2: BACKOFF_SPIN(%o2, %o3, 1b)
6231 .size atomic_add, .-atomic_add
6232
6233 + .globl atomic_add_unchecked
6234 + .type atomic_add_unchecked,#function
6235 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6236 + BACKOFF_SETUP(%o2)
6237 +1: lduw [%o1], %g1
6238 + add %g1, %o0, %g7
6239 + cas [%o1], %g1, %g7
6240 + cmp %g1, %g7
6241 + bne,pn %icc, 2f
6242 + nop
6243 + retl
6244 + nop
6245 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6246 + .size atomic_add_unchecked, .-atomic_add_unchecked
6247 +
6248 .globl atomic_sub
6249 .type atomic_sub,#function
6250 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6251 BACKOFF_SETUP(%o2)
6252 1: lduw [%o1], %g1
6253 - sub %g1, %o0, %g7
6254 + subcc %g1, %o0, %g7
6255 +
6256 +#ifdef CONFIG_PAX_REFCOUNT
6257 + tvs %icc, 6
6258 +#endif
6259 +
6260 cas [%o1], %g1, %g7
6261 cmp %g1, %g7
6262 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6263 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6264 2: BACKOFF_SPIN(%o2, %o3, 1b)
6265 .size atomic_sub, .-atomic_sub
6266
6267 + .globl atomic_sub_unchecked
6268 + .type atomic_sub_unchecked,#function
6269 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6270 + BACKOFF_SETUP(%o2)
6271 +1: lduw [%o1], %g1
6272 + sub %g1, %o0, %g7
6273 + cas [%o1], %g1, %g7
6274 + cmp %g1, %g7
6275 + bne,pn %icc, 2f
6276 + nop
6277 + retl
6278 + nop
6279 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6280 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
6281 +
6282 .globl atomic_add_ret
6283 .type atomic_add_ret,#function
6284 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6285 BACKOFF_SETUP(%o2)
6286 1: lduw [%o1], %g1
6287 - add %g1, %o0, %g7
6288 + addcc %g1, %o0, %g7
6289 +
6290 +#ifdef CONFIG_PAX_REFCOUNT
6291 + tvs %icc, 6
6292 +#endif
6293 +
6294 cas [%o1], %g1, %g7
6295 cmp %g1, %g7
6296 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6297 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6298 2: BACKOFF_SPIN(%o2, %o3, 1b)
6299 .size atomic_add_ret, .-atomic_add_ret
6300
6301 + .globl atomic_add_ret_unchecked
6302 + .type atomic_add_ret_unchecked,#function
6303 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6304 + BACKOFF_SETUP(%o2)
6305 +1: lduw [%o1], %g1
6306 + addcc %g1, %o0, %g7
6307 + cas [%o1], %g1, %g7
6308 + cmp %g1, %g7
6309 + bne,pn %icc, 2f
6310 + add %g7, %o0, %g7
6311 + sra %g7, 0, %o0
6312 + retl
6313 + nop
6314 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6315 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6316 +
6317 .globl atomic_sub_ret
6318 .type atomic_sub_ret,#function
6319 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6320 BACKOFF_SETUP(%o2)
6321 1: lduw [%o1], %g1
6322 - sub %g1, %o0, %g7
6323 + subcc %g1, %o0, %g7
6324 +
6325 +#ifdef CONFIG_PAX_REFCOUNT
6326 + tvs %icc, 6
6327 +#endif
6328 +
6329 cas [%o1], %g1, %g7
6330 cmp %g1, %g7
6331 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6332 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6333 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6334 BACKOFF_SETUP(%o2)
6335 1: ldx [%o1], %g1
6336 - add %g1, %o0, %g7
6337 + addcc %g1, %o0, %g7
6338 +
6339 +#ifdef CONFIG_PAX_REFCOUNT
6340 + tvs %xcc, 6
6341 +#endif
6342 +
6343 casx [%o1], %g1, %g7
6344 cmp %g1, %g7
6345 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6346 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6347 2: BACKOFF_SPIN(%o2, %o3, 1b)
6348 .size atomic64_add, .-atomic64_add
6349
6350 + .globl atomic64_add_unchecked
6351 + .type atomic64_add_unchecked,#function
6352 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6353 + BACKOFF_SETUP(%o2)
6354 +1: ldx [%o1], %g1
6355 + addcc %g1, %o0, %g7
6356 + casx [%o1], %g1, %g7
6357 + cmp %g1, %g7
6358 + bne,pn %xcc, 2f
6359 + nop
6360 + retl
6361 + nop
6362 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6363 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
6364 +
6365 .globl atomic64_sub
6366 .type atomic64_sub,#function
6367 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6368 BACKOFF_SETUP(%o2)
6369 1: ldx [%o1], %g1
6370 - sub %g1, %o0, %g7
6371 + subcc %g1, %o0, %g7
6372 +
6373 +#ifdef CONFIG_PAX_REFCOUNT
6374 + tvs %xcc, 6
6375 +#endif
6376 +
6377 casx [%o1], %g1, %g7
6378 cmp %g1, %g7
6379 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6380 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6381 2: BACKOFF_SPIN(%o2, %o3, 1b)
6382 .size atomic64_sub, .-atomic64_sub
6383
6384 + .globl atomic64_sub_unchecked
6385 + .type atomic64_sub_unchecked,#function
6386 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6387 + BACKOFF_SETUP(%o2)
6388 +1: ldx [%o1], %g1
6389 + subcc %g1, %o0, %g7
6390 + casx [%o1], %g1, %g7
6391 + cmp %g1, %g7
6392 + bne,pn %xcc, 2f
6393 + nop
6394 + retl
6395 + nop
6396 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6397 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6398 +
6399 .globl atomic64_add_ret
6400 .type atomic64_add_ret,#function
6401 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6402 BACKOFF_SETUP(%o2)
6403 1: ldx [%o1], %g1
6404 - add %g1, %o0, %g7
6405 + addcc %g1, %o0, %g7
6406 +
6407 +#ifdef CONFIG_PAX_REFCOUNT
6408 + tvs %xcc, 6
6409 +#endif
6410 +
6411 casx [%o1], %g1, %g7
6412 cmp %g1, %g7
6413 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6414 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6415 2: BACKOFF_SPIN(%o2, %o3, 1b)
6416 .size atomic64_add_ret, .-atomic64_add_ret
6417
6418 + .globl atomic64_add_ret_unchecked
6419 + .type atomic64_add_ret_unchecked,#function
6420 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6421 + BACKOFF_SETUP(%o2)
6422 +1: ldx [%o1], %g1
6423 + addcc %g1, %o0, %g7
6424 + casx [%o1], %g1, %g7
6425 + cmp %g1, %g7
6426 + bne,pn %xcc, 2f
6427 + add %g7, %o0, %g7
6428 + mov %g7, %o0
6429 + retl
6430 + nop
6431 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6432 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6433 +
6434 .globl atomic64_sub_ret
6435 .type atomic64_sub_ret,#function
6436 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6437 BACKOFF_SETUP(%o2)
6438 1: ldx [%o1], %g1
6439 - sub %g1, %o0, %g7
6440 + subcc %g1, %o0, %g7
6441 +
6442 +#ifdef CONFIG_PAX_REFCOUNT
6443 + tvs %xcc, 6
6444 +#endif
6445 +
6446 casx [%o1], %g1, %g7
6447 cmp %g1, %g7
6448 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6449 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6450 index f73c224..662af10 100644
6451 --- a/arch/sparc/lib/ksyms.c
6452 +++ b/arch/sparc/lib/ksyms.c
6453 @@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
6454
6455 /* Atomic counter implementation. */
6456 EXPORT_SYMBOL(atomic_add);
6457 +EXPORT_SYMBOL(atomic_add_unchecked);
6458 EXPORT_SYMBOL(atomic_add_ret);
6459 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6460 EXPORT_SYMBOL(atomic_sub);
6461 +EXPORT_SYMBOL(atomic_sub_unchecked);
6462 EXPORT_SYMBOL(atomic_sub_ret);
6463 EXPORT_SYMBOL(atomic64_add);
6464 +EXPORT_SYMBOL(atomic64_add_unchecked);
6465 EXPORT_SYMBOL(atomic64_add_ret);
6466 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6467 EXPORT_SYMBOL(atomic64_sub);
6468 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6469 EXPORT_SYMBOL(atomic64_sub_ret);
6470
6471 /* Atomic bit operations. */
6472 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6473 index 301421c..e2535d1 100644
6474 --- a/arch/sparc/mm/Makefile
6475 +++ b/arch/sparc/mm/Makefile
6476 @@ -2,7 +2,7 @@
6477 #
6478
6479 asflags-y := -ansi
6480 -ccflags-y := -Werror
6481 +#ccflags-y := -Werror
6482
6483 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6484 obj-y += fault_$(BITS).o
6485 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6486 index 8023fd7..c8e89e9 100644
6487 --- a/arch/sparc/mm/fault_32.c
6488 +++ b/arch/sparc/mm/fault_32.c
6489 @@ -21,6 +21,9 @@
6490 #include <linux/perf_event.h>
6491 #include <linux/interrupt.h>
6492 #include <linux/kdebug.h>
6493 +#include <linux/slab.h>
6494 +#include <linux/pagemap.h>
6495 +#include <linux/compiler.h>
6496
6497 #include <asm/system.h>
6498 #include <asm/page.h>
6499 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6500 return safe_compute_effective_address(regs, insn);
6501 }
6502
6503 +#ifdef CONFIG_PAX_PAGEEXEC
6504 +#ifdef CONFIG_PAX_DLRESOLVE
6505 +static void pax_emuplt_close(struct vm_area_struct *vma)
6506 +{
6507 + vma->vm_mm->call_dl_resolve = 0UL;
6508 +}
6509 +
6510 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6511 +{
6512 + unsigned int *kaddr;
6513 +
6514 + vmf->page = alloc_page(GFP_HIGHUSER);
6515 + if (!vmf->page)
6516 + return VM_FAULT_OOM;
6517 +
6518 + kaddr = kmap(vmf->page);
6519 + memset(kaddr, 0, PAGE_SIZE);
6520 + kaddr[0] = 0x9DE3BFA8U; /* save */
6521 + flush_dcache_page(vmf->page);
6522 + kunmap(vmf->page);
6523 + return VM_FAULT_MAJOR;
6524 +}
6525 +
6526 +static const struct vm_operations_struct pax_vm_ops = {
6527 + .close = pax_emuplt_close,
6528 + .fault = pax_emuplt_fault
6529 +};
6530 +
6531 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6532 +{
6533 + int ret;
6534 +
6535 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6536 + vma->vm_mm = current->mm;
6537 + vma->vm_start = addr;
6538 + vma->vm_end = addr + PAGE_SIZE;
6539 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6540 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6541 + vma->vm_ops = &pax_vm_ops;
6542 +
6543 + ret = insert_vm_struct(current->mm, vma);
6544 + if (ret)
6545 + return ret;
6546 +
6547 + ++current->mm->total_vm;
6548 + return 0;
6549 +}
6550 +#endif
6551 +
6552 +/*
6553 + * PaX: decide what to do with offenders (regs->pc = fault address)
6554 + *
6555 + * returns 1 when task should be killed
6556 + * 2 when patched PLT trampoline was detected
6557 + * 3 when unpatched PLT trampoline was detected
6558 + */
6559 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6560 +{
6561 +
6562 +#ifdef CONFIG_PAX_EMUPLT
6563 + int err;
6564 +
6565 + do { /* PaX: patched PLT emulation #1 */
6566 + unsigned int sethi1, sethi2, jmpl;
6567 +
6568 + err = get_user(sethi1, (unsigned int *)regs->pc);
6569 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6570 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6571 +
6572 + if (err)
6573 + break;
6574 +
6575 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6576 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6577 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6578 + {
6579 + unsigned int addr;
6580 +
6581 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6582 + addr = regs->u_regs[UREG_G1];
6583 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6584 + regs->pc = addr;
6585 + regs->npc = addr+4;
6586 + return 2;
6587 + }
6588 + } while (0);
6589 +
6590 + { /* PaX: patched PLT emulation #2 */
6591 + unsigned int ba;
6592 +
6593 + err = get_user(ba, (unsigned int *)regs->pc);
6594 +
6595 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6596 + unsigned int addr;
6597 +
6598 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6599 + regs->pc = addr;
6600 + regs->npc = addr+4;
6601 + return 2;
6602 + }
6603 + }
6604 +
6605 + do { /* PaX: patched PLT emulation #3 */
6606 + unsigned int sethi, jmpl, nop;
6607 +
6608 + err = get_user(sethi, (unsigned int *)regs->pc);
6609 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6610 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6611 +
6612 + if (err)
6613 + break;
6614 +
6615 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6616 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6617 + nop == 0x01000000U)
6618 + {
6619 + unsigned int addr;
6620 +
6621 + addr = (sethi & 0x003FFFFFU) << 10;
6622 + regs->u_regs[UREG_G1] = addr;
6623 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6624 + regs->pc = addr;
6625 + regs->npc = addr+4;
6626 + return 2;
6627 + }
6628 + } while (0);
6629 +
6630 + do { /* PaX: unpatched PLT emulation step 1 */
6631 + unsigned int sethi, ba, nop;
6632 +
6633 + err = get_user(sethi, (unsigned int *)regs->pc);
6634 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6635 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6636 +
6637 + if (err)
6638 + break;
6639 +
6640 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6641 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6642 + nop == 0x01000000U)
6643 + {
6644 + unsigned int addr, save, call;
6645 +
6646 + if ((ba & 0xFFC00000U) == 0x30800000U)
6647 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6648 + else
6649 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6650 +
6651 + err = get_user(save, (unsigned int *)addr);
6652 + err |= get_user(call, (unsigned int *)(addr+4));
6653 + err |= get_user(nop, (unsigned int *)(addr+8));
6654 + if (err)
6655 + break;
6656 +
6657 +#ifdef CONFIG_PAX_DLRESOLVE
6658 + if (save == 0x9DE3BFA8U &&
6659 + (call & 0xC0000000U) == 0x40000000U &&
6660 + nop == 0x01000000U)
6661 + {
6662 + struct vm_area_struct *vma;
6663 + unsigned long call_dl_resolve;
6664 +
6665 + down_read(&current->mm->mmap_sem);
6666 + call_dl_resolve = current->mm->call_dl_resolve;
6667 + up_read(&current->mm->mmap_sem);
6668 + if (likely(call_dl_resolve))
6669 + goto emulate;
6670 +
6671 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6672 +
6673 + down_write(&current->mm->mmap_sem);
6674 + if (current->mm->call_dl_resolve) {
6675 + call_dl_resolve = current->mm->call_dl_resolve;
6676 + up_write(&current->mm->mmap_sem);
6677 + if (vma)
6678 + kmem_cache_free(vm_area_cachep, vma);
6679 + goto emulate;
6680 + }
6681 +
6682 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6683 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6684 + up_write(&current->mm->mmap_sem);
6685 + if (vma)
6686 + kmem_cache_free(vm_area_cachep, vma);
6687 + return 1;
6688 + }
6689 +
6690 + if (pax_insert_vma(vma, call_dl_resolve)) {
6691 + up_write(&current->mm->mmap_sem);
6692 + kmem_cache_free(vm_area_cachep, vma);
6693 + return 1;
6694 + }
6695 +
6696 + current->mm->call_dl_resolve = call_dl_resolve;
6697 + up_write(&current->mm->mmap_sem);
6698 +
6699 +emulate:
6700 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6701 + regs->pc = call_dl_resolve;
6702 + regs->npc = addr+4;
6703 + return 3;
6704 + }
6705 +#endif
6706 +
6707 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6708 + if ((save & 0xFFC00000U) == 0x05000000U &&
6709 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6710 + nop == 0x01000000U)
6711 + {
6712 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6713 + regs->u_regs[UREG_G2] = addr + 4;
6714 + addr = (save & 0x003FFFFFU) << 10;
6715 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6716 + regs->pc = addr;
6717 + regs->npc = addr+4;
6718 + return 3;
6719 + }
6720 + }
6721 + } while (0);
6722 +
6723 + do { /* PaX: unpatched PLT emulation step 2 */
6724 + unsigned int save, call, nop;
6725 +
6726 + err = get_user(save, (unsigned int *)(regs->pc-4));
6727 + err |= get_user(call, (unsigned int *)regs->pc);
6728 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6729 + if (err)
6730 + break;
6731 +
6732 + if (save == 0x9DE3BFA8U &&
6733 + (call & 0xC0000000U) == 0x40000000U &&
6734 + nop == 0x01000000U)
6735 + {
6736 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6737 +
6738 + regs->u_regs[UREG_RETPC] = regs->pc;
6739 + regs->pc = dl_resolve;
6740 + regs->npc = dl_resolve+4;
6741 + return 3;
6742 + }
6743 + } while (0);
6744 +#endif
6745 +
6746 + return 1;
6747 +}
6748 +
6749 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6750 +{
6751 + unsigned long i;
6752 +
6753 + printk(KERN_ERR "PAX: bytes at PC: ");
6754 + for (i = 0; i < 8; i++) {
6755 + unsigned int c;
6756 + if (get_user(c, (unsigned int *)pc+i))
6757 + printk(KERN_CONT "???????? ");
6758 + else
6759 + printk(KERN_CONT "%08x ", c);
6760 + }
6761 + printk("\n");
6762 +}
6763 +#endif
6764 +
6765 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6766 int text_fault)
6767 {
6768 @@ -280,6 +545,24 @@ good_area:
6769 if(!(vma->vm_flags & VM_WRITE))
6770 goto bad_area;
6771 } else {
6772 +
6773 +#ifdef CONFIG_PAX_PAGEEXEC
6774 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6775 + up_read(&mm->mmap_sem);
6776 + switch (pax_handle_fetch_fault(regs)) {
6777 +
6778 +#ifdef CONFIG_PAX_EMUPLT
6779 + case 2:
6780 + case 3:
6781 + return;
6782 +#endif
6783 +
6784 + }
6785 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6786 + do_group_exit(SIGKILL);
6787 + }
6788 +#endif
6789 +
6790 /* Allow reads even for write-only mappings */
6791 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6792 goto bad_area;
6793 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6794 index 504c062..6fcb9c6 100644
6795 --- a/arch/sparc/mm/fault_64.c
6796 +++ b/arch/sparc/mm/fault_64.c
6797 @@ -21,6 +21,9 @@
6798 #include <linux/kprobes.h>
6799 #include <linux/kdebug.h>
6800 #include <linux/percpu.h>
6801 +#include <linux/slab.h>
6802 +#include <linux/pagemap.h>
6803 +#include <linux/compiler.h>
6804
6805 #include <asm/page.h>
6806 #include <asm/pgtable.h>
6807 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6808 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6809 regs->tpc);
6810 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6811 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6812 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6813 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6814 dump_stack();
6815 unhandled_fault(regs->tpc, current, regs);
6816 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6817 show_regs(regs);
6818 }
6819
6820 +#ifdef CONFIG_PAX_PAGEEXEC
6821 +#ifdef CONFIG_PAX_DLRESOLVE
6822 +static void pax_emuplt_close(struct vm_area_struct *vma)
6823 +{
6824 + vma->vm_mm->call_dl_resolve = 0UL;
6825 +}
6826 +
6827 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6828 +{
6829 + unsigned int *kaddr;
6830 +
6831 + vmf->page = alloc_page(GFP_HIGHUSER);
6832 + if (!vmf->page)
6833 + return VM_FAULT_OOM;
6834 +
6835 + kaddr = kmap(vmf->page);
6836 + memset(kaddr, 0, PAGE_SIZE);
6837 + kaddr[0] = 0x9DE3BFA8U; /* save */
6838 + flush_dcache_page(vmf->page);
6839 + kunmap(vmf->page);
6840 + return VM_FAULT_MAJOR;
6841 +}
6842 +
6843 +static const struct vm_operations_struct pax_vm_ops = {
6844 + .close = pax_emuplt_close,
6845 + .fault = pax_emuplt_fault
6846 +};
6847 +
6848 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6849 +{
6850 + int ret;
6851 +
6852 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6853 + vma->vm_mm = current->mm;
6854 + vma->vm_start = addr;
6855 + vma->vm_end = addr + PAGE_SIZE;
6856 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6857 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6858 + vma->vm_ops = &pax_vm_ops;
6859 +
6860 + ret = insert_vm_struct(current->mm, vma);
6861 + if (ret)
6862 + return ret;
6863 +
6864 + ++current->mm->total_vm;
6865 + return 0;
6866 +}
6867 +#endif
6868 +
6869 +/*
6870 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6871 + *
6872 + * returns 1 when task should be killed
6873 + * 2 when patched PLT trampoline was detected
6874 + * 3 when unpatched PLT trampoline was detected
6875 + */
6876 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6877 +{
6878 +
6879 +#ifdef CONFIG_PAX_EMUPLT
6880 + int err;
6881 +
6882 + do { /* PaX: patched PLT emulation #1 */
6883 + unsigned int sethi1, sethi2, jmpl;
6884 +
6885 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6886 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6887 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6888 +
6889 + if (err)
6890 + break;
6891 +
6892 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6893 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6894 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6895 + {
6896 + unsigned long addr;
6897 +
6898 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6899 + addr = regs->u_regs[UREG_G1];
6900 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6901 +
6902 + if (test_thread_flag(TIF_32BIT))
6903 + addr &= 0xFFFFFFFFUL;
6904 +
6905 + regs->tpc = addr;
6906 + regs->tnpc = addr+4;
6907 + return 2;
6908 + }
6909 + } while (0);
6910 +
6911 + { /* PaX: patched PLT emulation #2 */
6912 + unsigned int ba;
6913 +
6914 + err = get_user(ba, (unsigned int *)regs->tpc);
6915 +
6916 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6917 + unsigned long addr;
6918 +
6919 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6920 +
6921 + if (test_thread_flag(TIF_32BIT))
6922 + addr &= 0xFFFFFFFFUL;
6923 +
6924 + regs->tpc = addr;
6925 + regs->tnpc = addr+4;
6926 + return 2;
6927 + }
6928 + }
6929 +
6930 + do { /* PaX: patched PLT emulation #3 */
6931 + unsigned int sethi, jmpl, nop;
6932 +
6933 + err = get_user(sethi, (unsigned int *)regs->tpc);
6934 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6935 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6936 +
6937 + if (err)
6938 + break;
6939 +
6940 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6941 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6942 + nop == 0x01000000U)
6943 + {
6944 + unsigned long addr;
6945 +
6946 + addr = (sethi & 0x003FFFFFU) << 10;
6947 + regs->u_regs[UREG_G1] = addr;
6948 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6949 +
6950 + if (test_thread_flag(TIF_32BIT))
6951 + addr &= 0xFFFFFFFFUL;
6952 +
6953 + regs->tpc = addr;
6954 + regs->tnpc = addr+4;
6955 + return 2;
6956 + }
6957 + } while (0);
6958 +
6959 + do { /* PaX: patched PLT emulation #4 */
6960 + unsigned int sethi, mov1, call, mov2;
6961 +
6962 + err = get_user(sethi, (unsigned int *)regs->tpc);
6963 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6964 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6965 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6966 +
6967 + if (err)
6968 + break;
6969 +
6970 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6971 + mov1 == 0x8210000FU &&
6972 + (call & 0xC0000000U) == 0x40000000U &&
6973 + mov2 == 0x9E100001U)
6974 + {
6975 + unsigned long addr;
6976 +
6977 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6978 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6979 +
6980 + if (test_thread_flag(TIF_32BIT))
6981 + addr &= 0xFFFFFFFFUL;
6982 +
6983 + regs->tpc = addr;
6984 + regs->tnpc = addr+4;
6985 + return 2;
6986 + }
6987 + } while (0);
6988 +
6989 + do { /* PaX: patched PLT emulation #5 */
6990 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6991 +
6992 + err = get_user(sethi, (unsigned int *)regs->tpc);
6993 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6994 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6995 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6996 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6997 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6998 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6999 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7000 +
7001 + if (err)
7002 + break;
7003 +
7004 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7005 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7006 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7007 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7008 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7009 + sllx == 0x83287020U &&
7010 + jmpl == 0x81C04005U &&
7011 + nop == 0x01000000U)
7012 + {
7013 + unsigned long addr;
7014 +
7015 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7016 + regs->u_regs[UREG_G1] <<= 32;
7017 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7018 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7019 + regs->tpc = addr;
7020 + regs->tnpc = addr+4;
7021 + return 2;
7022 + }
7023 + } while (0);
7024 +
7025 + do { /* PaX: patched PLT emulation #6 */
7026 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7027 +
7028 + err = get_user(sethi, (unsigned int *)regs->tpc);
7029 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7030 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7031 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7032 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7033 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7034 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7035 +
7036 + if (err)
7037 + break;
7038 +
7039 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7040 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7041 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7042 + sllx == 0x83287020U &&
7043 + (or & 0xFFFFE000U) == 0x8A116000U &&
7044 + jmpl == 0x81C04005U &&
7045 + nop == 0x01000000U)
7046 + {
7047 + unsigned long addr;
7048 +
7049 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7050 + regs->u_regs[UREG_G1] <<= 32;
7051 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7052 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7053 + regs->tpc = addr;
7054 + regs->tnpc = addr+4;
7055 + return 2;
7056 + }
7057 + } while (0);
7058 +
7059 + do { /* PaX: unpatched PLT emulation step 1 */
7060 + unsigned int sethi, ba, nop;
7061 +
7062 + err = get_user(sethi, (unsigned int *)regs->tpc);
7063 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7064 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7065 +
7066 + if (err)
7067 + break;
7068 +
7069 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7070 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7071 + nop == 0x01000000U)
7072 + {
7073 + unsigned long addr;
7074 + unsigned int save, call;
7075 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7076 +
7077 + if ((ba & 0xFFC00000U) == 0x30800000U)
7078 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7079 + else
7080 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7081 +
7082 + if (test_thread_flag(TIF_32BIT))
7083 + addr &= 0xFFFFFFFFUL;
7084 +
7085 + err = get_user(save, (unsigned int *)addr);
7086 + err |= get_user(call, (unsigned int *)(addr+4));
7087 + err |= get_user(nop, (unsigned int *)(addr+8));
7088 + if (err)
7089 + break;
7090 +
7091 +#ifdef CONFIG_PAX_DLRESOLVE
7092 + if (save == 0x9DE3BFA8U &&
7093 + (call & 0xC0000000U) == 0x40000000U &&
7094 + nop == 0x01000000U)
7095 + {
7096 + struct vm_area_struct *vma;
7097 + unsigned long call_dl_resolve;
7098 +
7099 + down_read(&current->mm->mmap_sem);
7100 + call_dl_resolve = current->mm->call_dl_resolve;
7101 + up_read(&current->mm->mmap_sem);
7102 + if (likely(call_dl_resolve))
7103 + goto emulate;
7104 +
7105 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7106 +
7107 + down_write(&current->mm->mmap_sem);
7108 + if (current->mm->call_dl_resolve) {
7109 + call_dl_resolve = current->mm->call_dl_resolve;
7110 + up_write(&current->mm->mmap_sem);
7111 + if (vma)
7112 + kmem_cache_free(vm_area_cachep, vma);
7113 + goto emulate;
7114 + }
7115 +
7116 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7117 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7118 + up_write(&current->mm->mmap_sem);
7119 + if (vma)
7120 + kmem_cache_free(vm_area_cachep, vma);
7121 + return 1;
7122 + }
7123 +
7124 + if (pax_insert_vma(vma, call_dl_resolve)) {
7125 + up_write(&current->mm->mmap_sem);
7126 + kmem_cache_free(vm_area_cachep, vma);
7127 + return 1;
7128 + }
7129 +
7130 + current->mm->call_dl_resolve = call_dl_resolve;
7131 + up_write(&current->mm->mmap_sem);
7132 +
7133 +emulate:
7134 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7135 + regs->tpc = call_dl_resolve;
7136 + regs->tnpc = addr+4;
7137 + return 3;
7138 + }
7139 +#endif
7140 +
7141 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7142 + if ((save & 0xFFC00000U) == 0x05000000U &&
7143 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7144 + nop == 0x01000000U)
7145 + {
7146 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7147 + regs->u_regs[UREG_G2] = addr + 4;
7148 + addr = (save & 0x003FFFFFU) << 10;
7149 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7150 +
7151 + if (test_thread_flag(TIF_32BIT))
7152 + addr &= 0xFFFFFFFFUL;
7153 +
7154 + regs->tpc = addr;
7155 + regs->tnpc = addr+4;
7156 + return 3;
7157 + }
7158 +
7159 + /* PaX: 64-bit PLT stub */
7160 + err = get_user(sethi1, (unsigned int *)addr);
7161 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7162 + err |= get_user(or1, (unsigned int *)(addr+8));
7163 + err |= get_user(or2, (unsigned int *)(addr+12));
7164 + err |= get_user(sllx, (unsigned int *)(addr+16));
7165 + err |= get_user(add, (unsigned int *)(addr+20));
7166 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7167 + err |= get_user(nop, (unsigned int *)(addr+28));
7168 + if (err)
7169 + break;
7170 +
7171 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7172 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7173 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7174 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7175 + sllx == 0x89293020U &&
7176 + add == 0x8A010005U &&
7177 + jmpl == 0x89C14000U &&
7178 + nop == 0x01000000U)
7179 + {
7180 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7181 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7182 + regs->u_regs[UREG_G4] <<= 32;
7183 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7184 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7185 + regs->u_regs[UREG_G4] = addr + 24;
7186 + addr = regs->u_regs[UREG_G5];
7187 + regs->tpc = addr;
7188 + regs->tnpc = addr+4;
7189 + return 3;
7190 + }
7191 + }
7192 + } while (0);
7193 +
7194 +#ifdef CONFIG_PAX_DLRESOLVE
7195 + do { /* PaX: unpatched PLT emulation step 2 */
7196 + unsigned int save, call, nop;
7197 +
7198 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7199 + err |= get_user(call, (unsigned int *)regs->tpc);
7200 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7201 + if (err)
7202 + break;
7203 +
7204 + if (save == 0x9DE3BFA8U &&
7205 + (call & 0xC0000000U) == 0x40000000U &&
7206 + nop == 0x01000000U)
7207 + {
7208 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7209 +
7210 + if (test_thread_flag(TIF_32BIT))
7211 + dl_resolve &= 0xFFFFFFFFUL;
7212 +
7213 + regs->u_regs[UREG_RETPC] = regs->tpc;
7214 + regs->tpc = dl_resolve;
7215 + regs->tnpc = dl_resolve+4;
7216 + return 3;
7217 + }
7218 + } while (0);
7219 +#endif
7220 +
7221 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7222 + unsigned int sethi, ba, nop;
7223 +
7224 + err = get_user(sethi, (unsigned int *)regs->tpc);
7225 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7226 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7227 +
7228 + if (err)
7229 + break;
7230 +
7231 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7232 + (ba & 0xFFF00000U) == 0x30600000U &&
7233 + nop == 0x01000000U)
7234 + {
7235 + unsigned long addr;
7236 +
7237 + addr = (sethi & 0x003FFFFFU) << 10;
7238 + regs->u_regs[UREG_G1] = addr;
7239 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7240 +
7241 + if (test_thread_flag(TIF_32BIT))
7242 + addr &= 0xFFFFFFFFUL;
7243 +
7244 + regs->tpc = addr;
7245 + regs->tnpc = addr+4;
7246 + return 2;
7247 + }
7248 + } while (0);
7249 +
7250 +#endif
7251 +
7252 + return 1;
7253 +}
7254 +
7255 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7256 +{
7257 + unsigned long i;
7258 +
7259 + printk(KERN_ERR "PAX: bytes at PC: ");
7260 + for (i = 0; i < 8; i++) {
7261 + unsigned int c;
7262 + if (get_user(c, (unsigned int *)pc+i))
7263 + printk(KERN_CONT "???????? ");
7264 + else
7265 + printk(KERN_CONT "%08x ", c);
7266 + }
7267 + printk("\n");
7268 +}
7269 +#endif
7270 +
7271 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7272 {
7273 struct mm_struct *mm = current->mm;
7274 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7275 if (!vma)
7276 goto bad_area;
7277
7278 +#ifdef CONFIG_PAX_PAGEEXEC
7279 + /* PaX: detect ITLB misses on non-exec pages */
7280 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7281 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7282 + {
7283 + if (address != regs->tpc)
7284 + goto good_area;
7285 +
7286 + up_read(&mm->mmap_sem);
7287 + switch (pax_handle_fetch_fault(regs)) {
7288 +
7289 +#ifdef CONFIG_PAX_EMUPLT
7290 + case 2:
7291 + case 3:
7292 + return;
7293 +#endif
7294 +
7295 + }
7296 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7297 + do_group_exit(SIGKILL);
7298 + }
7299 +#endif
7300 +
7301 /* Pure DTLB misses do not tell us whether the fault causing
7302 * load/store/atomic was a write or not, it only says that there
7303 * was no match. So in such a case we (carefully) read the
7304 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7305 index 07e1453..0a7d9e9 100644
7306 --- a/arch/sparc/mm/hugetlbpage.c
7307 +++ b/arch/sparc/mm/hugetlbpage.c
7308 @@ -67,7 +67,7 @@ full_search:
7309 }
7310 return -ENOMEM;
7311 }
7312 - if (likely(!vma || addr + len <= vma->vm_start)) {
7313 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7314 /*
7315 * Remember the place where we stopped the search:
7316 */
7317 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7318 /* make sure it can fit in the remaining address space */
7319 if (likely(addr > len)) {
7320 vma = find_vma(mm, addr-len);
7321 - if (!vma || addr <= vma->vm_start) {
7322 + if (check_heap_stack_gap(vma, addr - len, len)) {
7323 /* remember the address as a hint for next time */
7324 return (mm->free_area_cache = addr-len);
7325 }
7326 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7327 if (unlikely(mm->mmap_base < len))
7328 goto bottomup;
7329
7330 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7331 + addr = mm->mmap_base - len;
7332
7333 do {
7334 + addr &= HPAGE_MASK;
7335 /*
7336 * Lookup failure means no vma is above this address,
7337 * else if new region fits below vma->vm_start,
7338 * return with success:
7339 */
7340 vma = find_vma(mm, addr);
7341 - if (likely(!vma || addr+len <= vma->vm_start)) {
7342 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7343 /* remember the address as a hint for next time */
7344 return (mm->free_area_cache = addr);
7345 }
7346 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7347 mm->cached_hole_size = vma->vm_start - addr;
7348
7349 /* try just below the current vma->vm_start */
7350 - addr = (vma->vm_start-len) & HPAGE_MASK;
7351 - } while (likely(len < vma->vm_start));
7352 + addr = skip_heap_stack_gap(vma, len);
7353 + } while (!IS_ERR_VALUE(addr));
7354
7355 bottomup:
7356 /*
7357 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7358 if (addr) {
7359 addr = ALIGN(addr, HPAGE_SIZE);
7360 vma = find_vma(mm, addr);
7361 - if (task_size - len >= addr &&
7362 - (!vma || addr + len <= vma->vm_start))
7363 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7364 return addr;
7365 }
7366 if (mm->get_unmapped_area == arch_get_unmapped_area)
7367 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
7368 index 7b00de6..78239f4 100644
7369 --- a/arch/sparc/mm/init_32.c
7370 +++ b/arch/sparc/mm/init_32.c
7371 @@ -316,6 +316,9 @@ extern void device_scan(void);
7372 pgprot_t PAGE_SHARED __read_mostly;
7373 EXPORT_SYMBOL(PAGE_SHARED);
7374
7375 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7376 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7377 +
7378 void __init paging_init(void)
7379 {
7380 switch(sparc_cpu_model) {
7381 @@ -344,17 +347,17 @@ void __init paging_init(void)
7382
7383 /* Initialize the protection map with non-constant, MMU dependent values. */
7384 protection_map[0] = PAGE_NONE;
7385 - protection_map[1] = PAGE_READONLY;
7386 - protection_map[2] = PAGE_COPY;
7387 - protection_map[3] = PAGE_COPY;
7388 + protection_map[1] = PAGE_READONLY_NOEXEC;
7389 + protection_map[2] = PAGE_COPY_NOEXEC;
7390 + protection_map[3] = PAGE_COPY_NOEXEC;
7391 protection_map[4] = PAGE_READONLY;
7392 protection_map[5] = PAGE_READONLY;
7393 protection_map[6] = PAGE_COPY;
7394 protection_map[7] = PAGE_COPY;
7395 protection_map[8] = PAGE_NONE;
7396 - protection_map[9] = PAGE_READONLY;
7397 - protection_map[10] = PAGE_SHARED;
7398 - protection_map[11] = PAGE_SHARED;
7399 + protection_map[9] = PAGE_READONLY_NOEXEC;
7400 + protection_map[10] = PAGE_SHARED_NOEXEC;
7401 + protection_map[11] = PAGE_SHARED_NOEXEC;
7402 protection_map[12] = PAGE_READONLY;
7403 protection_map[13] = PAGE_READONLY;
7404 protection_map[14] = PAGE_SHARED;
7405 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
7406 index cbef74e..c38fead 100644
7407 --- a/arch/sparc/mm/srmmu.c
7408 +++ b/arch/sparc/mm/srmmu.c
7409 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7410 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7411 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7412 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7413 +
7414 +#ifdef CONFIG_PAX_PAGEEXEC
7415 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7416 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7417 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7418 +#endif
7419 +
7420 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7421 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7422
7423 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7424 index 27fe667..36d474c 100644
7425 --- a/arch/tile/include/asm/atomic_64.h
7426 +++ b/arch/tile/include/asm/atomic_64.h
7427 @@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7428
7429 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7430
7431 +#define atomic64_read_unchecked(v) atomic64_read(v)
7432 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7433 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7434 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7435 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7436 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7437 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7438 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7439 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7440 +
7441 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7442 #define smp_mb__before_atomic_dec() smp_mb()
7443 #define smp_mb__after_atomic_dec() smp_mb()
7444 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7445 index 392e533..536b092 100644
7446 --- a/arch/tile/include/asm/cache.h
7447 +++ b/arch/tile/include/asm/cache.h
7448 @@ -15,11 +15,12 @@
7449 #ifndef _ASM_TILE_CACHE_H
7450 #define _ASM_TILE_CACHE_H
7451
7452 +#include <linux/const.h>
7453 #include <arch/chip.h>
7454
7455 /* bytes per L1 data cache line */
7456 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7457 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7458 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7459
7460 /* bytes per L2 cache line */
7461 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7462 diff --git a/arch/um/Makefile b/arch/um/Makefile
7463 index 28688e6..4c0aa1c 100644
7464 --- a/arch/um/Makefile
7465 +++ b/arch/um/Makefile
7466 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7467 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7468 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7469
7470 +ifdef CONSTIFY_PLUGIN
7471 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7472 +endif
7473 +
7474 #This will adjust *FLAGS accordingly to the platform.
7475 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7476
7477 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7478 index 19e1bdd..3665b77 100644
7479 --- a/arch/um/include/asm/cache.h
7480 +++ b/arch/um/include/asm/cache.h
7481 @@ -1,6 +1,7 @@
7482 #ifndef __UM_CACHE_H
7483 #define __UM_CACHE_H
7484
7485 +#include <linux/const.h>
7486
7487 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7488 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7489 @@ -12,6 +13,6 @@
7490 # define L1_CACHE_SHIFT 5
7491 #endif
7492
7493 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7494 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7495
7496 #endif
7497 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7498 index 6c03acd..a5e0215 100644
7499 --- a/arch/um/include/asm/kmap_types.h
7500 +++ b/arch/um/include/asm/kmap_types.h
7501 @@ -23,6 +23,7 @@ enum km_type {
7502 KM_IRQ1,
7503 KM_SOFTIRQ0,
7504 KM_SOFTIRQ1,
7505 + KM_CLEARPAGE,
7506 KM_TYPE_NR
7507 };
7508
7509 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7510 index 7cfc3ce..cbd1a58 100644
7511 --- a/arch/um/include/asm/page.h
7512 +++ b/arch/um/include/asm/page.h
7513 @@ -14,6 +14,9 @@
7514 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7515 #define PAGE_MASK (~(PAGE_SIZE-1))
7516
7517 +#define ktla_ktva(addr) (addr)
7518 +#define ktva_ktla(addr) (addr)
7519 +
7520 #ifndef __ASSEMBLY__
7521
7522 struct page;
7523 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7524 index 0032f92..cd151e0 100644
7525 --- a/arch/um/include/asm/pgtable-3level.h
7526 +++ b/arch/um/include/asm/pgtable-3level.h
7527 @@ -58,6 +58,7 @@
7528 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7529 #define pud_populate(mm, pud, pmd) \
7530 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7531 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7532
7533 #ifdef CONFIG_64BIT
7534 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7535 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7536 index 69f2490..2634831 100644
7537 --- a/arch/um/kernel/process.c
7538 +++ b/arch/um/kernel/process.c
7539 @@ -408,22 +408,6 @@ int singlestepping(void * t)
7540 return 2;
7541 }
7542
7543 -/*
7544 - * Only x86 and x86_64 have an arch_align_stack().
7545 - * All other arches have "#define arch_align_stack(x) (x)"
7546 - * in their asm/system.h
7547 - * As this is included in UML from asm-um/system-generic.h,
7548 - * we can use it to behave as the subarch does.
7549 - */
7550 -#ifndef arch_align_stack
7551 -unsigned long arch_align_stack(unsigned long sp)
7552 -{
7553 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7554 - sp -= get_random_int() % 8192;
7555 - return sp & ~0xf;
7556 -}
7557 -#endif
7558 -
7559 unsigned long get_wchan(struct task_struct *p)
7560 {
7561 unsigned long stack_page, sp, ip;
7562 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7563 index ad8f795..2c7eec6 100644
7564 --- a/arch/unicore32/include/asm/cache.h
7565 +++ b/arch/unicore32/include/asm/cache.h
7566 @@ -12,8 +12,10 @@
7567 #ifndef __UNICORE_CACHE_H__
7568 #define __UNICORE_CACHE_H__
7569
7570 -#define L1_CACHE_SHIFT (5)
7571 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7572 +#include <linux/const.h>
7573 +
7574 +#define L1_CACHE_SHIFT 5
7575 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7576
7577 /*
7578 * Memory returned by kmalloc() may be used for DMA, so we must make
7579 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7580 index 5bed94e..fbcf200 100644
7581 --- a/arch/x86/Kconfig
7582 +++ b/arch/x86/Kconfig
7583 @@ -226,7 +226,7 @@ config X86_HT
7584
7585 config X86_32_LAZY_GS
7586 def_bool y
7587 - depends on X86_32 && !CC_STACKPROTECTOR
7588 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7589
7590 config ARCH_HWEIGHT_CFLAGS
7591 string
7592 @@ -1058,7 +1058,7 @@ choice
7593
7594 config NOHIGHMEM
7595 bool "off"
7596 - depends on !X86_NUMAQ
7597 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7598 ---help---
7599 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7600 However, the address space of 32-bit x86 processors is only 4
7601 @@ -1095,7 +1095,7 @@ config NOHIGHMEM
7602
7603 config HIGHMEM4G
7604 bool "4GB"
7605 - depends on !X86_NUMAQ
7606 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7607 ---help---
7608 Select this if you have a 32-bit processor and between 1 and 4
7609 gigabytes of physical RAM.
7610 @@ -1149,7 +1149,7 @@ config PAGE_OFFSET
7611 hex
7612 default 0xB0000000 if VMSPLIT_3G_OPT
7613 default 0x80000000 if VMSPLIT_2G
7614 - default 0x78000000 if VMSPLIT_2G_OPT
7615 + default 0x70000000 if VMSPLIT_2G_OPT
7616 default 0x40000000 if VMSPLIT_1G
7617 default 0xC0000000
7618 depends on X86_32
7619 @@ -1539,6 +1539,7 @@ config SECCOMP
7620
7621 config CC_STACKPROTECTOR
7622 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7623 + depends on X86_64 || !PAX_MEMORY_UDEREF
7624 ---help---
7625 This option turns on the -fstack-protector GCC feature. This
7626 feature puts, at the beginning of functions, a canary value on
7627 @@ -1596,6 +1597,7 @@ config KEXEC_JUMP
7628 config PHYSICAL_START
7629 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7630 default "0x1000000"
7631 + range 0x400000 0x40000000
7632 ---help---
7633 This gives the physical address where the kernel is loaded.
7634
7635 @@ -1659,6 +1661,7 @@ config X86_NEED_RELOCS
7636 config PHYSICAL_ALIGN
7637 hex "Alignment value to which kernel should be aligned" if X86_32
7638 default "0x1000000"
7639 + range 0x400000 0x1000000 if PAX_KERNEXEC
7640 range 0x2000 0x1000000
7641 ---help---
7642 This value puts the alignment restrictions on physical address
7643 @@ -1690,9 +1693,10 @@ config HOTPLUG_CPU
7644 Say N if you want to disable CPU hotplug.
7645
7646 config COMPAT_VDSO
7647 - def_bool y
7648 + def_bool n
7649 prompt "Compat VDSO support"
7650 depends on X86_32 || IA32_EMULATION
7651 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7652 ---help---
7653 Map the 32-bit VDSO to the predictable old-style address too.
7654
7655 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7656 index 3c57033..22d44aa 100644
7657 --- a/arch/x86/Kconfig.cpu
7658 +++ b/arch/x86/Kconfig.cpu
7659 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
7660
7661 config X86_F00F_BUG
7662 def_bool y
7663 - depends on M586MMX || M586TSC || M586 || M486 || M386
7664 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7665
7666 config X86_INVD_BUG
7667 def_bool y
7668 @@ -359,7 +359,7 @@ config X86_POPAD_OK
7669
7670 config X86_ALIGNMENT_16
7671 def_bool y
7672 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7673 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7674
7675 config X86_INTEL_USERCOPY
7676 def_bool y
7677 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
7678 # generates cmov.
7679 config X86_CMOV
7680 def_bool y
7681 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7682 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7683
7684 config X86_MINIMUM_CPU_FAMILY
7685 int
7686 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7687 index e46c214..7c72b55 100644
7688 --- a/arch/x86/Kconfig.debug
7689 +++ b/arch/x86/Kconfig.debug
7690 @@ -84,7 +84,7 @@ config X86_PTDUMP
7691 config DEBUG_RODATA
7692 bool "Write protect kernel read-only data structures"
7693 default y
7694 - depends on DEBUG_KERNEL
7695 + depends on DEBUG_KERNEL && BROKEN
7696 ---help---
7697 Mark the kernel read-only data as write-protected in the pagetables,
7698 in order to catch accidental (and incorrect) writes to such const
7699 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7700
7701 config DEBUG_SET_MODULE_RONX
7702 bool "Set loadable kernel module data as NX and text as RO"
7703 - depends on MODULES
7704 + depends on MODULES && BROKEN
7705 ---help---
7706 This option helps catch unintended modifications to loadable
7707 kernel module's text and read-only data. It also prevents execution
7708 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7709 index 209ba12..15140db 100644
7710 --- a/arch/x86/Makefile
7711 +++ b/arch/x86/Makefile
7712 @@ -46,6 +46,7 @@ else
7713 UTS_MACHINE := x86_64
7714 CHECKFLAGS += -D__x86_64__ -m64
7715
7716 + biarch := $(call cc-option,-m64)
7717 KBUILD_AFLAGS += -m64
7718 KBUILD_CFLAGS += -m64
7719
7720 @@ -201,3 +202,12 @@ define archhelp
7721 echo ' FDARGS="..." arguments for the booted kernel'
7722 echo ' FDINITRD=file initrd for the booted kernel'
7723 endef
7724 +
7725 +define OLD_LD
7726 +
7727 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7728 +*** Please upgrade your binutils to 2.18 or newer
7729 +endef
7730 +
7731 +archprepare:
7732 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7733 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7734 index 5a747dd..ff7b12c 100644
7735 --- a/arch/x86/boot/Makefile
7736 +++ b/arch/x86/boot/Makefile
7737 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7738 $(call cc-option, -fno-stack-protector) \
7739 $(call cc-option, -mpreferred-stack-boundary=2)
7740 KBUILD_CFLAGS += $(call cc-option, -m32)
7741 +ifdef CONSTIFY_PLUGIN
7742 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7743 +endif
7744 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7745 GCOV_PROFILE := n
7746
7747 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7748 index 878e4b9..20537ab 100644
7749 --- a/arch/x86/boot/bitops.h
7750 +++ b/arch/x86/boot/bitops.h
7751 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7752 u8 v;
7753 const u32 *p = (const u32 *)addr;
7754
7755 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7756 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7757 return v;
7758 }
7759
7760 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7761
7762 static inline void set_bit(int nr, void *addr)
7763 {
7764 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7765 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7766 }
7767
7768 #endif /* BOOT_BITOPS_H */
7769 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7770 index c7093bd..d4247ffe0 100644
7771 --- a/arch/x86/boot/boot.h
7772 +++ b/arch/x86/boot/boot.h
7773 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7774 static inline u16 ds(void)
7775 {
7776 u16 seg;
7777 - asm("movw %%ds,%0" : "=rm" (seg));
7778 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7779 return seg;
7780 }
7781
7782 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7783 static inline int memcmp(const void *s1, const void *s2, size_t len)
7784 {
7785 u8 diff;
7786 - asm("repe; cmpsb; setnz %0"
7787 + asm volatile("repe; cmpsb; setnz %0"
7788 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7789 return diff;
7790 }
7791 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7792 index fd55a2f..217b501 100644
7793 --- a/arch/x86/boot/compressed/Makefile
7794 +++ b/arch/x86/boot/compressed/Makefile
7795 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7796 KBUILD_CFLAGS += $(cflags-y)
7797 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7798 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7799 +ifdef CONSTIFY_PLUGIN
7800 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7801 +endif
7802
7803 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7804 GCOV_PROFILE := n
7805 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7806 index c85e3ac..6f5aa80 100644
7807 --- a/arch/x86/boot/compressed/head_32.S
7808 +++ b/arch/x86/boot/compressed/head_32.S
7809 @@ -106,7 +106,7 @@ preferred_addr:
7810 notl %eax
7811 andl %eax, %ebx
7812 #else
7813 - movl $LOAD_PHYSICAL_ADDR, %ebx
7814 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7815 #endif
7816
7817 /* Target address to relocate to for decompression */
7818 @@ -192,7 +192,7 @@ relocated:
7819 * and where it was actually loaded.
7820 */
7821 movl %ebp, %ebx
7822 - subl $LOAD_PHYSICAL_ADDR, %ebx
7823 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7824 jz 2f /* Nothing to be done if loaded at compiled addr. */
7825 /*
7826 * Process relocations.
7827 @@ -200,8 +200,7 @@ relocated:
7828
7829 1: subl $4, %edi
7830 movl (%edi), %ecx
7831 - testl %ecx, %ecx
7832 - jz 2f
7833 + jecxz 2f
7834 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7835 jmp 1b
7836 2:
7837 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7838 index 87e03a1..0d94c76 100644
7839 --- a/arch/x86/boot/compressed/head_64.S
7840 +++ b/arch/x86/boot/compressed/head_64.S
7841 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7842 notl %eax
7843 andl %eax, %ebx
7844 #else
7845 - movl $LOAD_PHYSICAL_ADDR, %ebx
7846 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7847 #endif
7848
7849 /* Target address to relocate to for decompression */
7850 @@ -263,7 +263,7 @@ preferred_addr:
7851 notq %rax
7852 andq %rax, %rbp
7853 #else
7854 - movq $LOAD_PHYSICAL_ADDR, %rbp
7855 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7856 #endif
7857
7858 /* Target address to relocate to for decompression */
7859 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7860 index 7116dcb..d9ae1d7 100644
7861 --- a/arch/x86/boot/compressed/misc.c
7862 +++ b/arch/x86/boot/compressed/misc.c
7863 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7864 case PT_LOAD:
7865 #ifdef CONFIG_RELOCATABLE
7866 dest = output;
7867 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7868 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7869 #else
7870 dest = (void *)(phdr->p_paddr);
7871 #endif
7872 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7873 error("Destination address too large");
7874 #endif
7875 #ifndef CONFIG_RELOCATABLE
7876 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7877 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7878 error("Wrong destination address");
7879 #endif
7880
7881 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7882 index e77f4e4..17e511f 100644
7883 --- a/arch/x86/boot/compressed/relocs.c
7884 +++ b/arch/x86/boot/compressed/relocs.c
7885 @@ -13,8 +13,11 @@
7886
7887 static void die(char *fmt, ...);
7888
7889 +#include "../../../../include/generated/autoconf.h"
7890 +
7891 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7892 static Elf32_Ehdr ehdr;
7893 +static Elf32_Phdr *phdr;
7894 static unsigned long reloc_count, reloc_idx;
7895 static unsigned long *relocs;
7896
7897 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
7898 }
7899 }
7900
7901 +static void read_phdrs(FILE *fp)
7902 +{
7903 + unsigned int i;
7904 +
7905 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7906 + if (!phdr) {
7907 + die("Unable to allocate %d program headers\n",
7908 + ehdr.e_phnum);
7909 + }
7910 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7911 + die("Seek to %d failed: %s\n",
7912 + ehdr.e_phoff, strerror(errno));
7913 + }
7914 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7915 + die("Cannot read ELF program headers: %s\n",
7916 + strerror(errno));
7917 + }
7918 + for(i = 0; i < ehdr.e_phnum; i++) {
7919 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7920 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7921 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7922 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7923 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7924 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7925 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7926 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7927 + }
7928 +
7929 +}
7930 +
7931 static void read_shdrs(FILE *fp)
7932 {
7933 - int i;
7934 + unsigned int i;
7935 Elf32_Shdr shdr;
7936
7937 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7938 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
7939
7940 static void read_strtabs(FILE *fp)
7941 {
7942 - int i;
7943 + unsigned int i;
7944 for (i = 0; i < ehdr.e_shnum; i++) {
7945 struct section *sec = &secs[i];
7946 if (sec->shdr.sh_type != SHT_STRTAB) {
7947 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
7948
7949 static void read_symtabs(FILE *fp)
7950 {
7951 - int i,j;
7952 + unsigned int i,j;
7953 for (i = 0; i < ehdr.e_shnum; i++) {
7954 struct section *sec = &secs[i];
7955 if (sec->shdr.sh_type != SHT_SYMTAB) {
7956 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
7957
7958 static void read_relocs(FILE *fp)
7959 {
7960 - int i,j;
7961 + unsigned int i,j;
7962 + uint32_t base;
7963 +
7964 for (i = 0; i < ehdr.e_shnum; i++) {
7965 struct section *sec = &secs[i];
7966 if (sec->shdr.sh_type != SHT_REL) {
7967 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
7968 die("Cannot read symbol table: %s\n",
7969 strerror(errno));
7970 }
7971 + base = 0;
7972 + for (j = 0; j < ehdr.e_phnum; j++) {
7973 + if (phdr[j].p_type != PT_LOAD )
7974 + continue;
7975 + 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)
7976 + continue;
7977 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7978 + break;
7979 + }
7980 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7981 Elf32_Rel *rel = &sec->reltab[j];
7982 - rel->r_offset = elf32_to_cpu(rel->r_offset);
7983 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7984 rel->r_info = elf32_to_cpu(rel->r_info);
7985 }
7986 }
7987 @@ -396,13 +440,13 @@ static void read_relocs(FILE *fp)
7988
7989 static void print_absolute_symbols(void)
7990 {
7991 - int i;
7992 + unsigned int i;
7993 printf("Absolute symbols\n");
7994 printf(" Num: Value Size Type Bind Visibility Name\n");
7995 for (i = 0; i < ehdr.e_shnum; i++) {
7996 struct section *sec = &secs[i];
7997 char *sym_strtab;
7998 - int j;
7999 + unsigned int j;
8000
8001 if (sec->shdr.sh_type != SHT_SYMTAB) {
8002 continue;
8003 @@ -429,14 +473,14 @@ static void print_absolute_symbols(void)
8004
8005 static void print_absolute_relocs(void)
8006 {
8007 - int i, printed = 0;
8008 + unsigned int i, printed = 0;
8009
8010 for (i = 0; i < ehdr.e_shnum; i++) {
8011 struct section *sec = &secs[i];
8012 struct section *sec_applies, *sec_symtab;
8013 char *sym_strtab;
8014 Elf32_Sym *sh_symtab;
8015 - int j;
8016 + unsigned int j;
8017 if (sec->shdr.sh_type != SHT_REL) {
8018 continue;
8019 }
8020 @@ -497,13 +541,13 @@ static void print_absolute_relocs(void)
8021
8022 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
8023 {
8024 - int i;
8025 + unsigned int i;
8026 /* Walk through the relocations */
8027 for (i = 0; i < ehdr.e_shnum; i++) {
8028 char *sym_strtab;
8029 Elf32_Sym *sh_symtab;
8030 struct section *sec_applies, *sec_symtab;
8031 - int j;
8032 + unsigned int j;
8033 struct section *sec = &secs[i];
8034
8035 if (sec->shdr.sh_type != SHT_REL) {
8036 @@ -528,6 +572,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
8037 !is_rel_reloc(sym_name(sym_strtab, sym))) {
8038 continue;
8039 }
8040 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
8041 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
8042 + continue;
8043 +
8044 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
8045 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
8046 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
8047 + continue;
8048 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
8049 + continue;
8050 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
8051 + continue;
8052 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
8053 + continue;
8054 +#endif
8055 +
8056 switch (r_type) {
8057 case R_386_NONE:
8058 case R_386_PC32:
8059 @@ -569,7 +629,7 @@ static int cmp_relocs(const void *va, const void *vb)
8060
8061 static void emit_relocs(int as_text)
8062 {
8063 - int i;
8064 + unsigned int i;
8065 /* Count how many relocations I have and allocate space for them. */
8066 reloc_count = 0;
8067 walk_relocs(count_reloc);
8068 @@ -663,6 +723,7 @@ int main(int argc, char **argv)
8069 fname, strerror(errno));
8070 }
8071 read_ehdr(fp);
8072 + read_phdrs(fp);
8073 read_shdrs(fp);
8074 read_strtabs(fp);
8075 read_symtabs(fp);
8076 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
8077 index 4d3ff03..e4972ff 100644
8078 --- a/arch/x86/boot/cpucheck.c
8079 +++ b/arch/x86/boot/cpucheck.c
8080 @@ -74,7 +74,7 @@ static int has_fpu(void)
8081 u16 fcw = -1, fsw = -1;
8082 u32 cr0;
8083
8084 - asm("movl %%cr0,%0" : "=r" (cr0));
8085 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
8086 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
8087 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
8088 asm volatile("movl %0,%%cr0" : : "r" (cr0));
8089 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
8090 {
8091 u32 f0, f1;
8092
8093 - asm("pushfl ; "
8094 + asm volatile("pushfl ; "
8095 "pushfl ; "
8096 "popl %0 ; "
8097 "movl %0,%1 ; "
8098 @@ -115,7 +115,7 @@ static void get_flags(void)
8099 set_bit(X86_FEATURE_FPU, cpu.flags);
8100
8101 if (has_eflag(X86_EFLAGS_ID)) {
8102 - asm("cpuid"
8103 + asm volatile("cpuid"
8104 : "=a" (max_intel_level),
8105 "=b" (cpu_vendor[0]),
8106 "=d" (cpu_vendor[1]),
8107 @@ -124,7 +124,7 @@ static void get_flags(void)
8108
8109 if (max_intel_level >= 0x00000001 &&
8110 max_intel_level <= 0x0000ffff) {
8111 - asm("cpuid"
8112 + asm volatile("cpuid"
8113 : "=a" (tfms),
8114 "=c" (cpu.flags[4]),
8115 "=d" (cpu.flags[0])
8116 @@ -136,7 +136,7 @@ static void get_flags(void)
8117 cpu.model += ((tfms >> 16) & 0xf) << 4;
8118 }
8119
8120 - asm("cpuid"
8121 + asm volatile("cpuid"
8122 : "=a" (max_amd_level)
8123 : "a" (0x80000000)
8124 : "ebx", "ecx", "edx");
8125 @@ -144,7 +144,7 @@ static void get_flags(void)
8126 if (max_amd_level >= 0x80000001 &&
8127 max_amd_level <= 0x8000ffff) {
8128 u32 eax = 0x80000001;
8129 - asm("cpuid"
8130 + asm volatile("cpuid"
8131 : "+a" (eax),
8132 "=c" (cpu.flags[6]),
8133 "=d" (cpu.flags[1])
8134 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8135 u32 ecx = MSR_K7_HWCR;
8136 u32 eax, edx;
8137
8138 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8139 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8140 eax &= ~(1 << 15);
8141 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8142 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8143
8144 get_flags(); /* Make sure it really did something */
8145 err = check_flags();
8146 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8147 u32 ecx = MSR_VIA_FCR;
8148 u32 eax, edx;
8149
8150 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8151 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8152 eax |= (1<<1)|(1<<7);
8153 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8154 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8155
8156 set_bit(X86_FEATURE_CX8, cpu.flags);
8157 err = check_flags();
8158 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8159 u32 eax, edx;
8160 u32 level = 1;
8161
8162 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8163 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8164 - asm("cpuid"
8165 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8166 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8167 + asm volatile("cpuid"
8168 : "+a" (level), "=d" (cpu.flags[0])
8169 : : "ecx", "ebx");
8170 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8171 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8172
8173 err = check_flags();
8174 }
8175 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8176 index f1bbeeb..aff09cb 100644
8177 --- a/arch/x86/boot/header.S
8178 +++ b/arch/x86/boot/header.S
8179 @@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
8180 # single linked list of
8181 # struct setup_data
8182
8183 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8184 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8185
8186 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8187 #define VO_INIT_SIZE (VO__end - VO__text)
8188 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8189 index db75d07..8e6d0af 100644
8190 --- a/arch/x86/boot/memory.c
8191 +++ b/arch/x86/boot/memory.c
8192 @@ -19,7 +19,7 @@
8193
8194 static int detect_memory_e820(void)
8195 {
8196 - int count = 0;
8197 + unsigned int count = 0;
8198 struct biosregs ireg, oreg;
8199 struct e820entry *desc = boot_params.e820_map;
8200 static struct e820entry buf; /* static so it is zeroed */
8201 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8202 index 11e8c6e..fdbb1ed 100644
8203 --- a/arch/x86/boot/video-vesa.c
8204 +++ b/arch/x86/boot/video-vesa.c
8205 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8206
8207 boot_params.screen_info.vesapm_seg = oreg.es;
8208 boot_params.screen_info.vesapm_off = oreg.di;
8209 + boot_params.screen_info.vesapm_size = oreg.cx;
8210 }
8211
8212 /*
8213 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8214 index 43eda28..5ab5fdb 100644
8215 --- a/arch/x86/boot/video.c
8216 +++ b/arch/x86/boot/video.c
8217 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8218 static unsigned int get_entry(void)
8219 {
8220 char entry_buf[4];
8221 - int i, len = 0;
8222 + unsigned int i, len = 0;
8223 int key;
8224 unsigned int v;
8225
8226 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8227 index 5b577d5..3c1fed4 100644
8228 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8229 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8230 @@ -8,6 +8,8 @@
8231 * including this sentence is retained in full.
8232 */
8233
8234 +#include <asm/alternative-asm.h>
8235 +
8236 .extern crypto_ft_tab
8237 .extern crypto_it_tab
8238 .extern crypto_fl_tab
8239 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8240 je B192; \
8241 leaq 32(r9),r9;
8242
8243 +#define ret pax_force_retaddr 0, 1; ret
8244 +
8245 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8246 movq r1,r2; \
8247 movq r3,r4; \
8248 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8249 index be6d9e3..21fbbca 100644
8250 --- a/arch/x86/crypto/aesni-intel_asm.S
8251 +++ b/arch/x86/crypto/aesni-intel_asm.S
8252 @@ -31,6 +31,7 @@
8253
8254 #include <linux/linkage.h>
8255 #include <asm/inst.h>
8256 +#include <asm/alternative-asm.h>
8257
8258 #ifdef __x86_64__
8259 .data
8260 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8261 pop %r14
8262 pop %r13
8263 pop %r12
8264 + pax_force_retaddr 0, 1
8265 ret
8266 +ENDPROC(aesni_gcm_dec)
8267
8268
8269 /*****************************************************************************
8270 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8271 pop %r14
8272 pop %r13
8273 pop %r12
8274 + pax_force_retaddr 0, 1
8275 ret
8276 +ENDPROC(aesni_gcm_enc)
8277
8278 #endif
8279
8280 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8281 pxor %xmm1, %xmm0
8282 movaps %xmm0, (TKEYP)
8283 add $0x10, TKEYP
8284 + pax_force_retaddr_bts
8285 ret
8286
8287 .align 4
8288 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8289 shufps $0b01001110, %xmm2, %xmm1
8290 movaps %xmm1, 0x10(TKEYP)
8291 add $0x20, TKEYP
8292 + pax_force_retaddr_bts
8293 ret
8294
8295 .align 4
8296 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8297
8298 movaps %xmm0, (TKEYP)
8299 add $0x10, TKEYP
8300 + pax_force_retaddr_bts
8301 ret
8302
8303 .align 4
8304 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8305 pxor %xmm1, %xmm2
8306 movaps %xmm2, (TKEYP)
8307 add $0x10, TKEYP
8308 + pax_force_retaddr_bts
8309 ret
8310
8311 /*
8312 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8313 #ifndef __x86_64__
8314 popl KEYP
8315 #endif
8316 + pax_force_retaddr 0, 1
8317 ret
8318 +ENDPROC(aesni_set_key)
8319
8320 /*
8321 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8322 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8323 popl KLEN
8324 popl KEYP
8325 #endif
8326 + pax_force_retaddr 0, 1
8327 ret
8328 +ENDPROC(aesni_enc)
8329
8330 /*
8331 * _aesni_enc1: internal ABI
8332 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8333 AESENC KEY STATE
8334 movaps 0x70(TKEYP), KEY
8335 AESENCLAST KEY STATE
8336 + pax_force_retaddr_bts
8337 ret
8338
8339 /*
8340 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8341 AESENCLAST KEY STATE2
8342 AESENCLAST KEY STATE3
8343 AESENCLAST KEY STATE4
8344 + pax_force_retaddr_bts
8345 ret
8346
8347 /*
8348 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8349 popl KLEN
8350 popl KEYP
8351 #endif
8352 + pax_force_retaddr 0, 1
8353 ret
8354 +ENDPROC(aesni_dec)
8355
8356 /*
8357 * _aesni_dec1: internal ABI
8358 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8359 AESDEC KEY STATE
8360 movaps 0x70(TKEYP), KEY
8361 AESDECLAST KEY STATE
8362 + pax_force_retaddr_bts
8363 ret
8364
8365 /*
8366 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8367 AESDECLAST KEY STATE2
8368 AESDECLAST KEY STATE3
8369 AESDECLAST KEY STATE4
8370 + pax_force_retaddr_bts
8371 ret
8372
8373 /*
8374 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8375 popl KEYP
8376 popl LEN
8377 #endif
8378 + pax_force_retaddr 0, 1
8379 ret
8380 +ENDPROC(aesni_ecb_enc)
8381
8382 /*
8383 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8384 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8385 popl KEYP
8386 popl LEN
8387 #endif
8388 + pax_force_retaddr 0, 1
8389 ret
8390 +ENDPROC(aesni_ecb_dec)
8391
8392 /*
8393 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8394 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8395 popl LEN
8396 popl IVP
8397 #endif
8398 + pax_force_retaddr 0, 1
8399 ret
8400 +ENDPROC(aesni_cbc_enc)
8401
8402 /*
8403 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8404 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
8405 popl LEN
8406 popl IVP
8407 #endif
8408 + pax_force_retaddr 0, 1
8409 ret
8410 +ENDPROC(aesni_cbc_dec)
8411
8412 #ifdef __x86_64__
8413 .align 16
8414 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
8415 mov $1, TCTR_LOW
8416 MOVQ_R64_XMM TCTR_LOW INC
8417 MOVQ_R64_XMM CTR TCTR_LOW
8418 + pax_force_retaddr_bts
8419 ret
8420
8421 /*
8422 @@ -2552,6 +2580,7 @@ _aesni_inc:
8423 .Linc_low:
8424 movaps CTR, IV
8425 PSHUFB_XMM BSWAP_MASK IV
8426 + pax_force_retaddr_bts
8427 ret
8428
8429 /*
8430 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
8431 .Lctr_enc_ret:
8432 movups IV, (IVP)
8433 .Lctr_enc_just_ret:
8434 + pax_force_retaddr 0, 1
8435 ret
8436 +ENDPROC(aesni_ctr_enc)
8437 #endif
8438 diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
8439 index 545d0ce..14841a6 100644
8440 --- a/arch/x86/crypto/aesni-intel_glue.c
8441 +++ b/arch/x86/crypto/aesni-intel_glue.c
8442 @@ -929,6 +929,8 @@ out_free_ablkcipher:
8443 }
8444
8445 static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
8446 + unsigned int key_len) __size_overflow(3);
8447 +static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
8448 unsigned int key_len)
8449 {
8450 int ret = 0;
8451 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8452 index 391d245..67f35c2 100644
8453 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8454 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8455 @@ -20,6 +20,8 @@
8456 *
8457 */
8458
8459 +#include <asm/alternative-asm.h>
8460 +
8461 .file "blowfish-x86_64-asm.S"
8462 .text
8463
8464 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8465 jnz __enc_xor;
8466
8467 write_block();
8468 + pax_force_retaddr 0, 1
8469 ret;
8470 __enc_xor:
8471 xor_block();
8472 + pax_force_retaddr 0, 1
8473 ret;
8474
8475 .align 8
8476 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8477
8478 movq %r11, %rbp;
8479
8480 + pax_force_retaddr 0, 1
8481 ret;
8482
8483 /**********************************************************************
8484 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8485
8486 popq %rbx;
8487 popq %rbp;
8488 + pax_force_retaddr 0, 1
8489 ret;
8490
8491 __enc_xor4:
8492 @@ -349,6 +355,7 @@ __enc_xor4:
8493
8494 popq %rbx;
8495 popq %rbp;
8496 + pax_force_retaddr 0, 1
8497 ret;
8498
8499 .align 8
8500 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8501 popq %rbx;
8502 popq %rbp;
8503
8504 + pax_force_retaddr 0, 1
8505 ret;
8506
8507 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8508 index 6214a9b..1f4fc9a 100644
8509 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8510 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8511 @@ -1,3 +1,5 @@
8512 +#include <asm/alternative-asm.h>
8513 +
8514 # enter ECRYPT_encrypt_bytes
8515 .text
8516 .p2align 5
8517 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8518 add %r11,%rsp
8519 mov %rdi,%rax
8520 mov %rsi,%rdx
8521 + pax_force_retaddr 0, 1
8522 ret
8523 # bytesatleast65:
8524 ._bytesatleast65:
8525 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8526 add %r11,%rsp
8527 mov %rdi,%rax
8528 mov %rsi,%rdx
8529 + pax_force_retaddr
8530 ret
8531 # enter ECRYPT_ivsetup
8532 .text
8533 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8534 add %r11,%rsp
8535 mov %rdi,%rax
8536 mov %rsi,%rdx
8537 + pax_force_retaddr
8538 ret
8539 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8540 index 7f24a15..9cd3ffe 100644
8541 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8542 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8543 @@ -24,6 +24,8 @@
8544 *
8545 */
8546
8547 +#include <asm/alternative-asm.h>
8548 +
8549 .file "serpent-sse2-x86_64-asm_64.S"
8550 .text
8551
8552 @@ -695,12 +697,14 @@ __serpent_enc_blk_8way:
8553 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8554 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8555
8556 + pax_force_retaddr
8557 ret;
8558
8559 __enc_xor8:
8560 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8561 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8562
8563 + pax_force_retaddr
8564 ret;
8565
8566 .align 8
8567 @@ -758,4 +762,5 @@ serpent_dec_blk_8way:
8568 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8569 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8570
8571 + pax_force_retaddr
8572 ret;
8573 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8574 index b2c2f57..8470cab 100644
8575 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8576 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8577 @@ -28,6 +28,8 @@
8578 * (at your option) any later version.
8579 */
8580
8581 +#include <asm/alternative-asm.h>
8582 +
8583 #define CTX %rdi // arg1
8584 #define BUF %rsi // arg2
8585 #define CNT %rdx // arg3
8586 @@ -104,6 +106,7 @@
8587 pop %r12
8588 pop %rbp
8589 pop %rbx
8590 + pax_force_retaddr 0, 1
8591 ret
8592
8593 .size \name, .-\name
8594 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8595 index 5b012a2..36d5364 100644
8596 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8597 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8598 @@ -20,6 +20,8 @@
8599 *
8600 */
8601
8602 +#include <asm/alternative-asm.h>
8603 +
8604 .file "twofish-x86_64-asm-3way.S"
8605 .text
8606
8607 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8608 popq %r13;
8609 popq %r14;
8610 popq %r15;
8611 + pax_force_retaddr 0, 1
8612 ret;
8613
8614 __enc_xor3:
8615 @@ -271,6 +274,7 @@ __enc_xor3:
8616 popq %r13;
8617 popq %r14;
8618 popq %r15;
8619 + pax_force_retaddr 0, 1
8620 ret;
8621
8622 .global twofish_dec_blk_3way
8623 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8624 popq %r13;
8625 popq %r14;
8626 popq %r15;
8627 + pax_force_retaddr 0, 1
8628 ret;
8629
8630 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8631 index 7bcf3fc..f53832f 100644
8632 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8633 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8634 @@ -21,6 +21,7 @@
8635 .text
8636
8637 #include <asm/asm-offsets.h>
8638 +#include <asm/alternative-asm.h>
8639
8640 #define a_offset 0
8641 #define b_offset 4
8642 @@ -268,6 +269,7 @@ twofish_enc_blk:
8643
8644 popq R1
8645 movq $1,%rax
8646 + pax_force_retaddr 0, 1
8647 ret
8648
8649 twofish_dec_blk:
8650 @@ -319,4 +321,5 @@ twofish_dec_blk:
8651
8652 popq R1
8653 movq $1,%rax
8654 + pax_force_retaddr 0, 1
8655 ret
8656 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8657 index 39e4909..887aa7e 100644
8658 --- a/arch/x86/ia32/ia32_aout.c
8659 +++ b/arch/x86/ia32/ia32_aout.c
8660 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8661 unsigned long dump_start, dump_size;
8662 struct user32 dump;
8663
8664 + memset(&dump, 0, sizeof(dump));
8665 +
8666 fs = get_fs();
8667 set_fs(KERNEL_DS);
8668 has_dumped = 1;
8669 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8670 index 6557769..ef6ae89 100644
8671 --- a/arch/x86/ia32/ia32_signal.c
8672 +++ b/arch/x86/ia32/ia32_signal.c
8673 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8674 }
8675 seg = get_fs();
8676 set_fs(KERNEL_DS);
8677 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8678 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8679 set_fs(seg);
8680 if (ret >= 0 && uoss_ptr) {
8681 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8682 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8683 */
8684 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8685 size_t frame_size,
8686 - void **fpstate)
8687 + void __user **fpstate)
8688 {
8689 unsigned long sp;
8690
8691 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8692
8693 if (used_math()) {
8694 sp = sp - sig_xstate_ia32_size;
8695 - *fpstate = (struct _fpstate_ia32 *) sp;
8696 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8697 if (save_i387_xstate_ia32(*fpstate) < 0)
8698 return (void __user *) -1L;
8699 }
8700 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8701 sp -= frame_size;
8702 /* Align the stack pointer according to the i386 ABI,
8703 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8704 - sp = ((sp + 4) & -16ul) - 4;
8705 + sp = ((sp - 12) & -16ul) - 4;
8706 return (void __user *) sp;
8707 }
8708
8709 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8710 * These are actually not used anymore, but left because some
8711 * gdb versions depend on them as a marker.
8712 */
8713 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8714 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8715 } put_user_catch(err);
8716
8717 if (err)
8718 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8719 0xb8,
8720 __NR_ia32_rt_sigreturn,
8721 0x80cd,
8722 - 0,
8723 + 0
8724 };
8725
8726 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8727 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8728
8729 if (ka->sa.sa_flags & SA_RESTORER)
8730 restorer = ka->sa.sa_restorer;
8731 + else if (current->mm->context.vdso)
8732 + /* Return stub is in 32bit vsyscall page */
8733 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8734 else
8735 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8736 - rt_sigreturn);
8737 + restorer = &frame->retcode;
8738 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8739
8740 /*
8741 * Not actually used anymore, but left because some gdb
8742 * versions need it.
8743 */
8744 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8745 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8746 } put_user_catch(err);
8747
8748 if (err)
8749 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8750 index e3e7340..05ed805 100644
8751 --- a/arch/x86/ia32/ia32entry.S
8752 +++ b/arch/x86/ia32/ia32entry.S
8753 @@ -13,8 +13,10 @@
8754 #include <asm/thread_info.h>
8755 #include <asm/segment.h>
8756 #include <asm/irqflags.h>
8757 +#include <asm/pgtable.h>
8758 #include <linux/linkage.h>
8759 #include <linux/err.h>
8760 +#include <asm/alternative-asm.h>
8761
8762 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8763 #include <linux/elf-em.h>
8764 @@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8765 ENDPROC(native_irq_enable_sysexit)
8766 #endif
8767
8768 + .macro pax_enter_kernel_user
8769 + pax_set_fptr_mask
8770 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8771 + call pax_enter_kernel_user
8772 +#endif
8773 + .endm
8774 +
8775 + .macro pax_exit_kernel_user
8776 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8777 + call pax_exit_kernel_user
8778 +#endif
8779 +#ifdef CONFIG_PAX_RANDKSTACK
8780 + pushq %rax
8781 + pushq %r11
8782 + call pax_randomize_kstack
8783 + popq %r11
8784 + popq %rax
8785 +#endif
8786 + .endm
8787 +
8788 +.macro pax_erase_kstack
8789 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8790 + call pax_erase_kstack
8791 +#endif
8792 +.endm
8793 +
8794 /*
8795 * 32bit SYSENTER instruction entry.
8796 *
8797 @@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8798 CFI_REGISTER rsp,rbp
8799 SWAPGS_UNSAFE_STACK
8800 movq PER_CPU_VAR(kernel_stack), %rsp
8801 - addq $(KERNEL_STACK_OFFSET),%rsp
8802 - /*
8803 - * No need to follow this irqs on/off section: the syscall
8804 - * disabled irqs, here we enable it straight after entry:
8805 - */
8806 - ENABLE_INTERRUPTS(CLBR_NONE)
8807 movl %ebp,%ebp /* zero extension */
8808 pushq_cfi $__USER32_DS
8809 /*CFI_REL_OFFSET ss,0*/
8810 @@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8811 CFI_REL_OFFSET rsp,0
8812 pushfq_cfi
8813 /*CFI_REL_OFFSET rflags,0*/
8814 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8815 - CFI_REGISTER rip,r10
8816 + orl $X86_EFLAGS_IF,(%rsp)
8817 + GET_THREAD_INFO(%r11)
8818 + movl TI_sysenter_return(%r11), %r11d
8819 + CFI_REGISTER rip,r11
8820 pushq_cfi $__USER32_CS
8821 /*CFI_REL_OFFSET cs,0*/
8822 movl %eax, %eax
8823 - pushq_cfi %r10
8824 + pushq_cfi %r11
8825 CFI_REL_OFFSET rip,0
8826 pushq_cfi %rax
8827 cld
8828 SAVE_ARGS 0,1,0
8829 + pax_enter_kernel_user
8830 + /*
8831 + * No need to follow this irqs on/off section: the syscall
8832 + * disabled irqs, here we enable it straight after entry:
8833 + */
8834 + ENABLE_INTERRUPTS(CLBR_NONE)
8835 /* no need to do an access_ok check here because rbp has been
8836 32bit zero extended */
8837 +
8838 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8839 + mov $PAX_USER_SHADOW_BASE,%r11
8840 + add %r11,%rbp
8841 +#endif
8842 +
8843 1: movl (%rbp),%ebp
8844 .section __ex_table,"a"
8845 .quad 1b,ia32_badarg
8846 .previous
8847 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8848 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8849 + GET_THREAD_INFO(%r11)
8850 + orl $TS_COMPAT,TI_status(%r11)
8851 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8852 CFI_REMEMBER_STATE
8853 jnz sysenter_tracesys
8854 cmpq $(IA32_NR_syscalls-1),%rax
8855 @@ -160,12 +197,15 @@ sysenter_do_call:
8856 sysenter_dispatch:
8857 call *ia32_sys_call_table(,%rax,8)
8858 movq %rax,RAX-ARGOFFSET(%rsp)
8859 + GET_THREAD_INFO(%r11)
8860 DISABLE_INTERRUPTS(CLBR_NONE)
8861 TRACE_IRQS_OFF
8862 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8863 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8864 jnz sysexit_audit
8865 sysexit_from_sys_call:
8866 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8867 + pax_exit_kernel_user
8868 + pax_erase_kstack
8869 + andl $~TS_COMPAT,TI_status(%r11)
8870 /* clear IF, that popfq doesn't enable interrupts early */
8871 andl $~0x200,EFLAGS-R11(%rsp)
8872 movl RIP-R11(%rsp),%edx /* User %eip */
8873 @@ -191,6 +231,9 @@ sysexit_from_sys_call:
8874 movl %eax,%esi /* 2nd arg: syscall number */
8875 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8876 call __audit_syscall_entry
8877 +
8878 + pax_erase_kstack
8879 +
8880 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8881 cmpq $(IA32_NR_syscalls-1),%rax
8882 ja ia32_badsys
8883 @@ -202,7 +245,7 @@ sysexit_from_sys_call:
8884 .endm
8885
8886 .macro auditsys_exit exit
8887 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8888 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8889 jnz ia32_ret_from_sys_call
8890 TRACE_IRQS_ON
8891 sti
8892 @@ -213,11 +256,12 @@ sysexit_from_sys_call:
8893 1: setbe %al /* 1 if error, 0 if not */
8894 movzbl %al,%edi /* zero-extend that into %edi */
8895 call __audit_syscall_exit
8896 + GET_THREAD_INFO(%r11)
8897 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8898 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8899 cli
8900 TRACE_IRQS_OFF
8901 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8902 + testl %edi,TI_flags(%r11)
8903 jz \exit
8904 CLEAR_RREGS -ARGOFFSET
8905 jmp int_with_check
8906 @@ -235,7 +279,7 @@ sysexit_audit:
8907
8908 sysenter_tracesys:
8909 #ifdef CONFIG_AUDITSYSCALL
8910 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8911 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8912 jz sysenter_auditsys
8913 #endif
8914 SAVE_REST
8915 @@ -243,6 +287,9 @@ sysenter_tracesys:
8916 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8917 movq %rsp,%rdi /* &pt_regs -> arg1 */
8918 call syscall_trace_enter
8919 +
8920 + pax_erase_kstack
8921 +
8922 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8923 RESTORE_REST
8924 cmpq $(IA32_NR_syscalls-1),%rax
8925 @@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8926 ENTRY(ia32_cstar_target)
8927 CFI_STARTPROC32 simple
8928 CFI_SIGNAL_FRAME
8929 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8930 + CFI_DEF_CFA rsp,0
8931 CFI_REGISTER rip,rcx
8932 /*CFI_REGISTER rflags,r11*/
8933 SWAPGS_UNSAFE_STACK
8934 movl %esp,%r8d
8935 CFI_REGISTER rsp,r8
8936 movq PER_CPU_VAR(kernel_stack),%rsp
8937 + SAVE_ARGS 8*6,0,0
8938 + pax_enter_kernel_user
8939 /*
8940 * No need to follow this irqs on/off section: the syscall
8941 * disabled irqs and here we enable it straight after entry:
8942 */
8943 ENABLE_INTERRUPTS(CLBR_NONE)
8944 - SAVE_ARGS 8,0,0
8945 movl %eax,%eax /* zero extension */
8946 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8947 movq %rcx,RIP-ARGOFFSET(%rsp)
8948 @@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8949 /* no need to do an access_ok check here because r8 has been
8950 32bit zero extended */
8951 /* hardware stack frame is complete now */
8952 +
8953 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8954 + mov $PAX_USER_SHADOW_BASE,%r11
8955 + add %r11,%r8
8956 +#endif
8957 +
8958 1: movl (%r8),%r9d
8959 .section __ex_table,"a"
8960 .quad 1b,ia32_badarg
8961 .previous
8962 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8963 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8964 + GET_THREAD_INFO(%r11)
8965 + orl $TS_COMPAT,TI_status(%r11)
8966 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8967 CFI_REMEMBER_STATE
8968 jnz cstar_tracesys
8969 cmpq $IA32_NR_syscalls-1,%rax
8970 @@ -317,12 +372,15 @@ cstar_do_call:
8971 cstar_dispatch:
8972 call *ia32_sys_call_table(,%rax,8)
8973 movq %rax,RAX-ARGOFFSET(%rsp)
8974 + GET_THREAD_INFO(%r11)
8975 DISABLE_INTERRUPTS(CLBR_NONE)
8976 TRACE_IRQS_OFF
8977 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8978 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8979 jnz sysretl_audit
8980 sysretl_from_sys_call:
8981 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8982 + pax_exit_kernel_user
8983 + pax_erase_kstack
8984 + andl $~TS_COMPAT,TI_status(%r11)
8985 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8986 movl RIP-ARGOFFSET(%rsp),%ecx
8987 CFI_REGISTER rip,rcx
8988 @@ -350,7 +408,7 @@ sysretl_audit:
8989
8990 cstar_tracesys:
8991 #ifdef CONFIG_AUDITSYSCALL
8992 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8993 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8994 jz cstar_auditsys
8995 #endif
8996 xchgl %r9d,%ebp
8997 @@ -359,6 +417,9 @@ cstar_tracesys:
8998 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8999 movq %rsp,%rdi /* &pt_regs -> arg1 */
9000 call syscall_trace_enter
9001 +
9002 + pax_erase_kstack
9003 +
9004 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
9005 RESTORE_REST
9006 xchgl %ebp,%r9d
9007 @@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
9008 CFI_REL_OFFSET rip,RIP-RIP
9009 PARAVIRT_ADJUST_EXCEPTION_FRAME
9010 SWAPGS
9011 - /*
9012 - * No need to follow this irqs on/off section: the syscall
9013 - * disabled irqs and here we enable it straight after entry:
9014 - */
9015 - ENABLE_INTERRUPTS(CLBR_NONE)
9016 movl %eax,%eax
9017 pushq_cfi %rax
9018 cld
9019 /* note the registers are not zero extended to the sf.
9020 this could be a problem. */
9021 SAVE_ARGS 0,1,0
9022 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9023 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9024 + pax_enter_kernel_user
9025 + /*
9026 + * No need to follow this irqs on/off section: the syscall
9027 + * disabled irqs and here we enable it straight after entry:
9028 + */
9029 + ENABLE_INTERRUPTS(CLBR_NONE)
9030 + GET_THREAD_INFO(%r11)
9031 + orl $TS_COMPAT,TI_status(%r11)
9032 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9033 jnz ia32_tracesys
9034 cmpq $(IA32_NR_syscalls-1),%rax
9035 ja ia32_badsys
9036 @@ -435,6 +498,9 @@ ia32_tracesys:
9037 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
9038 movq %rsp,%rdi /* &pt_regs -> arg1 */
9039 call syscall_trace_enter
9040 +
9041 + pax_erase_kstack
9042 +
9043 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
9044 RESTORE_REST
9045 cmpq $(IA32_NR_syscalls-1),%rax
9046 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
9047 index f6f5c53..b358b28 100644
9048 --- a/arch/x86/ia32/sys_ia32.c
9049 +++ b/arch/x86/ia32/sys_ia32.c
9050 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
9051 */
9052 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
9053 {
9054 - typeof(ubuf->st_uid) uid = 0;
9055 - typeof(ubuf->st_gid) gid = 0;
9056 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
9057 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
9058 SET_UID(uid, stat->uid);
9059 SET_GID(gid, stat->gid);
9060 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
9061 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
9062 }
9063 set_fs(KERNEL_DS);
9064 ret = sys_rt_sigprocmask(how,
9065 - set ? (sigset_t __user *)&s : NULL,
9066 - oset ? (sigset_t __user *)&s : NULL,
9067 + set ? (sigset_t __force_user *)&s : NULL,
9068 + oset ? (sigset_t __force_user *)&s : NULL,
9069 sigsetsize);
9070 set_fs(old_fs);
9071 if (ret)
9072 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
9073 return alarm_setitimer(seconds);
9074 }
9075
9076 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
9077 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
9078 int options)
9079 {
9080 return compat_sys_wait4(pid, stat_addr, options, NULL);
9081 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
9082 mm_segment_t old_fs = get_fs();
9083
9084 set_fs(KERNEL_DS);
9085 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9086 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9087 set_fs(old_fs);
9088 if (put_compat_timespec(&t, interval))
9089 return -EFAULT;
9090 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9091 mm_segment_t old_fs = get_fs();
9092
9093 set_fs(KERNEL_DS);
9094 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9095 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9096 set_fs(old_fs);
9097 if (!ret) {
9098 switch (_NSIG_WORDS) {
9099 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9100 if (copy_siginfo_from_user32(&info, uinfo))
9101 return -EFAULT;
9102 set_fs(KERNEL_DS);
9103 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9104 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9105 set_fs(old_fs);
9106 return ret;
9107 }
9108 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9109 return -EFAULT;
9110
9111 set_fs(KERNEL_DS);
9112 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9113 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9114 count);
9115 set_fs(old_fs);
9116
9117 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9118 index 952bd01..7692c6f 100644
9119 --- a/arch/x86/include/asm/alternative-asm.h
9120 +++ b/arch/x86/include/asm/alternative-asm.h
9121 @@ -15,6 +15,45 @@
9122 .endm
9123 #endif
9124
9125 +#ifdef KERNEXEC_PLUGIN
9126 + .macro pax_force_retaddr_bts rip=0
9127 + btsq $63,\rip(%rsp)
9128 + .endm
9129 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9130 + .macro pax_force_retaddr rip=0, reload=0
9131 + btsq $63,\rip(%rsp)
9132 + .endm
9133 + .macro pax_force_fptr ptr
9134 + btsq $63,\ptr
9135 + .endm
9136 + .macro pax_set_fptr_mask
9137 + .endm
9138 +#endif
9139 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9140 + .macro pax_force_retaddr rip=0, reload=0
9141 + .if \reload
9142 + pax_set_fptr_mask
9143 + .endif
9144 + orq %r10,\rip(%rsp)
9145 + .endm
9146 + .macro pax_force_fptr ptr
9147 + orq %r10,\ptr
9148 + .endm
9149 + .macro pax_set_fptr_mask
9150 + movabs $0x8000000000000000,%r10
9151 + .endm
9152 +#endif
9153 +#else
9154 + .macro pax_force_retaddr rip=0, reload=0
9155 + .endm
9156 + .macro pax_force_fptr ptr
9157 + .endm
9158 + .macro pax_force_retaddr_bts rip=0
9159 + .endm
9160 + .macro pax_set_fptr_mask
9161 + .endm
9162 +#endif
9163 +
9164 .macro altinstruction_entry orig alt feature orig_len alt_len
9165 .long \orig - .
9166 .long \alt - .
9167 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9168 index 37ad100..7d47faa 100644
9169 --- a/arch/x86/include/asm/alternative.h
9170 +++ b/arch/x86/include/asm/alternative.h
9171 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9172 ".section .discard,\"aw\",@progbits\n" \
9173 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9174 ".previous\n" \
9175 - ".section .altinstr_replacement, \"ax\"\n" \
9176 + ".section .altinstr_replacement, \"a\"\n" \
9177 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9178 ".previous"
9179
9180 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9181 index 3ab9bdd..238033e 100644
9182 --- a/arch/x86/include/asm/apic.h
9183 +++ b/arch/x86/include/asm/apic.h
9184 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
9185
9186 #ifdef CONFIG_X86_LOCAL_APIC
9187
9188 -extern unsigned int apic_verbosity;
9189 +extern int apic_verbosity;
9190 extern int local_apic_timer_c2_ok;
9191
9192 extern int disable_apic;
9193 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9194 index 20370c6..a2eb9b0 100644
9195 --- a/arch/x86/include/asm/apm.h
9196 +++ b/arch/x86/include/asm/apm.h
9197 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9198 __asm__ __volatile__(APM_DO_ZERO_SEGS
9199 "pushl %%edi\n\t"
9200 "pushl %%ebp\n\t"
9201 - "lcall *%%cs:apm_bios_entry\n\t"
9202 + "lcall *%%ss:apm_bios_entry\n\t"
9203 "setc %%al\n\t"
9204 "popl %%ebp\n\t"
9205 "popl %%edi\n\t"
9206 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9207 __asm__ __volatile__(APM_DO_ZERO_SEGS
9208 "pushl %%edi\n\t"
9209 "pushl %%ebp\n\t"
9210 - "lcall *%%cs:apm_bios_entry\n\t"
9211 + "lcall *%%ss:apm_bios_entry\n\t"
9212 "setc %%bl\n\t"
9213 "popl %%ebp\n\t"
9214 "popl %%edi\n\t"
9215 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9216 index 58cb6d4..ca9010d 100644
9217 --- a/arch/x86/include/asm/atomic.h
9218 +++ b/arch/x86/include/asm/atomic.h
9219 @@ -22,7 +22,18 @@
9220 */
9221 static inline int atomic_read(const atomic_t *v)
9222 {
9223 - return (*(volatile int *)&(v)->counter);
9224 + return (*(volatile const int *)&(v)->counter);
9225 +}
9226 +
9227 +/**
9228 + * atomic_read_unchecked - read atomic variable
9229 + * @v: pointer of type atomic_unchecked_t
9230 + *
9231 + * Atomically reads the value of @v.
9232 + */
9233 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9234 +{
9235 + return (*(volatile const int *)&(v)->counter);
9236 }
9237
9238 /**
9239 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9240 }
9241
9242 /**
9243 + * atomic_set_unchecked - set atomic variable
9244 + * @v: pointer of type atomic_unchecked_t
9245 + * @i: required value
9246 + *
9247 + * Atomically sets the value of @v to @i.
9248 + */
9249 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9250 +{
9251 + v->counter = i;
9252 +}
9253 +
9254 +/**
9255 * atomic_add - add integer to atomic variable
9256 * @i: integer value to add
9257 * @v: pointer of type atomic_t
9258 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9259 */
9260 static inline void atomic_add(int i, atomic_t *v)
9261 {
9262 - asm volatile(LOCK_PREFIX "addl %1,%0"
9263 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9264 +
9265 +#ifdef CONFIG_PAX_REFCOUNT
9266 + "jno 0f\n"
9267 + LOCK_PREFIX "subl %1,%0\n"
9268 + "int $4\n0:\n"
9269 + _ASM_EXTABLE(0b, 0b)
9270 +#endif
9271 +
9272 + : "+m" (v->counter)
9273 + : "ir" (i));
9274 +}
9275 +
9276 +/**
9277 + * atomic_add_unchecked - add integer to atomic variable
9278 + * @i: integer value to add
9279 + * @v: pointer of type atomic_unchecked_t
9280 + *
9281 + * Atomically adds @i to @v.
9282 + */
9283 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9284 +{
9285 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9286 : "+m" (v->counter)
9287 : "ir" (i));
9288 }
9289 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9290 */
9291 static inline void atomic_sub(int i, atomic_t *v)
9292 {
9293 - asm volatile(LOCK_PREFIX "subl %1,%0"
9294 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9295 +
9296 +#ifdef CONFIG_PAX_REFCOUNT
9297 + "jno 0f\n"
9298 + LOCK_PREFIX "addl %1,%0\n"
9299 + "int $4\n0:\n"
9300 + _ASM_EXTABLE(0b, 0b)
9301 +#endif
9302 +
9303 + : "+m" (v->counter)
9304 + : "ir" (i));
9305 +}
9306 +
9307 +/**
9308 + * atomic_sub_unchecked - subtract integer from atomic variable
9309 + * @i: integer value to subtract
9310 + * @v: pointer of type atomic_unchecked_t
9311 + *
9312 + * Atomically subtracts @i from @v.
9313 + */
9314 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9315 +{
9316 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9317 : "+m" (v->counter)
9318 : "ir" (i));
9319 }
9320 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9321 {
9322 unsigned char c;
9323
9324 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9325 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9326 +
9327 +#ifdef CONFIG_PAX_REFCOUNT
9328 + "jno 0f\n"
9329 + LOCK_PREFIX "addl %2,%0\n"
9330 + "int $4\n0:\n"
9331 + _ASM_EXTABLE(0b, 0b)
9332 +#endif
9333 +
9334 + "sete %1\n"
9335 : "+m" (v->counter), "=qm" (c)
9336 : "ir" (i) : "memory");
9337 return c;
9338 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9339 */
9340 static inline void atomic_inc(atomic_t *v)
9341 {
9342 - asm volatile(LOCK_PREFIX "incl %0"
9343 + asm volatile(LOCK_PREFIX "incl %0\n"
9344 +
9345 +#ifdef CONFIG_PAX_REFCOUNT
9346 + "jno 0f\n"
9347 + LOCK_PREFIX "decl %0\n"
9348 + "int $4\n0:\n"
9349 + _ASM_EXTABLE(0b, 0b)
9350 +#endif
9351 +
9352 + : "+m" (v->counter));
9353 +}
9354 +
9355 +/**
9356 + * atomic_inc_unchecked - increment atomic variable
9357 + * @v: pointer of type atomic_unchecked_t
9358 + *
9359 + * Atomically increments @v by 1.
9360 + */
9361 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9362 +{
9363 + asm volatile(LOCK_PREFIX "incl %0\n"
9364 : "+m" (v->counter));
9365 }
9366
9367 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9368 */
9369 static inline void atomic_dec(atomic_t *v)
9370 {
9371 - asm volatile(LOCK_PREFIX "decl %0"
9372 + asm volatile(LOCK_PREFIX "decl %0\n"
9373 +
9374 +#ifdef CONFIG_PAX_REFCOUNT
9375 + "jno 0f\n"
9376 + LOCK_PREFIX "incl %0\n"
9377 + "int $4\n0:\n"
9378 + _ASM_EXTABLE(0b, 0b)
9379 +#endif
9380 +
9381 + : "+m" (v->counter));
9382 +}
9383 +
9384 +/**
9385 + * atomic_dec_unchecked - decrement atomic variable
9386 + * @v: pointer of type atomic_unchecked_t
9387 + *
9388 + * Atomically decrements @v by 1.
9389 + */
9390 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9391 +{
9392 + asm volatile(LOCK_PREFIX "decl %0\n"
9393 : "+m" (v->counter));
9394 }
9395
9396 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9397 {
9398 unsigned char c;
9399
9400 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9401 + asm volatile(LOCK_PREFIX "decl %0\n"
9402 +
9403 +#ifdef CONFIG_PAX_REFCOUNT
9404 + "jno 0f\n"
9405 + LOCK_PREFIX "incl %0\n"
9406 + "int $4\n0:\n"
9407 + _ASM_EXTABLE(0b, 0b)
9408 +#endif
9409 +
9410 + "sete %1\n"
9411 : "+m" (v->counter), "=qm" (c)
9412 : : "memory");
9413 return c != 0;
9414 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9415 {
9416 unsigned char c;
9417
9418 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9419 + asm volatile(LOCK_PREFIX "incl %0\n"
9420 +
9421 +#ifdef CONFIG_PAX_REFCOUNT
9422 + "jno 0f\n"
9423 + LOCK_PREFIX "decl %0\n"
9424 + "int $4\n0:\n"
9425 + _ASM_EXTABLE(0b, 0b)
9426 +#endif
9427 +
9428 + "sete %1\n"
9429 + : "+m" (v->counter), "=qm" (c)
9430 + : : "memory");
9431 + return c != 0;
9432 +}
9433 +
9434 +/**
9435 + * atomic_inc_and_test_unchecked - increment and test
9436 + * @v: pointer of type atomic_unchecked_t
9437 + *
9438 + * Atomically increments @v by 1
9439 + * and returns true if the result is zero, or false for all
9440 + * other cases.
9441 + */
9442 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9443 +{
9444 + unsigned char c;
9445 +
9446 + asm volatile(LOCK_PREFIX "incl %0\n"
9447 + "sete %1\n"
9448 : "+m" (v->counter), "=qm" (c)
9449 : : "memory");
9450 return c != 0;
9451 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9452 {
9453 unsigned char c;
9454
9455 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9456 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9457 +
9458 +#ifdef CONFIG_PAX_REFCOUNT
9459 + "jno 0f\n"
9460 + LOCK_PREFIX "subl %2,%0\n"
9461 + "int $4\n0:\n"
9462 + _ASM_EXTABLE(0b, 0b)
9463 +#endif
9464 +
9465 + "sets %1\n"
9466 : "+m" (v->counter), "=qm" (c)
9467 : "ir" (i) : "memory");
9468 return c;
9469 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9470 goto no_xadd;
9471 #endif
9472 /* Modern 486+ processor */
9473 - return i + xadd(&v->counter, i);
9474 + return i + xadd_check_overflow(&v->counter, i);
9475
9476 #ifdef CONFIG_M386
9477 no_xadd: /* Legacy 386 processor */
9478 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9479 }
9480
9481 /**
9482 + * atomic_add_return_unchecked - add integer and return
9483 + * @i: integer value to add
9484 + * @v: pointer of type atomic_unchecked_t
9485 + *
9486 + * Atomically adds @i to @v and returns @i + @v
9487 + */
9488 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9489 +{
9490 +#ifdef CONFIG_M386
9491 + int __i;
9492 + unsigned long flags;
9493 + if (unlikely(boot_cpu_data.x86 <= 3))
9494 + goto no_xadd;
9495 +#endif
9496 + /* Modern 486+ processor */
9497 + return i + xadd(&v->counter, i);
9498 +
9499 +#ifdef CONFIG_M386
9500 +no_xadd: /* Legacy 386 processor */
9501 + raw_local_irq_save(flags);
9502 + __i = atomic_read_unchecked(v);
9503 + atomic_set_unchecked(v, i + __i);
9504 + raw_local_irq_restore(flags);
9505 + return i + __i;
9506 +#endif
9507 +}
9508 +
9509 +/**
9510 * atomic_sub_return - subtract integer and return
9511 * @v: pointer of type atomic_t
9512 * @i: integer value to subtract
9513 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9514 }
9515
9516 #define atomic_inc_return(v) (atomic_add_return(1, v))
9517 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9518 +{
9519 + return atomic_add_return_unchecked(1, v);
9520 +}
9521 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9522
9523 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9524 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9525 return cmpxchg(&v->counter, old, new);
9526 }
9527
9528 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9529 +{
9530 + return cmpxchg(&v->counter, old, new);
9531 +}
9532 +
9533 static inline int atomic_xchg(atomic_t *v, int new)
9534 {
9535 return xchg(&v->counter, new);
9536 }
9537
9538 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9539 +{
9540 + return xchg(&v->counter, new);
9541 +}
9542 +
9543 /**
9544 * __atomic_add_unless - add unless the number is already a given value
9545 * @v: pointer of type atomic_t
9546 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9547 */
9548 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9549 {
9550 - int c, old;
9551 + int c, old, new;
9552 c = atomic_read(v);
9553 for (;;) {
9554 - if (unlikely(c == (u)))
9555 + if (unlikely(c == u))
9556 break;
9557 - old = atomic_cmpxchg((v), c, c + (a));
9558 +
9559 + asm volatile("addl %2,%0\n"
9560 +
9561 +#ifdef CONFIG_PAX_REFCOUNT
9562 + "jno 0f\n"
9563 + "subl %2,%0\n"
9564 + "int $4\n0:\n"
9565 + _ASM_EXTABLE(0b, 0b)
9566 +#endif
9567 +
9568 + : "=r" (new)
9569 + : "0" (c), "ir" (a));
9570 +
9571 + old = atomic_cmpxchg(v, c, new);
9572 if (likely(old == c))
9573 break;
9574 c = old;
9575 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9576 return c;
9577 }
9578
9579 +/**
9580 + * atomic_inc_not_zero_hint - increment if not null
9581 + * @v: pointer of type atomic_t
9582 + * @hint: probable value of the atomic before the increment
9583 + *
9584 + * This version of atomic_inc_not_zero() gives a hint of probable
9585 + * value of the atomic. This helps processor to not read the memory
9586 + * before doing the atomic read/modify/write cycle, lowering
9587 + * number of bus transactions on some arches.
9588 + *
9589 + * Returns: 0 if increment was not done, 1 otherwise.
9590 + */
9591 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9592 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9593 +{
9594 + int val, c = hint, new;
9595 +
9596 + /* sanity test, should be removed by compiler if hint is a constant */
9597 + if (!hint)
9598 + return __atomic_add_unless(v, 1, 0);
9599 +
9600 + do {
9601 + asm volatile("incl %0\n"
9602 +
9603 +#ifdef CONFIG_PAX_REFCOUNT
9604 + "jno 0f\n"
9605 + "decl %0\n"
9606 + "int $4\n0:\n"
9607 + _ASM_EXTABLE(0b, 0b)
9608 +#endif
9609 +
9610 + : "=r" (new)
9611 + : "0" (c));
9612 +
9613 + val = atomic_cmpxchg(v, c, new);
9614 + if (val == c)
9615 + return 1;
9616 + c = val;
9617 + } while (c);
9618 +
9619 + return 0;
9620 +}
9621
9622 /*
9623 * atomic_dec_if_positive - decrement by 1 if old value positive
9624 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9625 index fa13f0e..27c2e08 100644
9626 --- a/arch/x86/include/asm/atomic64_32.h
9627 +++ b/arch/x86/include/asm/atomic64_32.h
9628 @@ -12,6 +12,14 @@ typedef struct {
9629 u64 __aligned(8) counter;
9630 } atomic64_t;
9631
9632 +#ifdef CONFIG_PAX_REFCOUNT
9633 +typedef struct {
9634 + u64 __aligned(8) counter;
9635 +} atomic64_unchecked_t;
9636 +#else
9637 +typedef atomic64_t atomic64_unchecked_t;
9638 +#endif
9639 +
9640 #define ATOMIC64_INIT(val) { (val) }
9641
9642 #ifdef CONFIG_X86_CMPXCHG64
9643 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9644 }
9645
9646 /**
9647 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9648 + * @p: pointer to type atomic64_unchecked_t
9649 + * @o: expected value
9650 + * @n: new value
9651 + *
9652 + * Atomically sets @v to @n if it was equal to @o and returns
9653 + * the old value.
9654 + */
9655 +
9656 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9657 +{
9658 + return cmpxchg64(&v->counter, o, n);
9659 +}
9660 +
9661 +/**
9662 * atomic64_xchg - xchg atomic64 variable
9663 * @v: pointer to type atomic64_t
9664 * @n: value to assign
9665 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9666 }
9667
9668 /**
9669 + * atomic64_set_unchecked - set atomic64 variable
9670 + * @v: pointer to type atomic64_unchecked_t
9671 + * @n: value to assign
9672 + *
9673 + * Atomically sets the value of @v to @n.
9674 + */
9675 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9676 +{
9677 + unsigned high = (unsigned)(i >> 32);
9678 + unsigned low = (unsigned)i;
9679 + asm volatile(ATOMIC64_ALTERNATIVE(set)
9680 + : "+b" (low), "+c" (high)
9681 + : "S" (v)
9682 + : "eax", "edx", "memory"
9683 + );
9684 +}
9685 +
9686 +/**
9687 * atomic64_read - read atomic64 variable
9688 * @v: pointer to type atomic64_t
9689 *
9690 @@ -93,6 +134,22 @@ static inline long long atomic64_read(const atomic64_t *v)
9691 }
9692
9693 /**
9694 + * atomic64_read_unchecked - read atomic64 variable
9695 + * @v: pointer to type atomic64_unchecked_t
9696 + *
9697 + * Atomically reads the value of @v and returns it.
9698 + */
9699 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9700 +{
9701 + long long r;
9702 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
9703 + : "=A" (r), "+c" (v)
9704 + : : "memory"
9705 + );
9706 + return r;
9707 + }
9708 +
9709 +/**
9710 * atomic64_add_return - add and return
9711 * @i: integer value to add
9712 * @v: pointer to type atomic64_t
9713 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9714 return i;
9715 }
9716
9717 +/**
9718 + * atomic64_add_return_unchecked - add and return
9719 + * @i: integer value to add
9720 + * @v: pointer to type atomic64_unchecked_t
9721 + *
9722 + * Atomically adds @i to @v and returns @i + *@v
9723 + */
9724 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9725 +{
9726 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
9727 + : "+A" (i), "+c" (v)
9728 + : : "memory"
9729 + );
9730 + return i;
9731 +}
9732 +
9733 /*
9734 * Other variants with different arithmetic operators:
9735 */
9736 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9737 return a;
9738 }
9739
9740 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9741 +{
9742 + long long a;
9743 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
9744 + : "=A" (a)
9745 + : "S" (v)
9746 + : "memory", "ecx"
9747 + );
9748 + return a;
9749 +}
9750 +
9751 static inline long long atomic64_dec_return(atomic64_t *v)
9752 {
9753 long long a;
9754 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9755 }
9756
9757 /**
9758 + * atomic64_add_unchecked - add integer to atomic64 variable
9759 + * @i: integer value to add
9760 + * @v: pointer to type atomic64_unchecked_t
9761 + *
9762 + * Atomically adds @i to @v.
9763 + */
9764 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9765 +{
9766 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
9767 + : "+A" (i), "+c" (v)
9768 + : : "memory"
9769 + );
9770 + return i;
9771 +}
9772 +
9773 +/**
9774 * atomic64_sub - subtract the atomic64 variable
9775 * @i: integer value to subtract
9776 * @v: pointer to type atomic64_t
9777 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9778 index 0e1cbfc..5623683 100644
9779 --- a/arch/x86/include/asm/atomic64_64.h
9780 +++ b/arch/x86/include/asm/atomic64_64.h
9781 @@ -18,7 +18,19 @@
9782 */
9783 static inline long atomic64_read(const atomic64_t *v)
9784 {
9785 - return (*(volatile long *)&(v)->counter);
9786 + return (*(volatile const long *)&(v)->counter);
9787 +}
9788 +
9789 +/**
9790 + * atomic64_read_unchecked - read atomic64 variable
9791 + * @v: pointer of type atomic64_unchecked_t
9792 + *
9793 + * Atomically reads the value of @v.
9794 + * Doesn't imply a read memory barrier.
9795 + */
9796 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9797 +{
9798 + return (*(volatile const long *)&(v)->counter);
9799 }
9800
9801 /**
9802 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9803 }
9804
9805 /**
9806 + * atomic64_set_unchecked - set atomic64 variable
9807 + * @v: pointer to type atomic64_unchecked_t
9808 + * @i: required value
9809 + *
9810 + * Atomically sets the value of @v to @i.
9811 + */
9812 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9813 +{
9814 + v->counter = i;
9815 +}
9816 +
9817 +/**
9818 * atomic64_add - add integer to atomic64 variable
9819 * @i: integer value to add
9820 * @v: pointer to type atomic64_t
9821 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9822 */
9823 static inline void atomic64_add(long i, atomic64_t *v)
9824 {
9825 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9826 +
9827 +#ifdef CONFIG_PAX_REFCOUNT
9828 + "jno 0f\n"
9829 + LOCK_PREFIX "subq %1,%0\n"
9830 + "int $4\n0:\n"
9831 + _ASM_EXTABLE(0b, 0b)
9832 +#endif
9833 +
9834 + : "=m" (v->counter)
9835 + : "er" (i), "m" (v->counter));
9836 +}
9837 +
9838 +/**
9839 + * atomic64_add_unchecked - add integer to atomic64 variable
9840 + * @i: integer value to add
9841 + * @v: pointer to type atomic64_unchecked_t
9842 + *
9843 + * Atomically adds @i to @v.
9844 + */
9845 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9846 +{
9847 asm volatile(LOCK_PREFIX "addq %1,%0"
9848 : "=m" (v->counter)
9849 : "er" (i), "m" (v->counter));
9850 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9851 */
9852 static inline void atomic64_sub(long i, atomic64_t *v)
9853 {
9854 - asm volatile(LOCK_PREFIX "subq %1,%0"
9855 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9856 +
9857 +#ifdef CONFIG_PAX_REFCOUNT
9858 + "jno 0f\n"
9859 + LOCK_PREFIX "addq %1,%0\n"
9860 + "int $4\n0:\n"
9861 + _ASM_EXTABLE(0b, 0b)
9862 +#endif
9863 +
9864 + : "=m" (v->counter)
9865 + : "er" (i), "m" (v->counter));
9866 +}
9867 +
9868 +/**
9869 + * atomic64_sub_unchecked - subtract the atomic64 variable
9870 + * @i: integer value to subtract
9871 + * @v: pointer to type atomic64_unchecked_t
9872 + *
9873 + * Atomically subtracts @i from @v.
9874 + */
9875 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9876 +{
9877 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9878 : "=m" (v->counter)
9879 : "er" (i), "m" (v->counter));
9880 }
9881 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9882 {
9883 unsigned char c;
9884
9885 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9886 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9887 +
9888 +#ifdef CONFIG_PAX_REFCOUNT
9889 + "jno 0f\n"
9890 + LOCK_PREFIX "addq %2,%0\n"
9891 + "int $4\n0:\n"
9892 + _ASM_EXTABLE(0b, 0b)
9893 +#endif
9894 +
9895 + "sete %1\n"
9896 : "=m" (v->counter), "=qm" (c)
9897 : "er" (i), "m" (v->counter) : "memory");
9898 return c;
9899 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9900 */
9901 static inline void atomic64_inc(atomic64_t *v)
9902 {
9903 + asm volatile(LOCK_PREFIX "incq %0\n"
9904 +
9905 +#ifdef CONFIG_PAX_REFCOUNT
9906 + "jno 0f\n"
9907 + LOCK_PREFIX "decq %0\n"
9908 + "int $4\n0:\n"
9909 + _ASM_EXTABLE(0b, 0b)
9910 +#endif
9911 +
9912 + : "=m" (v->counter)
9913 + : "m" (v->counter));
9914 +}
9915 +
9916 +/**
9917 + * atomic64_inc_unchecked - increment atomic64 variable
9918 + * @v: pointer to type atomic64_unchecked_t
9919 + *
9920 + * Atomically increments @v by 1.
9921 + */
9922 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9923 +{
9924 asm volatile(LOCK_PREFIX "incq %0"
9925 : "=m" (v->counter)
9926 : "m" (v->counter));
9927 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9928 */
9929 static inline void atomic64_dec(atomic64_t *v)
9930 {
9931 - asm volatile(LOCK_PREFIX "decq %0"
9932 + asm volatile(LOCK_PREFIX "decq %0\n"
9933 +
9934 +#ifdef CONFIG_PAX_REFCOUNT
9935 + "jno 0f\n"
9936 + LOCK_PREFIX "incq %0\n"
9937 + "int $4\n0:\n"
9938 + _ASM_EXTABLE(0b, 0b)
9939 +#endif
9940 +
9941 + : "=m" (v->counter)
9942 + : "m" (v->counter));
9943 +}
9944 +
9945 +/**
9946 + * atomic64_dec_unchecked - decrement atomic64 variable
9947 + * @v: pointer to type atomic64_t
9948 + *
9949 + * Atomically decrements @v by 1.
9950 + */
9951 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9952 +{
9953 + asm volatile(LOCK_PREFIX "decq %0\n"
9954 : "=m" (v->counter)
9955 : "m" (v->counter));
9956 }
9957 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9958 {
9959 unsigned char c;
9960
9961 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9962 + asm volatile(LOCK_PREFIX "decq %0\n"
9963 +
9964 +#ifdef CONFIG_PAX_REFCOUNT
9965 + "jno 0f\n"
9966 + LOCK_PREFIX "incq %0\n"
9967 + "int $4\n0:\n"
9968 + _ASM_EXTABLE(0b, 0b)
9969 +#endif
9970 +
9971 + "sete %1\n"
9972 : "=m" (v->counter), "=qm" (c)
9973 : "m" (v->counter) : "memory");
9974 return c != 0;
9975 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9976 {
9977 unsigned char c;
9978
9979 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9980 + asm volatile(LOCK_PREFIX "incq %0\n"
9981 +
9982 +#ifdef CONFIG_PAX_REFCOUNT
9983 + "jno 0f\n"
9984 + LOCK_PREFIX "decq %0\n"
9985 + "int $4\n0:\n"
9986 + _ASM_EXTABLE(0b, 0b)
9987 +#endif
9988 +
9989 + "sete %1\n"
9990 : "=m" (v->counter), "=qm" (c)
9991 : "m" (v->counter) : "memory");
9992 return c != 0;
9993 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9994 {
9995 unsigned char c;
9996
9997 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9998 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9999 +
10000 +#ifdef CONFIG_PAX_REFCOUNT
10001 + "jno 0f\n"
10002 + LOCK_PREFIX "subq %2,%0\n"
10003 + "int $4\n0:\n"
10004 + _ASM_EXTABLE(0b, 0b)
10005 +#endif
10006 +
10007 + "sets %1\n"
10008 : "=m" (v->counter), "=qm" (c)
10009 : "er" (i), "m" (v->counter) : "memory");
10010 return c;
10011 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10012 */
10013 static inline long atomic64_add_return(long i, atomic64_t *v)
10014 {
10015 + return i + xadd_check_overflow(&v->counter, i);
10016 +}
10017 +
10018 +/**
10019 + * atomic64_add_return_unchecked - add and return
10020 + * @i: integer value to add
10021 + * @v: pointer to type atomic64_unchecked_t
10022 + *
10023 + * Atomically adds @i to @v and returns @i + @v
10024 + */
10025 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10026 +{
10027 return i + xadd(&v->counter, i);
10028 }
10029
10030 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10031 }
10032
10033 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10034 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10035 +{
10036 + return atomic64_add_return_unchecked(1, v);
10037 +}
10038 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10039
10040 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10041 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10042 return cmpxchg(&v->counter, old, new);
10043 }
10044
10045 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10046 +{
10047 + return cmpxchg(&v->counter, old, new);
10048 +}
10049 +
10050 static inline long atomic64_xchg(atomic64_t *v, long new)
10051 {
10052 return xchg(&v->counter, new);
10053 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10054 */
10055 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10056 {
10057 - long c, old;
10058 + long c, old, new;
10059 c = atomic64_read(v);
10060 for (;;) {
10061 - if (unlikely(c == (u)))
10062 + if (unlikely(c == u))
10063 break;
10064 - old = atomic64_cmpxchg((v), c, c + (a));
10065 +
10066 + asm volatile("add %2,%0\n"
10067 +
10068 +#ifdef CONFIG_PAX_REFCOUNT
10069 + "jno 0f\n"
10070 + "sub %2,%0\n"
10071 + "int $4\n0:\n"
10072 + _ASM_EXTABLE(0b, 0b)
10073 +#endif
10074 +
10075 + : "=r" (new)
10076 + : "0" (c), "ir" (a));
10077 +
10078 + old = atomic64_cmpxchg(v, c, new);
10079 if (likely(old == c))
10080 break;
10081 c = old;
10082 }
10083 - return c != (u);
10084 + return c != u;
10085 }
10086
10087 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10088 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10089 index b97596e..9bd48b06 100644
10090 --- a/arch/x86/include/asm/bitops.h
10091 +++ b/arch/x86/include/asm/bitops.h
10092 @@ -38,7 +38,7 @@
10093 * a mask operation on a byte.
10094 */
10095 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10096 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10097 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10098 #define CONST_MASK(nr) (1 << ((nr) & 7))
10099
10100 /**
10101 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10102 index 5e1a2ee..c9f9533 100644
10103 --- a/arch/x86/include/asm/boot.h
10104 +++ b/arch/x86/include/asm/boot.h
10105 @@ -11,10 +11,15 @@
10106 #include <asm/pgtable_types.h>
10107
10108 /* Physical address where kernel should be loaded. */
10109 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10110 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10111 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10112 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10113
10114 +#ifndef __ASSEMBLY__
10115 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10116 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10117 +#endif
10118 +
10119 /* Minimum kernel alignment, as a power of two */
10120 #ifdef CONFIG_X86_64
10121 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10122 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10123 index 48f99f1..d78ebf9 100644
10124 --- a/arch/x86/include/asm/cache.h
10125 +++ b/arch/x86/include/asm/cache.h
10126 @@ -5,12 +5,13 @@
10127
10128 /* L1 cache line size */
10129 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10130 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10131 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10132
10133 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10134 +#define __read_only __attribute__((__section__(".data..read_only")))
10135
10136 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10137 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10138 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10139
10140 #ifdef CONFIG_X86_VSMP
10141 #ifdef CONFIG_SMP
10142 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10143 index 4e12668..501d239 100644
10144 --- a/arch/x86/include/asm/cacheflush.h
10145 +++ b/arch/x86/include/asm/cacheflush.h
10146 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10147 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10148
10149 if (pg_flags == _PGMT_DEFAULT)
10150 - return -1;
10151 + return ~0UL;
10152 else if (pg_flags == _PGMT_WC)
10153 return _PAGE_CACHE_WC;
10154 else if (pg_flags == _PGMT_UC_MINUS)
10155 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10156 index 46fc474..b02b0f9 100644
10157 --- a/arch/x86/include/asm/checksum_32.h
10158 +++ b/arch/x86/include/asm/checksum_32.h
10159 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10160 int len, __wsum sum,
10161 int *src_err_ptr, int *dst_err_ptr);
10162
10163 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10164 + int len, __wsum sum,
10165 + int *src_err_ptr, int *dst_err_ptr);
10166 +
10167 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10168 + int len, __wsum sum,
10169 + int *src_err_ptr, int *dst_err_ptr);
10170 +
10171 /*
10172 * Note: when you get a NULL pointer exception here this means someone
10173 * passed in an incorrect kernel address to one of these functions.
10174 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10175 int *err_ptr)
10176 {
10177 might_sleep();
10178 - return csum_partial_copy_generic((__force void *)src, dst,
10179 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10180 len, sum, err_ptr, NULL);
10181 }
10182
10183 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10184 {
10185 might_sleep();
10186 if (access_ok(VERIFY_WRITE, dst, len))
10187 - return csum_partial_copy_generic(src, (__force void *)dst,
10188 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10189 len, sum, NULL, err_ptr);
10190
10191 if (len)
10192 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10193 index 99480e5..d81165b 100644
10194 --- a/arch/x86/include/asm/cmpxchg.h
10195 +++ b/arch/x86/include/asm/cmpxchg.h
10196 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10197 __compiletime_error("Bad argument size for cmpxchg");
10198 extern void __xadd_wrong_size(void)
10199 __compiletime_error("Bad argument size for xadd");
10200 +extern void __xadd_check_overflow_wrong_size(void)
10201 + __compiletime_error("Bad argument size for xadd_check_overflow");
10202 extern void __add_wrong_size(void)
10203 __compiletime_error("Bad argument size for add");
10204 +extern void __add_check_overflow_wrong_size(void)
10205 + __compiletime_error("Bad argument size for add_check_overflow");
10206
10207 /*
10208 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10209 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10210 __ret; \
10211 })
10212
10213 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10214 + ({ \
10215 + __typeof__ (*(ptr)) __ret = (arg); \
10216 + switch (sizeof(*(ptr))) { \
10217 + case __X86_CASE_L: \
10218 + asm volatile (lock #op "l %0, %1\n" \
10219 + "jno 0f\n" \
10220 + "mov %0,%1\n" \
10221 + "int $4\n0:\n" \
10222 + _ASM_EXTABLE(0b, 0b) \
10223 + : "+r" (__ret), "+m" (*(ptr)) \
10224 + : : "memory", "cc"); \
10225 + break; \
10226 + case __X86_CASE_Q: \
10227 + asm volatile (lock #op "q %q0, %1\n" \
10228 + "jno 0f\n" \
10229 + "mov %0,%1\n" \
10230 + "int $4\n0:\n" \
10231 + _ASM_EXTABLE(0b, 0b) \
10232 + : "+r" (__ret), "+m" (*(ptr)) \
10233 + : : "memory", "cc"); \
10234 + break; \
10235 + default: \
10236 + __ ## op ## _check_overflow_wrong_size(); \
10237 + } \
10238 + __ret; \
10239 + })
10240 +
10241 /*
10242 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10243 * Since this is generally used to protect other memory information, we
10244 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10245 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10246 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10247
10248 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10249 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10250 +
10251 #define __add(ptr, inc, lock) \
10252 ({ \
10253 __typeof__ (*(ptr)) __ret = (inc); \
10254 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10255 index 8d67d42..183d0eb 100644
10256 --- a/arch/x86/include/asm/cpufeature.h
10257 +++ b/arch/x86/include/asm/cpufeature.h
10258 @@ -367,7 +367,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10259 ".section .discard,\"aw\",@progbits\n"
10260 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10261 ".previous\n"
10262 - ".section .altinstr_replacement,\"ax\"\n"
10263 + ".section .altinstr_replacement,\"a\"\n"
10264 "3: movb $1,%0\n"
10265 "4:\n"
10266 ".previous\n"
10267 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10268 index e95822d..a90010e 100644
10269 --- a/arch/x86/include/asm/desc.h
10270 +++ b/arch/x86/include/asm/desc.h
10271 @@ -4,6 +4,7 @@
10272 #include <asm/desc_defs.h>
10273 #include <asm/ldt.h>
10274 #include <asm/mmu.h>
10275 +#include <asm/pgtable.h>
10276
10277 #include <linux/smp.h>
10278
10279 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10280
10281 desc->type = (info->read_exec_only ^ 1) << 1;
10282 desc->type |= info->contents << 2;
10283 + desc->type |= info->seg_not_present ^ 1;
10284
10285 desc->s = 1;
10286 desc->dpl = 0x3;
10287 @@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10288 }
10289
10290 extern struct desc_ptr idt_descr;
10291 -extern gate_desc idt_table[];
10292 extern struct desc_ptr nmi_idt_descr;
10293 -extern gate_desc nmi_idt_table[];
10294 -
10295 -struct gdt_page {
10296 - struct desc_struct gdt[GDT_ENTRIES];
10297 -} __attribute__((aligned(PAGE_SIZE)));
10298 -
10299 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10300 +extern gate_desc idt_table[256];
10301 +extern gate_desc nmi_idt_table[256];
10302
10303 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10304 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10305 {
10306 - return per_cpu(gdt_page, cpu).gdt;
10307 + return cpu_gdt_table[cpu];
10308 }
10309
10310 #ifdef CONFIG_X86_64
10311 @@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10312 unsigned long base, unsigned dpl, unsigned flags,
10313 unsigned short seg)
10314 {
10315 - gate->a = (seg << 16) | (base & 0xffff);
10316 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10317 + gate->gate.offset_low = base;
10318 + gate->gate.seg = seg;
10319 + gate->gate.reserved = 0;
10320 + gate->gate.type = type;
10321 + gate->gate.s = 0;
10322 + gate->gate.dpl = dpl;
10323 + gate->gate.p = 1;
10324 + gate->gate.offset_high = base >> 16;
10325 }
10326
10327 #endif
10328 @@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10329
10330 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10331 {
10332 + pax_open_kernel();
10333 memcpy(&idt[entry], gate, sizeof(*gate));
10334 + pax_close_kernel();
10335 }
10336
10337 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10338 {
10339 + pax_open_kernel();
10340 memcpy(&ldt[entry], desc, 8);
10341 + pax_close_kernel();
10342 }
10343
10344 static inline void
10345 @@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10346 default: size = sizeof(*gdt); break;
10347 }
10348
10349 + pax_open_kernel();
10350 memcpy(&gdt[entry], desc, size);
10351 + pax_close_kernel();
10352 }
10353
10354 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10355 @@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10356
10357 static inline void native_load_tr_desc(void)
10358 {
10359 + pax_open_kernel();
10360 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10361 + pax_close_kernel();
10362 }
10363
10364 static inline void native_load_gdt(const struct desc_ptr *dtr)
10365 @@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10366 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10367 unsigned int i;
10368
10369 + pax_open_kernel();
10370 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10371 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10372 + pax_close_kernel();
10373 }
10374
10375 #define _LDT_empty(info) \
10376 @@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10377 }
10378
10379 #ifdef CONFIG_X86_64
10380 -static inline void set_nmi_gate(int gate, void *addr)
10381 +static inline void set_nmi_gate(int gate, const void *addr)
10382 {
10383 gate_desc s;
10384
10385 @@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10386 }
10387 #endif
10388
10389 -static inline void _set_gate(int gate, unsigned type, void *addr,
10390 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10391 unsigned dpl, unsigned ist, unsigned seg)
10392 {
10393 gate_desc s;
10394 @@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10395 * Pentium F0 0F bugfix can have resulted in the mapped
10396 * IDT being write-protected.
10397 */
10398 -static inline void set_intr_gate(unsigned int n, void *addr)
10399 +static inline void set_intr_gate(unsigned int n, const void *addr)
10400 {
10401 BUG_ON((unsigned)n > 0xFF);
10402 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10403 @@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10404 /*
10405 * This routine sets up an interrupt gate at directory privilege level 3.
10406 */
10407 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10408 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10409 {
10410 BUG_ON((unsigned)n > 0xFF);
10411 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10412 }
10413
10414 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10415 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10416 {
10417 BUG_ON((unsigned)n > 0xFF);
10418 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10419 }
10420
10421 -static inline void set_trap_gate(unsigned int n, void *addr)
10422 +static inline void set_trap_gate(unsigned int n, const void *addr)
10423 {
10424 BUG_ON((unsigned)n > 0xFF);
10425 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10426 @@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10427 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10428 {
10429 BUG_ON((unsigned)n > 0xFF);
10430 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10431 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10432 }
10433
10434 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10435 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10436 {
10437 BUG_ON((unsigned)n > 0xFF);
10438 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10439 }
10440
10441 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10442 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10443 {
10444 BUG_ON((unsigned)n > 0xFF);
10445 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10446 }
10447
10448 +#ifdef CONFIG_X86_32
10449 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10450 +{
10451 + struct desc_struct d;
10452 +
10453 + if (likely(limit))
10454 + limit = (limit - 1UL) >> PAGE_SHIFT;
10455 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10456 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10457 +}
10458 +#endif
10459 +
10460 #endif /* _ASM_X86_DESC_H */
10461 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10462 index 278441f..b95a174 100644
10463 --- a/arch/x86/include/asm/desc_defs.h
10464 +++ b/arch/x86/include/asm/desc_defs.h
10465 @@ -31,6 +31,12 @@ struct desc_struct {
10466 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10467 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10468 };
10469 + struct {
10470 + u16 offset_low;
10471 + u16 seg;
10472 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10473 + unsigned offset_high: 16;
10474 + } gate;
10475 };
10476 } __attribute__((packed));
10477
10478 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10479 index 3778256..c5d4fce 100644
10480 --- a/arch/x86/include/asm/e820.h
10481 +++ b/arch/x86/include/asm/e820.h
10482 @@ -69,7 +69,7 @@ struct e820map {
10483 #define ISA_START_ADDRESS 0xa0000
10484 #define ISA_END_ADDRESS 0x100000
10485
10486 -#define BIOS_BEGIN 0x000a0000
10487 +#define BIOS_BEGIN 0x000c0000
10488 #define BIOS_END 0x00100000
10489
10490 #define BIOS_ROM_BASE 0xffe00000
10491 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10492 index 5f962df..7289f09 100644
10493 --- a/arch/x86/include/asm/elf.h
10494 +++ b/arch/x86/include/asm/elf.h
10495 @@ -238,7 +238,25 @@ extern int force_personality32;
10496 the loader. We need to make sure that it is out of the way of the program
10497 that it will "exec", and that there is sufficient room for the brk. */
10498
10499 +#ifdef CONFIG_PAX_SEGMEXEC
10500 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10501 +#else
10502 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10503 +#endif
10504 +
10505 +#ifdef CONFIG_PAX_ASLR
10506 +#ifdef CONFIG_X86_32
10507 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10508 +
10509 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10510 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10511 +#else
10512 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10513 +
10514 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10515 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10516 +#endif
10517 +#endif
10518
10519 /* This yields a mask that user programs can use to figure out what
10520 instruction set this CPU supports. This could be done in user space,
10521 @@ -291,9 +309,7 @@ do { \
10522
10523 #define ARCH_DLINFO \
10524 do { \
10525 - if (vdso_enabled) \
10526 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10527 - (unsigned long)current->mm->context.vdso); \
10528 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10529 } while (0)
10530
10531 #define AT_SYSINFO 32
10532 @@ -304,7 +320,7 @@ do { \
10533
10534 #endif /* !CONFIG_X86_32 */
10535
10536 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10537 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10538
10539 #define VDSO_ENTRY \
10540 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10541 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
10542 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10543 #define compat_arch_setup_additional_pages syscall32_setup_pages
10544
10545 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10546 -#define arch_randomize_brk arch_randomize_brk
10547 -
10548 /*
10549 * True on X86_32 or when emulating IA32 on X86_64
10550 */
10551 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10552 index cc70c1c..d96d011 100644
10553 --- a/arch/x86/include/asm/emergency-restart.h
10554 +++ b/arch/x86/include/asm/emergency-restart.h
10555 @@ -15,6 +15,6 @@ enum reboot_type {
10556
10557 extern enum reboot_type reboot_type;
10558
10559 -extern void machine_emergency_restart(void);
10560 +extern void machine_emergency_restart(void) __noreturn;
10561
10562 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10563 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
10564 index dbe82a5..c6d8a00 100644
10565 --- a/arch/x86/include/asm/floppy.h
10566 +++ b/arch/x86/include/asm/floppy.h
10567 @@ -157,6 +157,7 @@ static unsigned long dma_mem_alloc(unsigned long size)
10568 }
10569
10570
10571 +static unsigned long vdma_mem_alloc(unsigned long size) __size_overflow(1);
10572 static unsigned long vdma_mem_alloc(unsigned long size)
10573 {
10574 return (unsigned long)vmalloc(size);
10575 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10576 index d09bb03..4ea4194 100644
10577 --- a/arch/x86/include/asm/futex.h
10578 +++ b/arch/x86/include/asm/futex.h
10579 @@ -12,16 +12,18 @@
10580 #include <asm/system.h>
10581
10582 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10583 + typecheck(u32 __user *, uaddr); \
10584 asm volatile("1:\t" insn "\n" \
10585 "2:\t.section .fixup,\"ax\"\n" \
10586 "3:\tmov\t%3, %1\n" \
10587 "\tjmp\t2b\n" \
10588 "\t.previous\n" \
10589 _ASM_EXTABLE(1b, 3b) \
10590 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10591 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10592 : "i" (-EFAULT), "0" (oparg), "1" (0))
10593
10594 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10595 + typecheck(u32 __user *, uaddr); \
10596 asm volatile("1:\tmovl %2, %0\n" \
10597 "\tmovl\t%0, %3\n" \
10598 "\t" insn "\n" \
10599 @@ -34,7 +36,7 @@
10600 _ASM_EXTABLE(1b, 4b) \
10601 _ASM_EXTABLE(2b, 4b) \
10602 : "=&a" (oldval), "=&r" (ret), \
10603 - "+m" (*uaddr), "=&r" (tem) \
10604 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10605 : "r" (oparg), "i" (-EFAULT), "1" (0))
10606
10607 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10608 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10609
10610 switch (op) {
10611 case FUTEX_OP_SET:
10612 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10613 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10614 break;
10615 case FUTEX_OP_ADD:
10616 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10617 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10618 uaddr, oparg);
10619 break;
10620 case FUTEX_OP_OR:
10621 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10622 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10623 return -EFAULT;
10624
10625 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10626 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10627 "2:\t.section .fixup, \"ax\"\n"
10628 "3:\tmov %3, %0\n"
10629 "\tjmp 2b\n"
10630 "\t.previous\n"
10631 _ASM_EXTABLE(1b, 3b)
10632 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10633 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10634 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10635 : "memory"
10636 );
10637 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10638 index eb92a6e..b98b2f4 100644
10639 --- a/arch/x86/include/asm/hw_irq.h
10640 +++ b/arch/x86/include/asm/hw_irq.h
10641 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10642 extern void enable_IO_APIC(void);
10643
10644 /* Statistics */
10645 -extern atomic_t irq_err_count;
10646 -extern atomic_t irq_mis_count;
10647 +extern atomic_unchecked_t irq_err_count;
10648 +extern atomic_unchecked_t irq_mis_count;
10649
10650 /* EISA */
10651 extern void eisa_set_level_irq(unsigned int irq);
10652 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10653 index 2479049..3fb9795 100644
10654 --- a/arch/x86/include/asm/i387.h
10655 +++ b/arch/x86/include/asm/i387.h
10656 @@ -93,6 +93,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10657 {
10658 int err;
10659
10660 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10661 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10662 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10663 +#endif
10664 +
10665 /* See comment in fxsave() below. */
10666 #ifdef CONFIG_AS_FXSAVEQ
10667 asm volatile("1: fxrstorq %[fx]\n\t"
10668 @@ -122,6 +127,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10669 {
10670 int err;
10671
10672 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10673 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10674 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10675 +#endif
10676 +
10677 /*
10678 * Clear the bytes not touched by the fxsave and reserved
10679 * for the SW usage.
10680 @@ -278,7 +288,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10681 "emms\n\t" /* clear stack tags */
10682 "fildl %P[addr]", /* set F?P to defined value */
10683 X86_FEATURE_FXSAVE_LEAK,
10684 - [addr] "m" (tsk->thread.fpu.has_fpu));
10685 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10686
10687 return fpu_restore_checking(&tsk->thread.fpu);
10688 }
10689 @@ -445,7 +455,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10690 static inline bool interrupted_user_mode(void)
10691 {
10692 struct pt_regs *regs = get_irq_regs();
10693 - return regs && user_mode_vm(regs);
10694 + return regs && user_mode(regs);
10695 }
10696
10697 /*
10698 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10699 index d8e8eef..99f81ae 100644
10700 --- a/arch/x86/include/asm/io.h
10701 +++ b/arch/x86/include/asm/io.h
10702 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10703
10704 #include <linux/vmalloc.h>
10705
10706 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10707 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10708 +{
10709 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10710 +}
10711 +
10712 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10713 +{
10714 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10715 +}
10716 +
10717 /*
10718 * Convert a virtual cached pointer to an uncached pointer
10719 */
10720 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10721 index bba3cf8..06bc8da 100644
10722 --- a/arch/x86/include/asm/irqflags.h
10723 +++ b/arch/x86/include/asm/irqflags.h
10724 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10725 sti; \
10726 sysexit
10727
10728 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10729 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10730 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10731 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10732 +
10733 #else
10734 #define INTERRUPT_RETURN iret
10735 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10736 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10737 index 5478825..839e88c 100644
10738 --- a/arch/x86/include/asm/kprobes.h
10739 +++ b/arch/x86/include/asm/kprobes.h
10740 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10741 #define RELATIVEJUMP_SIZE 5
10742 #define RELATIVECALL_OPCODE 0xe8
10743 #define RELATIVE_ADDR_SIZE 4
10744 -#define MAX_STACK_SIZE 64
10745 -#define MIN_STACK_SIZE(ADDR) \
10746 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10747 - THREAD_SIZE - (unsigned long)(ADDR))) \
10748 - ? (MAX_STACK_SIZE) \
10749 - : (((unsigned long)current_thread_info()) + \
10750 - THREAD_SIZE - (unsigned long)(ADDR)))
10751 +#define MAX_STACK_SIZE 64UL
10752 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10753
10754 #define flush_insn_slot(p) do { } while (0)
10755
10756 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10757 index 52d6640..136b3bd 100644
10758 --- a/arch/x86/include/asm/kvm_host.h
10759 +++ b/arch/x86/include/asm/kvm_host.h
10760 @@ -663,7 +663,7 @@ struct kvm_x86_ops {
10761 int (*check_intercept)(struct kvm_vcpu *vcpu,
10762 struct x86_instruction_info *info,
10763 enum x86_intercept_stage stage);
10764 -};
10765 +} __do_const;
10766
10767 struct kvm_arch_async_pf {
10768 u32 token;
10769 @@ -694,7 +694,7 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
10770 int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3);
10771
10772 int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
10773 - const void *val, int bytes);
10774 + const void *val, int bytes) __size_overflow(2);
10775 u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
10776
10777 extern bool tdp_enabled;
10778 @@ -781,7 +781,7 @@ int fx_init(struct kvm_vcpu *vcpu);
10779
10780 void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu);
10781 void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
10782 - const u8 *new, int bytes);
10783 + const u8 *new, int bytes) __size_overflow(2);
10784 int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn);
10785 int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
10786 void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
10787 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10788 index 9cdae5d..300d20f 100644
10789 --- a/arch/x86/include/asm/local.h
10790 +++ b/arch/x86/include/asm/local.h
10791 @@ -18,26 +18,58 @@ typedef struct {
10792
10793 static inline void local_inc(local_t *l)
10794 {
10795 - asm volatile(_ASM_INC "%0"
10796 + asm volatile(_ASM_INC "%0\n"
10797 +
10798 +#ifdef CONFIG_PAX_REFCOUNT
10799 + "jno 0f\n"
10800 + _ASM_DEC "%0\n"
10801 + "int $4\n0:\n"
10802 + _ASM_EXTABLE(0b, 0b)
10803 +#endif
10804 +
10805 : "+m" (l->a.counter));
10806 }
10807
10808 static inline void local_dec(local_t *l)
10809 {
10810 - asm volatile(_ASM_DEC "%0"
10811 + asm volatile(_ASM_DEC "%0\n"
10812 +
10813 +#ifdef CONFIG_PAX_REFCOUNT
10814 + "jno 0f\n"
10815 + _ASM_INC "%0\n"
10816 + "int $4\n0:\n"
10817 + _ASM_EXTABLE(0b, 0b)
10818 +#endif
10819 +
10820 : "+m" (l->a.counter));
10821 }
10822
10823 static inline void local_add(long i, local_t *l)
10824 {
10825 - asm volatile(_ASM_ADD "%1,%0"
10826 + asm volatile(_ASM_ADD "%1,%0\n"
10827 +
10828 +#ifdef CONFIG_PAX_REFCOUNT
10829 + "jno 0f\n"
10830 + _ASM_SUB "%1,%0\n"
10831 + "int $4\n0:\n"
10832 + _ASM_EXTABLE(0b, 0b)
10833 +#endif
10834 +
10835 : "+m" (l->a.counter)
10836 : "ir" (i));
10837 }
10838
10839 static inline void local_sub(long i, local_t *l)
10840 {
10841 - asm volatile(_ASM_SUB "%1,%0"
10842 + asm volatile(_ASM_SUB "%1,%0\n"
10843 +
10844 +#ifdef CONFIG_PAX_REFCOUNT
10845 + "jno 0f\n"
10846 + _ASM_ADD "%1,%0\n"
10847 + "int $4\n0:\n"
10848 + _ASM_EXTABLE(0b, 0b)
10849 +#endif
10850 +
10851 : "+m" (l->a.counter)
10852 : "ir" (i));
10853 }
10854 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10855 {
10856 unsigned char c;
10857
10858 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10859 + asm volatile(_ASM_SUB "%2,%0\n"
10860 +
10861 +#ifdef CONFIG_PAX_REFCOUNT
10862 + "jno 0f\n"
10863 + _ASM_ADD "%2,%0\n"
10864 + "int $4\n0:\n"
10865 + _ASM_EXTABLE(0b, 0b)
10866 +#endif
10867 +
10868 + "sete %1\n"
10869 : "+m" (l->a.counter), "=qm" (c)
10870 : "ir" (i) : "memory");
10871 return c;
10872 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10873 {
10874 unsigned char c;
10875
10876 - asm volatile(_ASM_DEC "%0; sete %1"
10877 + asm volatile(_ASM_DEC "%0\n"
10878 +
10879 +#ifdef CONFIG_PAX_REFCOUNT
10880 + "jno 0f\n"
10881 + _ASM_INC "%0\n"
10882 + "int $4\n0:\n"
10883 + _ASM_EXTABLE(0b, 0b)
10884 +#endif
10885 +
10886 + "sete %1\n"
10887 : "+m" (l->a.counter), "=qm" (c)
10888 : : "memory");
10889 return c != 0;
10890 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10891 {
10892 unsigned char c;
10893
10894 - asm volatile(_ASM_INC "%0; sete %1"
10895 + asm volatile(_ASM_INC "%0\n"
10896 +
10897 +#ifdef CONFIG_PAX_REFCOUNT
10898 + "jno 0f\n"
10899 + _ASM_DEC "%0\n"
10900 + "int $4\n0:\n"
10901 + _ASM_EXTABLE(0b, 0b)
10902 +#endif
10903 +
10904 + "sete %1\n"
10905 : "+m" (l->a.counter), "=qm" (c)
10906 : : "memory");
10907 return c != 0;
10908 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10909 {
10910 unsigned char c;
10911
10912 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10913 + asm volatile(_ASM_ADD "%2,%0\n"
10914 +
10915 +#ifdef CONFIG_PAX_REFCOUNT
10916 + "jno 0f\n"
10917 + _ASM_SUB "%2,%0\n"
10918 + "int $4\n0:\n"
10919 + _ASM_EXTABLE(0b, 0b)
10920 +#endif
10921 +
10922 + "sets %1\n"
10923 : "+m" (l->a.counter), "=qm" (c)
10924 : "ir" (i) : "memory");
10925 return c;
10926 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10927 #endif
10928 /* Modern 486+ processor */
10929 __i = i;
10930 - asm volatile(_ASM_XADD "%0, %1;"
10931 + asm volatile(_ASM_XADD "%0, %1\n"
10932 +
10933 +#ifdef CONFIG_PAX_REFCOUNT
10934 + "jno 0f\n"
10935 + _ASM_MOV "%0,%1\n"
10936 + "int $4\n0:\n"
10937 + _ASM_EXTABLE(0b, 0b)
10938 +#endif
10939 +
10940 : "+r" (i), "+m" (l->a.counter)
10941 : : "memory");
10942 return i + __i;
10943 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10944 index 593e51d..fa69c9a 100644
10945 --- a/arch/x86/include/asm/mman.h
10946 +++ b/arch/x86/include/asm/mman.h
10947 @@ -5,4 +5,14 @@
10948
10949 #include <asm-generic/mman.h>
10950
10951 +#ifdef __KERNEL__
10952 +#ifndef __ASSEMBLY__
10953 +#ifdef CONFIG_X86_32
10954 +#define arch_mmap_check i386_mmap_check
10955 +int i386_mmap_check(unsigned long addr, unsigned long len,
10956 + unsigned long flags);
10957 +#endif
10958 +#endif
10959 +#endif
10960 +
10961 #endif /* _ASM_X86_MMAN_H */
10962 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10963 index 5f55e69..e20bfb1 100644
10964 --- a/arch/x86/include/asm/mmu.h
10965 +++ b/arch/x86/include/asm/mmu.h
10966 @@ -9,7 +9,7 @@
10967 * we put the segment information here.
10968 */
10969 typedef struct {
10970 - void *ldt;
10971 + struct desc_struct *ldt;
10972 int size;
10973
10974 #ifdef CONFIG_X86_64
10975 @@ -18,7 +18,19 @@ typedef struct {
10976 #endif
10977
10978 struct mutex lock;
10979 - void *vdso;
10980 + unsigned long vdso;
10981 +
10982 +#ifdef CONFIG_X86_32
10983 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10984 + unsigned long user_cs_base;
10985 + unsigned long user_cs_limit;
10986 +
10987 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10988 + cpumask_t cpu_user_cs_mask;
10989 +#endif
10990 +
10991 +#endif
10992 +#endif
10993 } mm_context_t;
10994
10995 #ifdef CONFIG_SMP
10996 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10997 index 6902152..399f3a2 100644
10998 --- a/arch/x86/include/asm/mmu_context.h
10999 +++ b/arch/x86/include/asm/mmu_context.h
11000 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
11001
11002 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
11003 {
11004 +
11005 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11006 + unsigned int i;
11007 + pgd_t *pgd;
11008 +
11009 + pax_open_kernel();
11010 + pgd = get_cpu_pgd(smp_processor_id());
11011 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
11012 + set_pgd_batched(pgd+i, native_make_pgd(0));
11013 + pax_close_kernel();
11014 +#endif
11015 +
11016 #ifdef CONFIG_SMP
11017 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11018 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11019 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11020 struct task_struct *tsk)
11021 {
11022 unsigned cpu = smp_processor_id();
11023 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11024 + int tlbstate = TLBSTATE_OK;
11025 +#endif
11026
11027 if (likely(prev != next)) {
11028 #ifdef CONFIG_SMP
11029 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11030 + tlbstate = percpu_read(cpu_tlbstate.state);
11031 +#endif
11032 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11033 percpu_write(cpu_tlbstate.active_mm, next);
11034 #endif
11035 cpumask_set_cpu(cpu, mm_cpumask(next));
11036
11037 /* Re-load page tables */
11038 +#ifdef CONFIG_PAX_PER_CPU_PGD
11039 + pax_open_kernel();
11040 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
11041 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
11042 + pax_close_kernel();
11043 + load_cr3(get_cpu_pgd(cpu));
11044 +#else
11045 load_cr3(next->pgd);
11046 +#endif
11047
11048 /* stop flush ipis for the previous mm */
11049 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11050 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11051 */
11052 if (unlikely(prev->context.ldt != next->context.ldt))
11053 load_LDT_nolock(&next->context);
11054 - }
11055 +
11056 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11057 + if (!(__supported_pte_mask & _PAGE_NX)) {
11058 + smp_mb__before_clear_bit();
11059 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11060 + smp_mb__after_clear_bit();
11061 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11062 + }
11063 +#endif
11064 +
11065 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11066 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11067 + prev->context.user_cs_limit != next->context.user_cs_limit))
11068 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11069 #ifdef CONFIG_SMP
11070 + else if (unlikely(tlbstate != TLBSTATE_OK))
11071 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11072 +#endif
11073 +#endif
11074 +
11075 + }
11076 else {
11077 +
11078 +#ifdef CONFIG_PAX_PER_CPU_PGD
11079 + pax_open_kernel();
11080 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
11081 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
11082 + pax_close_kernel();
11083 + load_cr3(get_cpu_pgd(cpu));
11084 +#endif
11085 +
11086 +#ifdef CONFIG_SMP
11087 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11088 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
11089
11090 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11091 * tlb flush IPI delivery. We must reload CR3
11092 * to make sure to use no freed page tables.
11093 */
11094 +
11095 +#ifndef CONFIG_PAX_PER_CPU_PGD
11096 load_cr3(next->pgd);
11097 +#endif
11098 +
11099 load_LDT_nolock(&next->context);
11100 +
11101 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11102 + if (!(__supported_pte_mask & _PAGE_NX))
11103 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11104 +#endif
11105 +
11106 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11107 +#ifdef CONFIG_PAX_PAGEEXEC
11108 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11109 +#endif
11110 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11111 +#endif
11112 +
11113 }
11114 +#endif
11115 }
11116 -#endif
11117 }
11118
11119 #define activate_mm(prev, next) \
11120 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11121 index 9eae775..c914fea 100644
11122 --- a/arch/x86/include/asm/module.h
11123 +++ b/arch/x86/include/asm/module.h
11124 @@ -5,6 +5,7 @@
11125
11126 #ifdef CONFIG_X86_64
11127 /* X86_64 does not define MODULE_PROC_FAMILY */
11128 +#define MODULE_PROC_FAMILY ""
11129 #elif defined CONFIG_M386
11130 #define MODULE_PROC_FAMILY "386 "
11131 #elif defined CONFIG_M486
11132 @@ -59,8 +60,20 @@
11133 #error unknown processor family
11134 #endif
11135
11136 -#ifdef CONFIG_X86_32
11137 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11138 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11139 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11140 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11141 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11142 +#else
11143 +#define MODULE_PAX_KERNEXEC ""
11144 #endif
11145
11146 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11147 +#define MODULE_PAX_UDEREF "UDEREF "
11148 +#else
11149 +#define MODULE_PAX_UDEREF ""
11150 +#endif
11151 +
11152 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11153 +
11154 #endif /* _ASM_X86_MODULE_H */
11155 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11156 index 7639dbf..e08a58c 100644
11157 --- a/arch/x86/include/asm/page_64_types.h
11158 +++ b/arch/x86/include/asm/page_64_types.h
11159 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11160
11161 /* duplicated to the one in bootmem.h */
11162 extern unsigned long max_pfn;
11163 -extern unsigned long phys_base;
11164 +extern const unsigned long phys_base;
11165
11166 extern unsigned long __phys_addr(unsigned long);
11167 #define __phys_reloc_hide(x) (x)
11168 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11169 index a7d2db9..edb023e 100644
11170 --- a/arch/x86/include/asm/paravirt.h
11171 +++ b/arch/x86/include/asm/paravirt.h
11172 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11173 val);
11174 }
11175
11176 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11177 +{
11178 + pgdval_t val = native_pgd_val(pgd);
11179 +
11180 + if (sizeof(pgdval_t) > sizeof(long))
11181 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11182 + val, (u64)val >> 32);
11183 + else
11184 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11185 + val);
11186 +}
11187 +
11188 static inline void pgd_clear(pgd_t *pgdp)
11189 {
11190 set_pgd(pgdp, __pgd(0));
11191 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11192 pv_mmu_ops.set_fixmap(idx, phys, flags);
11193 }
11194
11195 +#ifdef CONFIG_PAX_KERNEXEC
11196 +static inline unsigned long pax_open_kernel(void)
11197 +{
11198 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11199 +}
11200 +
11201 +static inline unsigned long pax_close_kernel(void)
11202 +{
11203 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11204 +}
11205 +#else
11206 +static inline unsigned long pax_open_kernel(void) { return 0; }
11207 +static inline unsigned long pax_close_kernel(void) { return 0; }
11208 +#endif
11209 +
11210 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11211
11212 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11213 @@ -964,7 +991,7 @@ extern void default_banner(void);
11214
11215 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11216 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11217 -#define PARA_INDIRECT(addr) *%cs:addr
11218 +#define PARA_INDIRECT(addr) *%ss:addr
11219 #endif
11220
11221 #define INTERRUPT_RETURN \
11222 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
11223 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11224 CLBR_NONE, \
11225 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11226 +
11227 +#define GET_CR0_INTO_RDI \
11228 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11229 + mov %rax,%rdi
11230 +
11231 +#define SET_RDI_INTO_CR0 \
11232 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11233 +
11234 +#define GET_CR3_INTO_RDI \
11235 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11236 + mov %rax,%rdi
11237 +
11238 +#define SET_RDI_INTO_CR3 \
11239 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11240 +
11241 #endif /* CONFIG_X86_32 */
11242
11243 #endif /* __ASSEMBLY__ */
11244 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11245 index 8e8b9a4..f07d725 100644
11246 --- a/arch/x86/include/asm/paravirt_types.h
11247 +++ b/arch/x86/include/asm/paravirt_types.h
11248 @@ -84,20 +84,20 @@ struct pv_init_ops {
11249 */
11250 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11251 unsigned long addr, unsigned len);
11252 -};
11253 +} __no_const;
11254
11255
11256 struct pv_lazy_ops {
11257 /* Set deferred update mode, used for batching operations. */
11258 void (*enter)(void);
11259 void (*leave)(void);
11260 -};
11261 +} __no_const;
11262
11263 struct pv_time_ops {
11264 unsigned long long (*sched_clock)(void);
11265 unsigned long long (*steal_clock)(int cpu);
11266 unsigned long (*get_tsc_khz)(void);
11267 -};
11268 +} __no_const;
11269
11270 struct pv_cpu_ops {
11271 /* hooks for various privileged instructions */
11272 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
11273
11274 void (*start_context_switch)(struct task_struct *prev);
11275 void (*end_context_switch)(struct task_struct *next);
11276 -};
11277 +} __no_const;
11278
11279 struct pv_irq_ops {
11280 /*
11281 @@ -224,7 +224,7 @@ struct pv_apic_ops {
11282 unsigned long start_eip,
11283 unsigned long start_esp);
11284 #endif
11285 -};
11286 +} __no_const;
11287
11288 struct pv_mmu_ops {
11289 unsigned long (*read_cr2)(void);
11290 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
11291 struct paravirt_callee_save make_pud;
11292
11293 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11294 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11295 #endif /* PAGETABLE_LEVELS == 4 */
11296 #endif /* PAGETABLE_LEVELS >= 3 */
11297
11298 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
11299 an mfn. We can tell which is which from the index. */
11300 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11301 phys_addr_t phys, pgprot_t flags);
11302 +
11303 +#ifdef CONFIG_PAX_KERNEXEC
11304 + unsigned long (*pax_open_kernel)(void);
11305 + unsigned long (*pax_close_kernel)(void);
11306 +#endif
11307 +
11308 };
11309
11310 struct arch_spinlock;
11311 @@ -334,7 +341,7 @@ struct pv_lock_ops {
11312 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11313 int (*spin_trylock)(struct arch_spinlock *lock);
11314 void (*spin_unlock)(struct arch_spinlock *lock);
11315 -};
11316 +} __no_const;
11317
11318 /* This contains all the paravirt structures: we get a convenient
11319 * number for each function using the offset which we use to indicate
11320 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11321 index b4389a4..7024269 100644
11322 --- a/arch/x86/include/asm/pgalloc.h
11323 +++ b/arch/x86/include/asm/pgalloc.h
11324 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11325 pmd_t *pmd, pte_t *pte)
11326 {
11327 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11328 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11329 +}
11330 +
11331 +static inline void pmd_populate_user(struct mm_struct *mm,
11332 + pmd_t *pmd, pte_t *pte)
11333 +{
11334 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11335 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11336 }
11337
11338 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11339
11340 #ifdef CONFIG_X86_PAE
11341 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11342 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11343 +{
11344 + pud_populate(mm, pudp, pmd);
11345 +}
11346 #else /* !CONFIG_X86_PAE */
11347 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11348 {
11349 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11350 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11351 }
11352 +
11353 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11354 +{
11355 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11356 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11357 +}
11358 #endif /* CONFIG_X86_PAE */
11359
11360 #if PAGETABLE_LEVELS > 3
11361 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11362 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11363 }
11364
11365 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11366 +{
11367 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11368 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11369 +}
11370 +
11371 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11372 {
11373 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11374 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11375 index 98391db..8f6984e 100644
11376 --- a/arch/x86/include/asm/pgtable-2level.h
11377 +++ b/arch/x86/include/asm/pgtable-2level.h
11378 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11379
11380 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11381 {
11382 + pax_open_kernel();
11383 *pmdp = pmd;
11384 + pax_close_kernel();
11385 }
11386
11387 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11388 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11389 index effff47..bbb8295 100644
11390 --- a/arch/x86/include/asm/pgtable-3level.h
11391 +++ b/arch/x86/include/asm/pgtable-3level.h
11392 @@ -31,6 +31,56 @@ static inline void native_set_pte(pte_t *ptep, pte_t pte)
11393 ptep->pte_low = pte.pte_low;
11394 }
11395
11396 +#define __HAVE_ARCH_READ_PMD_ATOMIC
11397 +/*
11398 + * pte_offset_map_lock on 32bit PAE kernels was reading the pmd_t with
11399 + * a "*pmdp" dereference done by gcc. Problem is, in certain places
11400 + * where pte_offset_map_lock is called, concurrent page faults are
11401 + * allowed, if the mmap_sem is hold for reading. An example is mincore
11402 + * vs page faults vs MADV_DONTNEED. On the page fault side
11403 + * pmd_populate rightfully does a set_64bit, but if we're reading the
11404 + * pmd_t with a "*pmdp" on the mincore side, a SMP race can happen
11405 + * because gcc will not read the 64bit of the pmd atomically. To fix
11406 + * this all places running pmd_offset_map_lock() while holding the
11407 + * mmap_sem in read mode, shall read the pmdp pointer using this
11408 + * function to know if the pmd is null nor not, and in turn to know if
11409 + * they can run pmd_offset_map_lock or pmd_trans_huge or other pmd
11410 + * operations.
11411 + *
11412 + * Without THP if the mmap_sem is hold for reading, the
11413 + * pmd can only transition from null to not null while read_pmd_atomic runs.
11414 + * So there's no need of literally reading it atomically.
11415 + *
11416 + * With THP if the mmap_sem is hold for reading, the pmd can become
11417 + * THP or null or point to a pte (and in turn become "stable") at any
11418 + * time under read_pmd_atomic, so it's mandatory to read it atomically
11419 + * with cmpxchg8b.
11420 + */
11421 +#ifndef CONFIG_TRANSPARENT_HUGEPAGE
11422 +static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11423 +{
11424 + pmdval_t ret;
11425 + u32 *tmp = (u32 *)pmdp;
11426 +
11427 + ret = (pmdval_t) (*tmp);
11428 + if (ret) {
11429 + /*
11430 + * If the low part is null, we must not read the high part
11431 + * or we can end up with a partial pmd.
11432 + */
11433 + smp_rmb();
11434 + ret |= ((pmdval_t)*(tmp + 1)) << 32;
11435 + }
11436 +
11437 + return __pmd(ret);
11438 +}
11439 +#else /* CONFIG_TRANSPARENT_HUGEPAGE */
11440 +static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11441 +{
11442 + return __pmd(atomic64_read((atomic64_t *)pmdp));
11443 +}
11444 +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
11445 +
11446 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11447 {
11448 set_64bit((unsigned long long *)(ptep), native_pte_val(pte));
11449 @@ -38,12 +88,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11450
11451 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11452 {
11453 + pax_open_kernel();
11454 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11455 + pax_close_kernel();
11456 }
11457
11458 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11459 {
11460 + pax_open_kernel();
11461 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11462 + pax_close_kernel();
11463 }
11464
11465 /*
11466 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11467 index 49afb3f..ed14d07 100644
11468 --- a/arch/x86/include/asm/pgtable.h
11469 +++ b/arch/x86/include/asm/pgtable.h
11470 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11471
11472 #ifndef __PAGETABLE_PUD_FOLDED
11473 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11474 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11475 #define pgd_clear(pgd) native_pgd_clear(pgd)
11476 #endif
11477
11478 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11479
11480 #define arch_end_context_switch(prev) do {} while(0)
11481
11482 +#define pax_open_kernel() native_pax_open_kernel()
11483 +#define pax_close_kernel() native_pax_close_kernel()
11484 #endif /* CONFIG_PARAVIRT */
11485
11486 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11487 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11488 +
11489 +#ifdef CONFIG_PAX_KERNEXEC
11490 +static inline unsigned long native_pax_open_kernel(void)
11491 +{
11492 + unsigned long cr0;
11493 +
11494 + preempt_disable();
11495 + barrier();
11496 + cr0 = read_cr0() ^ X86_CR0_WP;
11497 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11498 + write_cr0(cr0);
11499 + return cr0 ^ X86_CR0_WP;
11500 +}
11501 +
11502 +static inline unsigned long native_pax_close_kernel(void)
11503 +{
11504 + unsigned long cr0;
11505 +
11506 + cr0 = read_cr0() ^ X86_CR0_WP;
11507 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11508 + write_cr0(cr0);
11509 + barrier();
11510 + preempt_enable_no_resched();
11511 + return cr0 ^ X86_CR0_WP;
11512 +}
11513 +#else
11514 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11515 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11516 +#endif
11517 +
11518 /*
11519 * The following only work if pte_present() is true.
11520 * Undefined behaviour if not..
11521 */
11522 +static inline int pte_user(pte_t pte)
11523 +{
11524 + return pte_val(pte) & _PAGE_USER;
11525 +}
11526 +
11527 static inline int pte_dirty(pte_t pte)
11528 {
11529 return pte_flags(pte) & _PAGE_DIRTY;
11530 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11531 return pte_clear_flags(pte, _PAGE_RW);
11532 }
11533
11534 +static inline pte_t pte_mkread(pte_t pte)
11535 +{
11536 + return __pte(pte_val(pte) | _PAGE_USER);
11537 +}
11538 +
11539 static inline pte_t pte_mkexec(pte_t pte)
11540 {
11541 - return pte_clear_flags(pte, _PAGE_NX);
11542 +#ifdef CONFIG_X86_PAE
11543 + if (__supported_pte_mask & _PAGE_NX)
11544 + return pte_clear_flags(pte, _PAGE_NX);
11545 + else
11546 +#endif
11547 + return pte_set_flags(pte, _PAGE_USER);
11548 +}
11549 +
11550 +static inline pte_t pte_exprotect(pte_t pte)
11551 +{
11552 +#ifdef CONFIG_X86_PAE
11553 + if (__supported_pte_mask & _PAGE_NX)
11554 + return pte_set_flags(pte, _PAGE_NX);
11555 + else
11556 +#endif
11557 + return pte_clear_flags(pte, _PAGE_USER);
11558 }
11559
11560 static inline pte_t pte_mkdirty(pte_t pte)
11561 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11562 #endif
11563
11564 #ifndef __ASSEMBLY__
11565 +
11566 +#ifdef CONFIG_PAX_PER_CPU_PGD
11567 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11568 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11569 +{
11570 + return cpu_pgd[cpu];
11571 +}
11572 +#endif
11573 +
11574 #include <linux/mm_types.h>
11575
11576 static inline int pte_none(pte_t pte)
11577 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11578
11579 static inline int pgd_bad(pgd_t pgd)
11580 {
11581 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11582 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11583 }
11584
11585 static inline int pgd_none(pgd_t pgd)
11586 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11587 * pgd_offset() returns a (pgd_t *)
11588 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11589 */
11590 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11591 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11592 +
11593 +#ifdef CONFIG_PAX_PER_CPU_PGD
11594 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11595 +#endif
11596 +
11597 /*
11598 * a shortcut which implies the use of the kernel's pgd, instead
11599 * of a process's
11600 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11601 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11602 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11603
11604 +#ifdef CONFIG_X86_32
11605 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11606 +#else
11607 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11608 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11609 +
11610 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11611 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11612 +#else
11613 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11614 +#endif
11615 +
11616 +#endif
11617 +
11618 #ifndef __ASSEMBLY__
11619
11620 extern int direct_gbpages;
11621 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11622 * dst and src can be on the same page, but the range must not overlap,
11623 * and must not cross a page boundary.
11624 */
11625 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11626 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11627 {
11628 - memcpy(dst, src, count * sizeof(pgd_t));
11629 + pax_open_kernel();
11630 + while (count--)
11631 + *dst++ = *src++;
11632 + pax_close_kernel();
11633 }
11634
11635 +#ifdef CONFIG_PAX_PER_CPU_PGD
11636 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11637 +#endif
11638 +
11639 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11640 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11641 +#else
11642 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
11643 +#endif
11644
11645 #include <asm-generic/pgtable.h>
11646 #endif /* __ASSEMBLY__ */
11647 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11648 index 0c92113..34a77c6 100644
11649 --- a/arch/x86/include/asm/pgtable_32.h
11650 +++ b/arch/x86/include/asm/pgtable_32.h
11651 @@ -25,9 +25,6 @@
11652 struct mm_struct;
11653 struct vm_area_struct;
11654
11655 -extern pgd_t swapper_pg_dir[1024];
11656 -extern pgd_t initial_page_table[1024];
11657 -
11658 static inline void pgtable_cache_init(void) { }
11659 static inline void check_pgt_cache(void) { }
11660 void paging_init(void);
11661 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11662 # include <asm/pgtable-2level.h>
11663 #endif
11664
11665 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11666 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11667 +#ifdef CONFIG_X86_PAE
11668 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11669 +#endif
11670 +
11671 #if defined(CONFIG_HIGHPTE)
11672 #define pte_offset_map(dir, address) \
11673 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11674 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11675 /* Clear a kernel PTE and flush it from the TLB */
11676 #define kpte_clear_flush(ptep, vaddr) \
11677 do { \
11678 + pax_open_kernel(); \
11679 pte_clear(&init_mm, (vaddr), (ptep)); \
11680 + pax_close_kernel(); \
11681 __flush_tlb_one((vaddr)); \
11682 } while (0)
11683
11684 @@ -74,6 +79,9 @@ do { \
11685
11686 #endif /* !__ASSEMBLY__ */
11687
11688 +#define HAVE_ARCH_UNMAPPED_AREA
11689 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11690 +
11691 /*
11692 * kern_addr_valid() is (1) for FLATMEM and (0) for
11693 * SPARSEMEM and DISCONTIGMEM
11694 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11695 index ed5903b..c7fe163 100644
11696 --- a/arch/x86/include/asm/pgtable_32_types.h
11697 +++ b/arch/x86/include/asm/pgtable_32_types.h
11698 @@ -8,7 +8,7 @@
11699 */
11700 #ifdef CONFIG_X86_PAE
11701 # include <asm/pgtable-3level_types.h>
11702 -# define PMD_SIZE (1UL << PMD_SHIFT)
11703 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11704 # define PMD_MASK (~(PMD_SIZE - 1))
11705 #else
11706 # include <asm/pgtable-2level_types.h>
11707 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11708 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11709 #endif
11710
11711 +#ifdef CONFIG_PAX_KERNEXEC
11712 +#ifndef __ASSEMBLY__
11713 +extern unsigned char MODULES_EXEC_VADDR[];
11714 +extern unsigned char MODULES_EXEC_END[];
11715 +#endif
11716 +#include <asm/boot.h>
11717 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11718 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11719 +#else
11720 +#define ktla_ktva(addr) (addr)
11721 +#define ktva_ktla(addr) (addr)
11722 +#endif
11723 +
11724 #define MODULES_VADDR VMALLOC_START
11725 #define MODULES_END VMALLOC_END
11726 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11727 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11728 index 975f709..9f779c9 100644
11729 --- a/arch/x86/include/asm/pgtable_64.h
11730 +++ b/arch/x86/include/asm/pgtable_64.h
11731 @@ -16,10 +16,14 @@
11732
11733 extern pud_t level3_kernel_pgt[512];
11734 extern pud_t level3_ident_pgt[512];
11735 +extern pud_t level3_vmalloc_start_pgt[512];
11736 +extern pud_t level3_vmalloc_end_pgt[512];
11737 +extern pud_t level3_vmemmap_pgt[512];
11738 +extern pud_t level2_vmemmap_pgt[512];
11739 extern pmd_t level2_kernel_pgt[512];
11740 extern pmd_t level2_fixmap_pgt[512];
11741 -extern pmd_t level2_ident_pgt[512];
11742 -extern pgd_t init_level4_pgt[];
11743 +extern pmd_t level2_ident_pgt[512*2];
11744 +extern pgd_t init_level4_pgt[512];
11745
11746 #define swapper_pg_dir init_level4_pgt
11747
11748 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11749
11750 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11751 {
11752 + pax_open_kernel();
11753 *pmdp = pmd;
11754 + pax_close_kernel();
11755 }
11756
11757 static inline void native_pmd_clear(pmd_t *pmd)
11758 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11759
11760 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11761 {
11762 + pax_open_kernel();
11763 *pudp = pud;
11764 + pax_close_kernel();
11765 }
11766
11767 static inline void native_pud_clear(pud_t *pud)
11768 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11769
11770 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11771 {
11772 + pax_open_kernel();
11773 + *pgdp = pgd;
11774 + pax_close_kernel();
11775 +}
11776 +
11777 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11778 +{
11779 *pgdp = pgd;
11780 }
11781
11782 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11783 index 766ea16..5b96cb3 100644
11784 --- a/arch/x86/include/asm/pgtable_64_types.h
11785 +++ b/arch/x86/include/asm/pgtable_64_types.h
11786 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11787 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11788 #define MODULES_END _AC(0xffffffffff000000, UL)
11789 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11790 +#define MODULES_EXEC_VADDR MODULES_VADDR
11791 +#define MODULES_EXEC_END MODULES_END
11792 +
11793 +#define ktla_ktva(addr) (addr)
11794 +#define ktva_ktla(addr) (addr)
11795
11796 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11797 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11798 index 013286a..8b42f4f 100644
11799 --- a/arch/x86/include/asm/pgtable_types.h
11800 +++ b/arch/x86/include/asm/pgtable_types.h
11801 @@ -16,13 +16,12 @@
11802 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11803 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11804 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11805 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11806 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11807 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11808 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11809 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11810 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11811 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11812 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11813 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11814 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11815 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11816
11817 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11818 @@ -40,7 +39,6 @@
11819 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11820 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11821 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11822 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11823 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11824 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11825 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11826 @@ -57,8 +55,10 @@
11827
11828 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11829 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11830 -#else
11831 +#elif defined(CONFIG_KMEMCHECK)
11832 #define _PAGE_NX (_AT(pteval_t, 0))
11833 +#else
11834 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11835 #endif
11836
11837 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11838 @@ -96,6 +96,9 @@
11839 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11840 _PAGE_ACCESSED)
11841
11842 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11843 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11844 +
11845 #define __PAGE_KERNEL_EXEC \
11846 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11847 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11848 @@ -106,7 +109,7 @@
11849 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11850 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11851 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11852 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11853 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11854 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11855 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11856 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11857 @@ -168,8 +171,8 @@
11858 * bits are combined, this will alow user to access the high address mapped
11859 * VDSO in the presence of CONFIG_COMPAT_VDSO
11860 */
11861 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11862 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11863 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11864 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11865 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11866 #endif
11867
11868 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11869 {
11870 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11871 }
11872 +#endif
11873
11874 +#if PAGETABLE_LEVELS == 3
11875 +#include <asm-generic/pgtable-nopud.h>
11876 +#endif
11877 +
11878 +#if PAGETABLE_LEVELS == 2
11879 +#include <asm-generic/pgtable-nopmd.h>
11880 +#endif
11881 +
11882 +#ifndef __ASSEMBLY__
11883 #if PAGETABLE_LEVELS > 3
11884 typedef struct { pudval_t pud; } pud_t;
11885
11886 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11887 return pud.pud;
11888 }
11889 #else
11890 -#include <asm-generic/pgtable-nopud.h>
11891 -
11892 static inline pudval_t native_pud_val(pud_t pud)
11893 {
11894 return native_pgd_val(pud.pgd);
11895 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11896 return pmd.pmd;
11897 }
11898 #else
11899 -#include <asm-generic/pgtable-nopmd.h>
11900 -
11901 static inline pmdval_t native_pmd_val(pmd_t pmd)
11902 {
11903 return native_pgd_val(pmd.pud.pgd);
11904 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11905
11906 extern pteval_t __supported_pte_mask;
11907 extern void set_nx(void);
11908 -extern int nx_enabled;
11909
11910 #define pgprot_writecombine pgprot_writecombine
11911 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11912 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11913 index 58545c9..fe6fc38e 100644
11914 --- a/arch/x86/include/asm/processor.h
11915 +++ b/arch/x86/include/asm/processor.h
11916 @@ -266,7 +266,7 @@ struct tss_struct {
11917
11918 } ____cacheline_aligned;
11919
11920 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11921 +extern struct tss_struct init_tss[NR_CPUS];
11922
11923 /*
11924 * Save the original ist values for checking stack pointers during debugging
11925 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
11926 */
11927 #define TASK_SIZE PAGE_OFFSET
11928 #define TASK_SIZE_MAX TASK_SIZE
11929 +
11930 +#ifdef CONFIG_PAX_SEGMEXEC
11931 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11932 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11933 +#else
11934 #define STACK_TOP TASK_SIZE
11935 -#define STACK_TOP_MAX STACK_TOP
11936 +#endif
11937 +
11938 +#define STACK_TOP_MAX TASK_SIZE
11939
11940 #define INIT_THREAD { \
11941 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11942 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11943 .vm86_info = NULL, \
11944 .sysenter_cs = __KERNEL_CS, \
11945 .io_bitmap_ptr = NULL, \
11946 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
11947 */
11948 #define INIT_TSS { \
11949 .x86_tss = { \
11950 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11951 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11952 .ss0 = __KERNEL_DS, \
11953 .ss1 = __KERNEL_CS, \
11954 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11955 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
11956 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11957
11958 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11959 -#define KSTK_TOP(info) \
11960 -({ \
11961 - unsigned long *__ptr = (unsigned long *)(info); \
11962 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11963 -})
11964 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11965
11966 /*
11967 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11968 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11969 #define task_pt_regs(task) \
11970 ({ \
11971 struct pt_regs *__regs__; \
11972 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11973 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11974 __regs__ - 1; \
11975 })
11976
11977 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11978 /*
11979 * User space process size. 47bits minus one guard page.
11980 */
11981 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11982 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11983
11984 /* This decides where the kernel will search for a free chunk of vm
11985 * space during mmap's.
11986 */
11987 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11988 - 0xc0000000 : 0xFFFFe000)
11989 + 0xc0000000 : 0xFFFFf000)
11990
11991 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11992 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11993 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11994 #define STACK_TOP_MAX TASK_SIZE_MAX
11995
11996 #define INIT_THREAD { \
11997 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11998 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11999 }
12000
12001 #define INIT_TSS { \
12002 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
12003 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
12004 }
12005
12006 /*
12007 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
12008 */
12009 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
12010
12011 +#ifdef CONFIG_PAX_SEGMEXEC
12012 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
12013 +#endif
12014 +
12015 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
12016
12017 /* Get/set a process' ability to use the timestamp counter instruction */
12018 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
12019 index 3566454..4bdfb8c 100644
12020 --- a/arch/x86/include/asm/ptrace.h
12021 +++ b/arch/x86/include/asm/ptrace.h
12022 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
12023 }
12024
12025 /*
12026 - * user_mode_vm(regs) determines whether a register set came from user mode.
12027 + * user_mode(regs) determines whether a register set came from user mode.
12028 * This is true if V8086 mode was enabled OR if the register set was from
12029 * protected mode with RPL-3 CS value. This tricky test checks that with
12030 * one comparison. Many places in the kernel can bypass this full check
12031 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
12032 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
12033 + * be used.
12034 */
12035 -static inline int user_mode(struct pt_regs *regs)
12036 +static inline int user_mode_novm(struct pt_regs *regs)
12037 {
12038 #ifdef CONFIG_X86_32
12039 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
12040 #else
12041 - return !!(regs->cs & 3);
12042 + return !!(regs->cs & SEGMENT_RPL_MASK);
12043 #endif
12044 }
12045
12046 -static inline int user_mode_vm(struct pt_regs *regs)
12047 +static inline int user_mode(struct pt_regs *regs)
12048 {
12049 #ifdef CONFIG_X86_32
12050 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12051 USER_RPL;
12052 #else
12053 - return user_mode(regs);
12054 + return user_mode_novm(regs);
12055 #endif
12056 }
12057
12058 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12059 #ifdef CONFIG_X86_64
12060 static inline bool user_64bit_mode(struct pt_regs *regs)
12061 {
12062 + unsigned long cs = regs->cs & 0xffff;
12063 #ifndef CONFIG_PARAVIRT
12064 /*
12065 * On non-paravirt systems, this is the only long mode CPL 3
12066 * selector. We do not allow long mode selectors in the LDT.
12067 */
12068 - return regs->cs == __USER_CS;
12069 + return cs == __USER_CS;
12070 #else
12071 /* Headers are too twisted for this to go in paravirt.h. */
12072 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12073 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12074 #endif
12075 }
12076 #endif
12077 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12078 index 92f29706..a79cbbb 100644
12079 --- a/arch/x86/include/asm/reboot.h
12080 +++ b/arch/x86/include/asm/reboot.h
12081 @@ -6,19 +6,19 @@
12082 struct pt_regs;
12083
12084 struct machine_ops {
12085 - void (*restart)(char *cmd);
12086 - void (*halt)(void);
12087 - void (*power_off)(void);
12088 + void (* __noreturn restart)(char *cmd);
12089 + void (* __noreturn halt)(void);
12090 + void (* __noreturn power_off)(void);
12091 void (*shutdown)(void);
12092 void (*crash_shutdown)(struct pt_regs *);
12093 - void (*emergency_restart)(void);
12094 -};
12095 + void (* __noreturn emergency_restart)(void);
12096 +} __no_const;
12097
12098 extern struct machine_ops machine_ops;
12099
12100 void native_machine_crash_shutdown(struct pt_regs *regs);
12101 void native_machine_shutdown(void);
12102 -void machine_real_restart(unsigned int type);
12103 +void machine_real_restart(unsigned int type) __noreturn;
12104 /* These must match dispatch_table in reboot_32.S */
12105 #define MRR_BIOS 0
12106 #define MRR_APM 1
12107 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12108 index 2dbe4a7..ce1db00 100644
12109 --- a/arch/x86/include/asm/rwsem.h
12110 +++ b/arch/x86/include/asm/rwsem.h
12111 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12112 {
12113 asm volatile("# beginning down_read\n\t"
12114 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12115 +
12116 +#ifdef CONFIG_PAX_REFCOUNT
12117 + "jno 0f\n"
12118 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12119 + "int $4\n0:\n"
12120 + _ASM_EXTABLE(0b, 0b)
12121 +#endif
12122 +
12123 /* adds 0x00000001 */
12124 " jns 1f\n"
12125 " call call_rwsem_down_read_failed\n"
12126 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12127 "1:\n\t"
12128 " mov %1,%2\n\t"
12129 " add %3,%2\n\t"
12130 +
12131 +#ifdef CONFIG_PAX_REFCOUNT
12132 + "jno 0f\n"
12133 + "sub %3,%2\n"
12134 + "int $4\n0:\n"
12135 + _ASM_EXTABLE(0b, 0b)
12136 +#endif
12137 +
12138 " jle 2f\n\t"
12139 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12140 " jnz 1b\n\t"
12141 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12142 long tmp;
12143 asm volatile("# beginning down_write\n\t"
12144 LOCK_PREFIX " xadd %1,(%2)\n\t"
12145 +
12146 +#ifdef CONFIG_PAX_REFCOUNT
12147 + "jno 0f\n"
12148 + "mov %1,(%2)\n"
12149 + "int $4\n0:\n"
12150 + _ASM_EXTABLE(0b, 0b)
12151 +#endif
12152 +
12153 /* adds 0xffff0001, returns the old value */
12154 " test %1,%1\n\t"
12155 /* was the count 0 before? */
12156 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12157 long tmp;
12158 asm volatile("# beginning __up_read\n\t"
12159 LOCK_PREFIX " xadd %1,(%2)\n\t"
12160 +
12161 +#ifdef CONFIG_PAX_REFCOUNT
12162 + "jno 0f\n"
12163 + "mov %1,(%2)\n"
12164 + "int $4\n0:\n"
12165 + _ASM_EXTABLE(0b, 0b)
12166 +#endif
12167 +
12168 /* subtracts 1, returns the old value */
12169 " jns 1f\n\t"
12170 " call call_rwsem_wake\n" /* expects old value in %edx */
12171 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12172 long tmp;
12173 asm volatile("# beginning __up_write\n\t"
12174 LOCK_PREFIX " xadd %1,(%2)\n\t"
12175 +
12176 +#ifdef CONFIG_PAX_REFCOUNT
12177 + "jno 0f\n"
12178 + "mov %1,(%2)\n"
12179 + "int $4\n0:\n"
12180 + _ASM_EXTABLE(0b, 0b)
12181 +#endif
12182 +
12183 /* subtracts 0xffff0001, returns the old value */
12184 " jns 1f\n\t"
12185 " call call_rwsem_wake\n" /* expects old value in %edx */
12186 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12187 {
12188 asm volatile("# beginning __downgrade_write\n\t"
12189 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12190 +
12191 +#ifdef CONFIG_PAX_REFCOUNT
12192 + "jno 0f\n"
12193 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12194 + "int $4\n0:\n"
12195 + _ASM_EXTABLE(0b, 0b)
12196 +#endif
12197 +
12198 /*
12199 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12200 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12201 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12202 */
12203 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12204 {
12205 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12206 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12207 +
12208 +#ifdef CONFIG_PAX_REFCOUNT
12209 + "jno 0f\n"
12210 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12211 + "int $4\n0:\n"
12212 + _ASM_EXTABLE(0b, 0b)
12213 +#endif
12214 +
12215 : "+m" (sem->count)
12216 : "er" (delta));
12217 }
12218 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12219 */
12220 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12221 {
12222 - return delta + xadd(&sem->count, delta);
12223 + return delta + xadd_check_overflow(&sem->count, delta);
12224 }
12225
12226 #endif /* __KERNEL__ */
12227 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12228 index 5e64171..f58957e 100644
12229 --- a/arch/x86/include/asm/segment.h
12230 +++ b/arch/x86/include/asm/segment.h
12231 @@ -64,10 +64,15 @@
12232 * 26 - ESPFIX small SS
12233 * 27 - per-cpu [ offset to per-cpu data area ]
12234 * 28 - stack_canary-20 [ for stack protector ]
12235 - * 29 - unused
12236 - * 30 - unused
12237 + * 29 - PCI BIOS CS
12238 + * 30 - PCI BIOS DS
12239 * 31 - TSS for double fault handler
12240 */
12241 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12242 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12243 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12244 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12245 +
12246 #define GDT_ENTRY_TLS_MIN 6
12247 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12248
12249 @@ -79,6 +84,8 @@
12250
12251 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12252
12253 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12254 +
12255 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12256
12257 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12258 @@ -104,6 +111,12 @@
12259 #define __KERNEL_STACK_CANARY 0
12260 #endif
12261
12262 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12263 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12264 +
12265 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12266 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12267 +
12268 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12269
12270 /*
12271 @@ -141,7 +154,7 @@
12272 */
12273
12274 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12275 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12276 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12277
12278
12279 #else
12280 @@ -165,6 +178,8 @@
12281 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12282 #define __USER32_DS __USER_DS
12283
12284 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12285 +
12286 #define GDT_ENTRY_TSS 8 /* needs two entries */
12287 #define GDT_ENTRY_LDT 10 /* needs two entries */
12288 #define GDT_ENTRY_TLS_MIN 12
12289 @@ -185,6 +200,7 @@
12290 #endif
12291
12292 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12293 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12294 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12295 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12296 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12297 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12298 index 0434c40..1714bf0 100644
12299 --- a/arch/x86/include/asm/smp.h
12300 +++ b/arch/x86/include/asm/smp.h
12301 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12302 /* cpus sharing the last level cache: */
12303 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12304 DECLARE_PER_CPU(u16, cpu_llc_id);
12305 -DECLARE_PER_CPU(int, cpu_number);
12306 +DECLARE_PER_CPU(unsigned int, cpu_number);
12307
12308 static inline struct cpumask *cpu_sibling_mask(int cpu)
12309 {
12310 @@ -77,7 +77,7 @@ struct smp_ops {
12311
12312 void (*send_call_func_ipi)(const struct cpumask *mask);
12313 void (*send_call_func_single_ipi)(int cpu);
12314 -};
12315 +} __no_const;
12316
12317 /* Globals due to paravirt */
12318 extern void set_cpu_sibling_map(int cpu);
12319 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12320 extern int safe_smp_processor_id(void);
12321
12322 #elif defined(CONFIG_X86_64_SMP)
12323 -#define raw_smp_processor_id() (percpu_read(cpu_number))
12324 -
12325 -#define stack_smp_processor_id() \
12326 -({ \
12327 - struct thread_info *ti; \
12328 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12329 - ti->cpu; \
12330 -})
12331 +#define raw_smp_processor_id() (percpu_read(cpu_number))
12332 +#define stack_smp_processor_id() raw_smp_processor_id()
12333 #define safe_smp_processor_id() smp_processor_id()
12334
12335 #endif
12336 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12337 index a82c2bf..2198f61 100644
12338 --- a/arch/x86/include/asm/spinlock.h
12339 +++ b/arch/x86/include/asm/spinlock.h
12340 @@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12341 static inline void arch_read_lock(arch_rwlock_t *rw)
12342 {
12343 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12344 +
12345 +#ifdef CONFIG_PAX_REFCOUNT
12346 + "jno 0f\n"
12347 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12348 + "int $4\n0:\n"
12349 + _ASM_EXTABLE(0b, 0b)
12350 +#endif
12351 +
12352 "jns 1f\n"
12353 "call __read_lock_failed\n\t"
12354 "1:\n"
12355 @@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12356 static inline void arch_write_lock(arch_rwlock_t *rw)
12357 {
12358 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12359 +
12360 +#ifdef CONFIG_PAX_REFCOUNT
12361 + "jno 0f\n"
12362 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12363 + "int $4\n0:\n"
12364 + _ASM_EXTABLE(0b, 0b)
12365 +#endif
12366 +
12367 "jz 1f\n"
12368 "call __write_lock_failed\n\t"
12369 "1:\n"
12370 @@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12371
12372 static inline void arch_read_unlock(arch_rwlock_t *rw)
12373 {
12374 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12375 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12376 +
12377 +#ifdef CONFIG_PAX_REFCOUNT
12378 + "jno 0f\n"
12379 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12380 + "int $4\n0:\n"
12381 + _ASM_EXTABLE(0b, 0b)
12382 +#endif
12383 +
12384 :"+m" (rw->lock) : : "memory");
12385 }
12386
12387 static inline void arch_write_unlock(arch_rwlock_t *rw)
12388 {
12389 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12390 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12391 +
12392 +#ifdef CONFIG_PAX_REFCOUNT
12393 + "jno 0f\n"
12394 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12395 + "int $4\n0:\n"
12396 + _ASM_EXTABLE(0b, 0b)
12397 +#endif
12398 +
12399 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12400 }
12401
12402 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12403 index 1575177..cb23f52 100644
12404 --- a/arch/x86/include/asm/stackprotector.h
12405 +++ b/arch/x86/include/asm/stackprotector.h
12406 @@ -48,7 +48,7 @@
12407 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12408 */
12409 #define GDT_STACK_CANARY_INIT \
12410 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12411 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12412
12413 /*
12414 * Initialize the stackprotector canary value.
12415 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
12416
12417 static inline void load_stack_canary_segment(void)
12418 {
12419 -#ifdef CONFIG_X86_32
12420 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12421 asm volatile ("mov %0, %%gs" : : "r" (0));
12422 #endif
12423 }
12424 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12425 index 70bbe39..4ae2bd4 100644
12426 --- a/arch/x86/include/asm/stacktrace.h
12427 +++ b/arch/x86/include/asm/stacktrace.h
12428 @@ -11,28 +11,20 @@
12429
12430 extern int kstack_depth_to_print;
12431
12432 -struct thread_info;
12433 +struct task_struct;
12434 struct stacktrace_ops;
12435
12436 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12437 - unsigned long *stack,
12438 - unsigned long bp,
12439 - const struct stacktrace_ops *ops,
12440 - void *data,
12441 - unsigned long *end,
12442 - int *graph);
12443 +typedef unsigned long walk_stack_t(struct task_struct *task,
12444 + void *stack_start,
12445 + unsigned long *stack,
12446 + unsigned long bp,
12447 + const struct stacktrace_ops *ops,
12448 + void *data,
12449 + unsigned long *end,
12450 + int *graph);
12451
12452 -extern unsigned long
12453 -print_context_stack(struct thread_info *tinfo,
12454 - unsigned long *stack, unsigned long bp,
12455 - const struct stacktrace_ops *ops, void *data,
12456 - unsigned long *end, int *graph);
12457 -
12458 -extern unsigned long
12459 -print_context_stack_bp(struct thread_info *tinfo,
12460 - unsigned long *stack, unsigned long bp,
12461 - const struct stacktrace_ops *ops, void *data,
12462 - unsigned long *end, int *graph);
12463 +extern walk_stack_t print_context_stack;
12464 +extern walk_stack_t print_context_stack_bp;
12465
12466 /* Generic stack tracer with callbacks */
12467
12468 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12469 void (*address)(void *data, unsigned long address, int reliable);
12470 /* On negative return stop dumping */
12471 int (*stack)(void *data, char *name);
12472 - walk_stack_t walk_stack;
12473 + walk_stack_t *walk_stack;
12474 };
12475
12476 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12477 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12478 index cb23852..2dde194 100644
12479 --- a/arch/x86/include/asm/sys_ia32.h
12480 +++ b/arch/x86/include/asm/sys_ia32.h
12481 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
12482 compat_sigset_t __user *, unsigned int);
12483 asmlinkage long sys32_alarm(unsigned int);
12484
12485 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12486 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12487 asmlinkage long sys32_sysfs(int, u32, u32);
12488
12489 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12490 diff --git a/arch/x86/include/asm/syscalls.h b/arch/x86/include/asm/syscalls.h
12491 index f1d8b44..a4de8b7 100644
12492 --- a/arch/x86/include/asm/syscalls.h
12493 +++ b/arch/x86/include/asm/syscalls.h
12494 @@ -30,7 +30,7 @@ long sys_clone(unsigned long, unsigned long, void __user *,
12495 void __user *, struct pt_regs *);
12496
12497 /* kernel/ldt.c */
12498 -asmlinkage int sys_modify_ldt(int, void __user *, unsigned long);
12499 +asmlinkage int sys_modify_ldt(int, void __user *, unsigned long) __size_overflow(3);
12500
12501 /* kernel/signal.c */
12502 long sys_rt_sigreturn(struct pt_regs *);
12503 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
12504 index 2d2f01c..f985723 100644
12505 --- a/arch/x86/include/asm/system.h
12506 +++ b/arch/x86/include/asm/system.h
12507 @@ -129,7 +129,7 @@ do { \
12508 "call __switch_to\n\t" \
12509 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12510 __switch_canary \
12511 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12512 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12513 "movq %%rax,%%rdi\n\t" \
12514 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12515 "jnz ret_from_fork\n\t" \
12516 @@ -140,7 +140,7 @@ do { \
12517 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12518 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12519 [_tif_fork] "i" (_TIF_FORK), \
12520 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12521 + [thread_info] "m" (current_tinfo), \
12522 [current_task] "m" (current_task) \
12523 __switch_canary_iparam \
12524 : "memory", "cc" __EXTRA_CLOBBER)
12525 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
12526 {
12527 unsigned long __limit;
12528 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12529 - return __limit + 1;
12530 + return __limit;
12531 }
12532
12533 static inline void native_clts(void)
12534 @@ -397,13 +397,13 @@ void enable_hlt(void);
12535
12536 void cpu_idle_wait(void);
12537
12538 -extern unsigned long arch_align_stack(unsigned long sp);
12539 +#define arch_align_stack(x) ((x) & ~0xfUL)
12540 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12541
12542 void default_idle(void);
12543 bool set_pm_idle_to_default(void);
12544
12545 -void stop_this_cpu(void *dummy);
12546 +void stop_this_cpu(void *dummy) __noreturn;
12547
12548 /*
12549 * Force strict CPU ordering.
12550 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12551 index cfd8144..664ac89 100644
12552 --- a/arch/x86/include/asm/thread_info.h
12553 +++ b/arch/x86/include/asm/thread_info.h
12554 @@ -10,6 +10,7 @@
12555 #include <linux/compiler.h>
12556 #include <asm/page.h>
12557 #include <asm/types.h>
12558 +#include <asm/percpu.h>
12559
12560 /*
12561 * low level task data that entry.S needs immediate access to
12562 @@ -24,7 +25,6 @@ struct exec_domain;
12563 #include <linux/atomic.h>
12564
12565 struct thread_info {
12566 - struct task_struct *task; /* main task structure */
12567 struct exec_domain *exec_domain; /* execution domain */
12568 __u32 flags; /* low level flags */
12569 __u32 status; /* thread synchronous flags */
12570 @@ -34,19 +34,13 @@ struct thread_info {
12571 mm_segment_t addr_limit;
12572 struct restart_block restart_block;
12573 void __user *sysenter_return;
12574 -#ifdef CONFIG_X86_32
12575 - unsigned long previous_esp; /* ESP of the previous stack in
12576 - case of nested (IRQ) stacks
12577 - */
12578 - __u8 supervisor_stack[0];
12579 -#endif
12580 + unsigned long lowest_stack;
12581 unsigned int sig_on_uaccess_error:1;
12582 unsigned int uaccess_err:1; /* uaccess failed */
12583 };
12584
12585 -#define INIT_THREAD_INFO(tsk) \
12586 +#define INIT_THREAD_INFO \
12587 { \
12588 - .task = &tsk, \
12589 .exec_domain = &default_exec_domain, \
12590 .flags = 0, \
12591 .cpu = 0, \
12592 @@ -57,7 +51,7 @@ struct thread_info {
12593 }, \
12594 }
12595
12596 -#define init_thread_info (init_thread_union.thread_info)
12597 +#define init_thread_info (init_thread_union.stack)
12598 #define init_stack (init_thread_union.stack)
12599
12600 #else /* !__ASSEMBLY__ */
12601 @@ -95,6 +89,7 @@ struct thread_info {
12602 #define TIF_BLOCKSTEP 25 /* set when we want DEBUGCTLMSR_BTF */
12603 #define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */
12604 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12605 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
12606
12607 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12608 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12609 @@ -116,16 +111,17 @@ struct thread_info {
12610 #define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP)
12611 #define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES)
12612 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12613 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12614
12615 /* work to do in syscall_trace_enter() */
12616 #define _TIF_WORK_SYSCALL_ENTRY \
12617 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12618 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12619 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12620
12621 /* work to do in syscall_trace_leave() */
12622 #define _TIF_WORK_SYSCALL_EXIT \
12623 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12624 - _TIF_SYSCALL_TRACEPOINT)
12625 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12626
12627 /* work to do on interrupt/exception return */
12628 #define _TIF_WORK_MASK \
12629 @@ -135,7 +131,8 @@ struct thread_info {
12630
12631 /* work to do on any return to user space */
12632 #define _TIF_ALLWORK_MASK \
12633 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12634 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12635 + _TIF_GRSEC_SETXID)
12636
12637 /* Only used for 64 bit */
12638 #define _TIF_DO_NOTIFY_MASK \
12639 @@ -169,45 +166,40 @@ struct thread_info {
12640 ret; \
12641 })
12642
12643 -#ifdef CONFIG_X86_32
12644 -
12645 -#define STACK_WARN (THREAD_SIZE/8)
12646 -/*
12647 - * macros/functions for gaining access to the thread information structure
12648 - *
12649 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12650 - */
12651 -#ifndef __ASSEMBLY__
12652 -
12653 -
12654 -/* how to get the current stack pointer from C */
12655 -register unsigned long current_stack_pointer asm("esp") __used;
12656 -
12657 -/* how to get the thread information struct from C */
12658 -static inline struct thread_info *current_thread_info(void)
12659 -{
12660 - return (struct thread_info *)
12661 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12662 -}
12663 -
12664 -#else /* !__ASSEMBLY__ */
12665 -
12666 +#ifdef __ASSEMBLY__
12667 /* how to get the thread information struct from ASM */
12668 #define GET_THREAD_INFO(reg) \
12669 - movl $-THREAD_SIZE, reg; \
12670 - andl %esp, reg
12671 + mov PER_CPU_VAR(current_tinfo), reg
12672
12673 /* use this one if reg already contains %esp */
12674 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12675 - andl $-THREAD_SIZE, reg
12676 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12677 +#else
12678 +/* how to get the thread information struct from C */
12679 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12680 +
12681 +static __always_inline struct thread_info *current_thread_info(void)
12682 +{
12683 + return percpu_read_stable(current_tinfo);
12684 +}
12685 +#endif
12686 +
12687 +#ifdef CONFIG_X86_32
12688 +
12689 +#define STACK_WARN (THREAD_SIZE/8)
12690 +/*
12691 + * macros/functions for gaining access to the thread information structure
12692 + *
12693 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12694 + */
12695 +#ifndef __ASSEMBLY__
12696 +
12697 +/* how to get the current stack pointer from C */
12698 +register unsigned long current_stack_pointer asm("esp") __used;
12699
12700 #endif
12701
12702 #else /* X86_32 */
12703
12704 -#include <asm/percpu.h>
12705 -#define KERNEL_STACK_OFFSET (5*8)
12706 -
12707 /*
12708 * macros/functions for gaining access to the thread information structure
12709 * preempt_count needs to be 1 initially, until the scheduler is functional.
12710 @@ -215,27 +207,8 @@ static inline struct thread_info *current_thread_info(void)
12711 #ifndef __ASSEMBLY__
12712 DECLARE_PER_CPU(unsigned long, kernel_stack);
12713
12714 -static inline struct thread_info *current_thread_info(void)
12715 -{
12716 - struct thread_info *ti;
12717 - ti = (void *)(percpu_read_stable(kernel_stack) +
12718 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12719 - return ti;
12720 -}
12721 -
12722 -#else /* !__ASSEMBLY__ */
12723 -
12724 -/* how to get the thread information struct from ASM */
12725 -#define GET_THREAD_INFO(reg) \
12726 - movq PER_CPU_VAR(kernel_stack),reg ; \
12727 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12728 -
12729 -/*
12730 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12731 - * a certain register (to be used in assembler memory operands).
12732 - */
12733 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12734 -
12735 +/* how to get the current stack pointer from C */
12736 +register unsigned long current_stack_pointer asm("rsp") __used;
12737 #endif
12738
12739 #endif /* !X86_32 */
12740 @@ -269,5 +242,16 @@ extern void arch_task_cache_init(void);
12741 extern void free_thread_info(struct thread_info *ti);
12742 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12743 #define arch_task_cache_init arch_task_cache_init
12744 +
12745 +#define __HAVE_THREAD_FUNCTIONS
12746 +#define task_thread_info(task) (&(task)->tinfo)
12747 +#define task_stack_page(task) ((task)->stack)
12748 +#define setup_thread_stack(p, org) do {} while (0)
12749 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12750 +
12751 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12752 +extern struct task_struct *alloc_task_struct_node(int node);
12753 +extern void free_task_struct(struct task_struct *);
12754 +
12755 #endif
12756 #endif /* _ASM_X86_THREAD_INFO_H */
12757 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12758 index 8be5f54..7ae826d 100644
12759 --- a/arch/x86/include/asm/uaccess.h
12760 +++ b/arch/x86/include/asm/uaccess.h
12761 @@ -7,12 +7,15 @@
12762 #include <linux/compiler.h>
12763 #include <linux/thread_info.h>
12764 #include <linux/string.h>
12765 +#include <linux/sched.h>
12766 #include <asm/asm.h>
12767 #include <asm/page.h>
12768
12769 #define VERIFY_READ 0
12770 #define VERIFY_WRITE 1
12771
12772 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12773 +
12774 /*
12775 * The fs value determines whether argument validity checking should be
12776 * performed or not. If get_fs() == USER_DS, checking is performed, with
12777 @@ -28,7 +31,12 @@
12778
12779 #define get_ds() (KERNEL_DS)
12780 #define get_fs() (current_thread_info()->addr_limit)
12781 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12782 +void __set_fs(mm_segment_t x);
12783 +void set_fs(mm_segment_t x);
12784 +#else
12785 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12786 +#endif
12787
12788 #define segment_eq(a, b) ((a).seg == (b).seg)
12789
12790 @@ -76,7 +84,33 @@
12791 * checks that the pointer is in the user space range - after calling
12792 * this function, memory access functions may still return -EFAULT.
12793 */
12794 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12795 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12796 +#define access_ok(type, addr, size) \
12797 +({ \
12798 + long __size = size; \
12799 + unsigned long __addr = (unsigned long)addr; \
12800 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12801 + unsigned long __end_ao = __addr + __size - 1; \
12802 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12803 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12804 + while(__addr_ao <= __end_ao) { \
12805 + char __c_ao; \
12806 + __addr_ao += PAGE_SIZE; \
12807 + if (__size > PAGE_SIZE) \
12808 + cond_resched(); \
12809 + if (__get_user(__c_ao, (char __user *)__addr)) \
12810 + break; \
12811 + if (type != VERIFY_WRITE) { \
12812 + __addr = __addr_ao; \
12813 + continue; \
12814 + } \
12815 + if (__put_user(__c_ao, (char __user *)__addr)) \
12816 + break; \
12817 + __addr = __addr_ao; \
12818 + } \
12819 + } \
12820 + __ret_ao; \
12821 +})
12822
12823 /*
12824 * The exception table consists of pairs of addresses: the first is the
12825 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12826 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12827 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12828
12829 -
12830 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12831 +#define __copyuser_seg "gs;"
12832 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12833 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12834 +#else
12835 +#define __copyuser_seg
12836 +#define __COPYUSER_SET_ES
12837 +#define __COPYUSER_RESTORE_ES
12838 +#endif
12839
12840 #ifdef CONFIG_X86_32
12841 #define __put_user_asm_u64(x, addr, err, errret) \
12842 - asm volatile("1: movl %%eax,0(%2)\n" \
12843 - "2: movl %%edx,4(%2)\n" \
12844 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12845 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12846 "3:\n" \
12847 ".section .fixup,\"ax\"\n" \
12848 "4: movl %3,%0\n" \
12849 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12850 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12851
12852 #define __put_user_asm_ex_u64(x, addr) \
12853 - asm volatile("1: movl %%eax,0(%1)\n" \
12854 - "2: movl %%edx,4(%1)\n" \
12855 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12856 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12857 "3:\n" \
12858 _ASM_EXTABLE(1b, 2b - 1b) \
12859 _ASM_EXTABLE(2b, 3b - 2b) \
12860 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12861 __typeof__(*(ptr)) __pu_val; \
12862 __chk_user_ptr(ptr); \
12863 might_fault(); \
12864 - __pu_val = x; \
12865 + __pu_val = (x); \
12866 switch (sizeof(*(ptr))) { \
12867 case 1: \
12868 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12869 @@ -373,7 +415,7 @@ do { \
12870 } while (0)
12871
12872 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12873 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12874 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12875 "2:\n" \
12876 ".section .fixup,\"ax\"\n" \
12877 "3: mov %3,%0\n" \
12878 @@ -381,7 +423,7 @@ do { \
12879 " jmp 2b\n" \
12880 ".previous\n" \
12881 _ASM_EXTABLE(1b, 3b) \
12882 - : "=r" (err), ltype(x) \
12883 + : "=r" (err), ltype (x) \
12884 : "m" (__m(addr)), "i" (errret), "0" (err))
12885
12886 #define __get_user_size_ex(x, ptr, size) \
12887 @@ -406,7 +448,7 @@ do { \
12888 } while (0)
12889
12890 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12891 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12892 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12893 "2:\n" \
12894 _ASM_EXTABLE(1b, 2b - 1b) \
12895 : ltype(x) : "m" (__m(addr)))
12896 @@ -423,13 +465,24 @@ do { \
12897 int __gu_err; \
12898 unsigned long __gu_val; \
12899 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12900 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12901 + (x) = (__typeof__(*(ptr)))__gu_val; \
12902 __gu_err; \
12903 })
12904
12905 /* FIXME: this hack is definitely wrong -AK */
12906 struct __large_struct { unsigned long buf[100]; };
12907 -#define __m(x) (*(struct __large_struct __user *)(x))
12908 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12909 +#define ____m(x) \
12910 +({ \
12911 + unsigned long ____x = (unsigned long)(x); \
12912 + if (____x < PAX_USER_SHADOW_BASE) \
12913 + ____x += PAX_USER_SHADOW_BASE; \
12914 + (void __user *)____x; \
12915 +})
12916 +#else
12917 +#define ____m(x) (x)
12918 +#endif
12919 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12920
12921 /*
12922 * Tell gcc we read from memory instead of writing: this is because
12923 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12924 * aliasing issues.
12925 */
12926 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12927 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12928 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12929 "2:\n" \
12930 ".section .fixup,\"ax\"\n" \
12931 "3: mov %3,%0\n" \
12932 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12933 ".previous\n" \
12934 _ASM_EXTABLE(1b, 3b) \
12935 : "=r"(err) \
12936 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12937 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12938
12939 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12940 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12941 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12942 "2:\n" \
12943 _ASM_EXTABLE(1b, 2b - 1b) \
12944 : : ltype(x), "m" (__m(addr)))
12945 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12946 * On error, the variable @x is set to zero.
12947 */
12948
12949 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12950 +#define __get_user(x, ptr) get_user((x), (ptr))
12951 +#else
12952 #define __get_user(x, ptr) \
12953 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12954 +#endif
12955
12956 /**
12957 * __put_user: - Write a simple value into user space, with less checking.
12958 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12959 * Returns zero on success, or -EFAULT on error.
12960 */
12961
12962 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12963 +#define __put_user(x, ptr) put_user((x), (ptr))
12964 +#else
12965 #define __put_user(x, ptr) \
12966 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12967 +#endif
12968
12969 #define __get_user_unaligned __get_user
12970 #define __put_user_unaligned __put_user
12971 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12972 #define get_user_ex(x, ptr) do { \
12973 unsigned long __gue_val; \
12974 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12975 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12976 + (x) = (__typeof__(*(ptr)))__gue_val; \
12977 } while (0)
12978
12979 #ifdef CONFIG_X86_WP_WORKS_OK
12980 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12981 index 566e803..7183d0b 100644
12982 --- a/arch/x86/include/asm/uaccess_32.h
12983 +++ b/arch/x86/include/asm/uaccess_32.h
12984 @@ -11,15 +11,15 @@
12985 #include <asm/page.h>
12986
12987 unsigned long __must_check __copy_to_user_ll
12988 - (void __user *to, const void *from, unsigned long n);
12989 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12990 unsigned long __must_check __copy_from_user_ll
12991 - (void *to, const void __user *from, unsigned long n);
12992 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12993 unsigned long __must_check __copy_from_user_ll_nozero
12994 - (void *to, const void __user *from, unsigned long n);
12995 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12996 unsigned long __must_check __copy_from_user_ll_nocache
12997 - (void *to, const void __user *from, unsigned long n);
12998 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12999 unsigned long __must_check __copy_from_user_ll_nocache_nozero
13000 - (void *to, const void __user *from, unsigned long n);
13001 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
13002
13003 /**
13004 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
13005 @@ -41,8 +41,13 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
13006 */
13007
13008 static __always_inline unsigned long __must_check
13009 +__copy_to_user_inatomic(void __user *to, const void *from, unsigned long n) __size_overflow(3);
13010 +static __always_inline unsigned long __must_check
13011 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13012 {
13013 + if ((long)n < 0)
13014 + return n;
13015 +
13016 if (__builtin_constant_p(n)) {
13017 unsigned long ret;
13018
13019 @@ -61,6 +66,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13020 return ret;
13021 }
13022 }
13023 + if (!__builtin_constant_p(n))
13024 + check_object_size(from, n, true);
13025 return __copy_to_user_ll(to, from, n);
13026 }
13027
13028 @@ -79,15 +86,23 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
13029 * On success, this will be zero.
13030 */
13031 static __always_inline unsigned long __must_check
13032 +__copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
13033 +static __always_inline unsigned long __must_check
13034 __copy_to_user(void __user *to, const void *from, unsigned long n)
13035 {
13036 might_fault();
13037 +
13038 return __copy_to_user_inatomic(to, from, n);
13039 }
13040
13041 static __always_inline unsigned long
13042 +__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) __size_overflow(3);
13043 +static __always_inline unsigned long
13044 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
13045 {
13046 + if ((long)n < 0)
13047 + return n;
13048 +
13049 /* Avoid zeroing the tail if the copy fails..
13050 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
13051 * but as the zeroing behaviour is only significant when n is not
13052 @@ -134,9 +149,15 @@ __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
13053 * for explanation of why this is needed.
13054 */
13055 static __always_inline unsigned long
13056 +__copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
13057 +static __always_inline unsigned long
13058 __copy_from_user(void *to, const void __user *from, unsigned long n)
13059 {
13060 might_fault();
13061 +
13062 + if ((long)n < 0)
13063 + return n;
13064 +
13065 if (__builtin_constant_p(n)) {
13066 unsigned long ret;
13067
13068 @@ -152,13 +173,21 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
13069 return ret;
13070 }
13071 }
13072 + if (!__builtin_constant_p(n))
13073 + check_object_size(to, n, false);
13074 return __copy_from_user_ll(to, from, n);
13075 }
13076
13077 static __always_inline unsigned long __copy_from_user_nocache(void *to,
13078 + const void __user *from, unsigned long n) __size_overflow(3);
13079 +static __always_inline unsigned long __copy_from_user_nocache(void *to,
13080 const void __user *from, unsigned long n)
13081 {
13082 might_fault();
13083 +
13084 + if ((long)n < 0)
13085 + return n;
13086 +
13087 if (__builtin_constant_p(n)) {
13088 unsigned long ret;
13089
13090 @@ -179,17 +208,24 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
13091
13092 static __always_inline unsigned long
13093 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13094 + unsigned long n) __size_overflow(3);
13095 +static __always_inline unsigned long
13096 +__copy_from_user_inatomic_nocache(void *to, const void __user *from,
13097 unsigned long n)
13098 {
13099 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13100 + if ((long)n < 0)
13101 + return n;
13102 +
13103 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13104 }
13105
13106 -unsigned long __must_check copy_to_user(void __user *to,
13107 - const void *from, unsigned long n);
13108 -unsigned long __must_check _copy_from_user(void *to,
13109 - const void __user *from,
13110 - unsigned long n);
13111 -
13112 +extern void copy_to_user_overflow(void)
13113 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13114 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13115 +#else
13116 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13117 +#endif
13118 +;
13119
13120 extern void copy_from_user_overflow(void)
13121 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13122 @@ -199,17 +235,65 @@ extern void copy_from_user_overflow(void)
13123 #endif
13124 ;
13125
13126 -static inline unsigned long __must_check copy_from_user(void *to,
13127 - const void __user *from,
13128 - unsigned long n)
13129 +/**
13130 + * copy_to_user: - Copy a block of data into user space.
13131 + * @to: Destination address, in user space.
13132 + * @from: Source address, in kernel space.
13133 + * @n: Number of bytes to copy.
13134 + *
13135 + * Context: User context only. This function may sleep.
13136 + *
13137 + * Copy data from kernel space to user space.
13138 + *
13139 + * Returns number of bytes that could not be copied.
13140 + * On success, this will be zero.
13141 + */
13142 +static inline unsigned long __must_check
13143 +copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
13144 +static inline unsigned long __must_check
13145 +copy_to_user(void __user *to, const void *from, unsigned long n)
13146 +{
13147 + int sz = __compiletime_object_size(from);
13148 +
13149 + if (unlikely(sz != -1 && sz < n))
13150 + copy_to_user_overflow();
13151 + else if (access_ok(VERIFY_WRITE, to, n))
13152 + n = __copy_to_user(to, from, n);
13153 + return n;
13154 +}
13155 +
13156 +/**
13157 + * copy_from_user: - Copy a block of data from user space.
13158 + * @to: Destination address, in kernel space.
13159 + * @from: Source address, in user space.
13160 + * @n: Number of bytes to copy.
13161 + *
13162 + * Context: User context only. This function may sleep.
13163 + *
13164 + * Copy data from user space to kernel space.
13165 + *
13166 + * Returns number of bytes that could not be copied.
13167 + * On success, this will be zero.
13168 + *
13169 + * If some data could not be copied, this function will pad the copied
13170 + * data to the requested size using zero bytes.
13171 + */
13172 +static inline unsigned long __must_check
13173 +copy_from_user(void *to, const void __user *from, unsigned long n) __size_overflow(3);
13174 +static inline unsigned long __must_check
13175 +copy_from_user(void *to, const void __user *from, unsigned long n)
13176 {
13177 int sz = __compiletime_object_size(to);
13178
13179 - if (likely(sz == -1 || sz >= n))
13180 - n = _copy_from_user(to, from, n);
13181 - else
13182 + if (unlikely(sz != -1 && sz < n))
13183 copy_from_user_overflow();
13184 -
13185 + else if (access_ok(VERIFY_READ, from, n))
13186 + n = __copy_from_user(to, from, n);
13187 + else if ((long)n > 0) {
13188 + if (!__builtin_constant_p(n))
13189 + check_object_size(to, n, false);
13190 + memset(to, 0, n);
13191 + }
13192 return n;
13193 }
13194
13195 @@ -235,7 +319,7 @@ long __must_check __strncpy_from_user(char *dst,
13196 #define strlen_user(str) strnlen_user(str, LONG_MAX)
13197
13198 long strnlen_user(const char __user *str, long n);
13199 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13200 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13201 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13202 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13203
13204 #endif /* _ASM_X86_UACCESS_32_H */
13205 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13206 index 1c66d30..e294b5f 100644
13207 --- a/arch/x86/include/asm/uaccess_64.h
13208 +++ b/arch/x86/include/asm/uaccess_64.h
13209 @@ -10,6 +10,9 @@
13210 #include <asm/alternative.h>
13211 #include <asm/cpufeature.h>
13212 #include <asm/page.h>
13213 +#include <asm/pgtable.h>
13214 +
13215 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13216
13217 /*
13218 * Copy To/From Userspace
13219 @@ -17,12 +20,14 @@
13220
13221 /* Handles exceptions in both to and from, but doesn't do access_ok */
13222 __must_check unsigned long
13223 -copy_user_generic_string(void *to, const void *from, unsigned len);
13224 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13225 __must_check unsigned long
13226 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13227 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13228
13229 static __always_inline __must_check unsigned long
13230 -copy_user_generic(void *to, const void *from, unsigned len)
13231 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13232 +static __always_inline __must_check unsigned long
13233 +copy_user_generic(void *to, const void *from, unsigned long len)
13234 {
13235 unsigned ret;
13236
13237 @@ -32,142 +37,237 @@ copy_user_generic(void *to, const void *from, unsigned len)
13238 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13239 "=d" (len)),
13240 "1" (to), "2" (from), "3" (len)
13241 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13242 + : "memory", "rcx", "r8", "r9", "r11");
13243 return ret;
13244 }
13245
13246 +static __always_inline __must_check unsigned long
13247 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13248 +static __always_inline __must_check unsigned long
13249 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13250 __must_check unsigned long
13251 -_copy_to_user(void __user *to, const void *from, unsigned len);
13252 -__must_check unsigned long
13253 -_copy_from_user(void *to, const void __user *from, unsigned len);
13254 -__must_check unsigned long
13255 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13256 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13257
13258 static inline unsigned long __must_check copy_from_user(void *to,
13259 const void __user *from,
13260 + unsigned long n) __size_overflow(3);
13261 +static inline unsigned long __must_check copy_from_user(void *to,
13262 + const void __user *from,
13263 unsigned long n)
13264 {
13265 - int sz = __compiletime_object_size(to);
13266 -
13267 might_fault();
13268 - if (likely(sz == -1 || sz >= n))
13269 - n = _copy_from_user(to, from, n);
13270 -#ifdef CONFIG_DEBUG_VM
13271 - else
13272 - WARN(1, "Buffer overflow detected!\n");
13273 -#endif
13274 +
13275 + if (access_ok(VERIFY_READ, from, n))
13276 + n = __copy_from_user(to, from, n);
13277 + else if (n < INT_MAX) {
13278 + if (!__builtin_constant_p(n))
13279 + check_object_size(to, n, false);
13280 + memset(to, 0, n);
13281 + }
13282 return n;
13283 }
13284
13285 static __always_inline __must_check
13286 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13287 +int copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
13288 +static __always_inline __must_check
13289 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13290 {
13291 might_fault();
13292
13293 - return _copy_to_user(dst, src, size);
13294 + if (access_ok(VERIFY_WRITE, dst, size))
13295 + size = __copy_to_user(dst, src, size);
13296 + return size;
13297 }
13298
13299 static __always_inline __must_check
13300 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13301 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
13302 +static __always_inline __must_check
13303 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13304 {
13305 - int ret = 0;
13306 + int sz = __compiletime_object_size(dst);
13307 + unsigned ret = 0;
13308
13309 might_fault();
13310 - if (!__builtin_constant_p(size))
13311 - return copy_user_generic(dst, (__force void *)src, size);
13312 +
13313 + if (size > INT_MAX)
13314 + return size;
13315 +
13316 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13317 + if (!__access_ok(VERIFY_READ, src, size))
13318 + return size;
13319 +#endif
13320 +
13321 + if (unlikely(sz != -1 && sz < size)) {
13322 +#ifdef CONFIG_DEBUG_VM
13323 + WARN(1, "Buffer overflow detected!\n");
13324 +#endif
13325 + return size;
13326 + }
13327 +
13328 + if (!__builtin_constant_p(size)) {
13329 + check_object_size(dst, size, false);
13330 +
13331 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13332 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13333 + src += PAX_USER_SHADOW_BASE;
13334 +#endif
13335 +
13336 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13337 + }
13338 switch (size) {
13339 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13340 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13341 ret, "b", "b", "=q", 1);
13342 return ret;
13343 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13344 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13345 ret, "w", "w", "=r", 2);
13346 return ret;
13347 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13348 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13349 ret, "l", "k", "=r", 4);
13350 return ret;
13351 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13352 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13353 ret, "q", "", "=r", 8);
13354 return ret;
13355 case 10:
13356 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13357 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13358 ret, "q", "", "=r", 10);
13359 if (unlikely(ret))
13360 return ret;
13361 __get_user_asm(*(u16 *)(8 + (char *)dst),
13362 - (u16 __user *)(8 + (char __user *)src),
13363 + (const u16 __user *)(8 + (const char __user *)src),
13364 ret, "w", "w", "=r", 2);
13365 return ret;
13366 case 16:
13367 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13368 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13369 ret, "q", "", "=r", 16);
13370 if (unlikely(ret))
13371 return ret;
13372 __get_user_asm(*(u64 *)(8 + (char *)dst),
13373 - (u64 __user *)(8 + (char __user *)src),
13374 + (const u64 __user *)(8 + (const char __user *)src),
13375 ret, "q", "", "=r", 8);
13376 return ret;
13377 default:
13378 - return copy_user_generic(dst, (__force void *)src, size);
13379 +
13380 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13381 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13382 + src += PAX_USER_SHADOW_BASE;
13383 +#endif
13384 +
13385 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13386 }
13387 }
13388
13389 static __always_inline __must_check
13390 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13391 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
13392 +static __always_inline __must_check
13393 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13394 {
13395 - int ret = 0;
13396 + int sz = __compiletime_object_size(src);
13397 + unsigned ret = 0;
13398
13399 might_fault();
13400 - if (!__builtin_constant_p(size))
13401 - return copy_user_generic((__force void *)dst, src, size);
13402 +
13403 + if (size > INT_MAX)
13404 + return size;
13405 +
13406 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13407 + if (!__access_ok(VERIFY_WRITE, dst, size))
13408 + return size;
13409 +#endif
13410 +
13411 + if (unlikely(sz != -1 && sz < size)) {
13412 +#ifdef CONFIG_DEBUG_VM
13413 + WARN(1, "Buffer overflow detected!\n");
13414 +#endif
13415 + return size;
13416 + }
13417 +
13418 + if (!__builtin_constant_p(size)) {
13419 + check_object_size(src, size, true);
13420 +
13421 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13422 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13423 + dst += PAX_USER_SHADOW_BASE;
13424 +#endif
13425 +
13426 + return copy_user_generic((__force_kernel void *)dst, src, size);
13427 + }
13428 switch (size) {
13429 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13430 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13431 ret, "b", "b", "iq", 1);
13432 return ret;
13433 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13434 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13435 ret, "w", "w", "ir", 2);
13436 return ret;
13437 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13438 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13439 ret, "l", "k", "ir", 4);
13440 return ret;
13441 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13442 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13443 ret, "q", "", "er", 8);
13444 return ret;
13445 case 10:
13446 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13447 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13448 ret, "q", "", "er", 10);
13449 if (unlikely(ret))
13450 return ret;
13451 asm("":::"memory");
13452 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13453 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13454 ret, "w", "w", "ir", 2);
13455 return ret;
13456 case 16:
13457 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13458 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13459 ret, "q", "", "er", 16);
13460 if (unlikely(ret))
13461 return ret;
13462 asm("":::"memory");
13463 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13464 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13465 ret, "q", "", "er", 8);
13466 return ret;
13467 default:
13468 - return copy_user_generic((__force void *)dst, src, size);
13469 +
13470 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13471 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13472 + dst += PAX_USER_SHADOW_BASE;
13473 +#endif
13474 +
13475 + return copy_user_generic((__force_kernel void *)dst, src, size);
13476 }
13477 }
13478
13479 static __always_inline __must_check
13480 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13481 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size) __size_overflow(3);
13482 +static __always_inline __must_check
13483 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13484 {
13485 - int ret = 0;
13486 + unsigned ret = 0;
13487
13488 might_fault();
13489 - if (!__builtin_constant_p(size))
13490 - return copy_user_generic((__force void *)dst,
13491 - (__force void *)src, size);
13492 +
13493 + if (size > INT_MAX)
13494 + return size;
13495 +
13496 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13497 + if (!__access_ok(VERIFY_READ, src, size))
13498 + return size;
13499 + if (!__access_ok(VERIFY_WRITE, dst, size))
13500 + return size;
13501 +#endif
13502 +
13503 + if (!__builtin_constant_p(size)) {
13504 +
13505 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13506 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13507 + src += PAX_USER_SHADOW_BASE;
13508 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13509 + dst += PAX_USER_SHADOW_BASE;
13510 +#endif
13511 +
13512 + return copy_user_generic((__force_kernel void *)dst,
13513 + (__force_kernel const void *)src, size);
13514 + }
13515 switch (size) {
13516 case 1: {
13517 u8 tmp;
13518 - __get_user_asm(tmp, (u8 __user *)src,
13519 + __get_user_asm(tmp, (const u8 __user *)src,
13520 ret, "b", "b", "=q", 1);
13521 if (likely(!ret))
13522 __put_user_asm(tmp, (u8 __user *)dst,
13523 @@ -176,7 +276,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13524 }
13525 case 2: {
13526 u16 tmp;
13527 - __get_user_asm(tmp, (u16 __user *)src,
13528 + __get_user_asm(tmp, (const u16 __user *)src,
13529 ret, "w", "w", "=r", 2);
13530 if (likely(!ret))
13531 __put_user_asm(tmp, (u16 __user *)dst,
13532 @@ -186,7 +286,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13533
13534 case 4: {
13535 u32 tmp;
13536 - __get_user_asm(tmp, (u32 __user *)src,
13537 + __get_user_asm(tmp, (const u32 __user *)src,
13538 ret, "l", "k", "=r", 4);
13539 if (likely(!ret))
13540 __put_user_asm(tmp, (u32 __user *)dst,
13541 @@ -195,7 +295,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13542 }
13543 case 8: {
13544 u64 tmp;
13545 - __get_user_asm(tmp, (u64 __user *)src,
13546 + __get_user_asm(tmp, (const u64 __user *)src,
13547 ret, "q", "", "=r", 8);
13548 if (likely(!ret))
13549 __put_user_asm(tmp, (u64 __user *)dst,
13550 @@ -203,8 +303,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13551 return ret;
13552 }
13553 default:
13554 - return copy_user_generic((__force void *)dst,
13555 - (__force void *)src, size);
13556 +
13557 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13558 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13559 + src += PAX_USER_SHADOW_BASE;
13560 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13561 + dst += PAX_USER_SHADOW_BASE;
13562 +#endif
13563 +
13564 + return copy_user_generic((__force_kernel void *)dst,
13565 + (__force_kernel const void *)src, size);
13566 }
13567 }
13568
13569 @@ -215,39 +323,83 @@ __strncpy_from_user(char *dst, const char __user *src, long count);
13570 __must_check long strnlen_user(const char __user *str, long n);
13571 __must_check long __strnlen_user(const char __user *str, long n);
13572 __must_check long strlen_user(const char __user *str);
13573 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13574 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13575 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13576 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13577
13578 static __must_check __always_inline int
13579 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13580 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
13581 +static __must_check __always_inline int
13582 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13583 {
13584 - return copy_user_generic(dst, (__force const void *)src, size);
13585 + if (size > INT_MAX)
13586 + return size;
13587 +
13588 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13589 + if (!__access_ok(VERIFY_READ, src, size))
13590 + return size;
13591 +
13592 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13593 + src += PAX_USER_SHADOW_BASE;
13594 +#endif
13595 +
13596 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13597 }
13598
13599 -static __must_check __always_inline int
13600 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13601 +static __must_check __always_inline unsigned long
13602 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size) __size_overflow(3);
13603 +static __must_check __always_inline unsigned long
13604 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13605 {
13606 - return copy_user_generic((__force void *)dst, src, size);
13607 + if (size > INT_MAX)
13608 + return size;
13609 +
13610 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13611 + if (!__access_ok(VERIFY_WRITE, dst, size))
13612 + return size;
13613 +
13614 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13615 + dst += PAX_USER_SHADOW_BASE;
13616 +#endif
13617 +
13618 + return copy_user_generic((__force_kernel void *)dst, src, size);
13619 }
13620
13621 -extern long __copy_user_nocache(void *dst, const void __user *src,
13622 - unsigned size, int zerorest);
13623 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13624 + unsigned long size, int zerorest) __size_overflow(3);
13625
13626 -static inline int
13627 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13628 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size) __size_overflow(3);
13629 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13630 {
13631 might_sleep();
13632 +
13633 + if (size > INT_MAX)
13634 + return size;
13635 +
13636 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13637 + if (!__access_ok(VERIFY_READ, src, size))
13638 + return size;
13639 +#endif
13640 +
13641 return __copy_user_nocache(dst, src, size, 1);
13642 }
13643
13644 -static inline int
13645 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13646 - unsigned size)
13647 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13648 + unsigned long size) __size_overflow(3);
13649 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13650 + unsigned long size)
13651 {
13652 + if (size > INT_MAX)
13653 + return size;
13654 +
13655 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13656 + if (!__access_ok(VERIFY_READ, src, size))
13657 + return size;
13658 +#endif
13659 +
13660 return __copy_user_nocache(dst, src, size, 0);
13661 }
13662
13663 -unsigned long
13664 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13665 +extern unsigned long
13666 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13667
13668 #endif /* _ASM_X86_UACCESS_64_H */
13669 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13670 index bb05228..d763d5b 100644
13671 --- a/arch/x86/include/asm/vdso.h
13672 +++ b/arch/x86/include/asm/vdso.h
13673 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13674 #define VDSO32_SYMBOL(base, name) \
13675 ({ \
13676 extern const char VDSO32_##name[]; \
13677 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13678 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13679 })
13680 #endif
13681
13682 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13683 index a609c39..7a68dc7 100644
13684 --- a/arch/x86/include/asm/x86_init.h
13685 +++ b/arch/x86/include/asm/x86_init.h
13686 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13687 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13688 void (*find_smp_config)(void);
13689 void (*get_smp_config)(unsigned int early);
13690 -};
13691 +} __no_const;
13692
13693 /**
13694 * struct x86_init_resources - platform specific resource related ops
13695 @@ -43,7 +43,7 @@ struct x86_init_resources {
13696 void (*probe_roms)(void);
13697 void (*reserve_resources)(void);
13698 char *(*memory_setup)(void);
13699 -};
13700 +} __no_const;
13701
13702 /**
13703 * struct x86_init_irqs - platform specific interrupt setup
13704 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13705 void (*pre_vector_init)(void);
13706 void (*intr_init)(void);
13707 void (*trap_init)(void);
13708 -};
13709 +} __no_const;
13710
13711 /**
13712 * struct x86_init_oem - oem platform specific customizing functions
13713 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13714 struct x86_init_oem {
13715 void (*arch_setup)(void);
13716 void (*banner)(void);
13717 -};
13718 +} __no_const;
13719
13720 /**
13721 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13722 @@ -77,7 +77,7 @@ struct x86_init_oem {
13723 */
13724 struct x86_init_mapping {
13725 void (*pagetable_reserve)(u64 start, u64 end);
13726 -};
13727 +} __no_const;
13728
13729 /**
13730 * struct x86_init_paging - platform specific paging functions
13731 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13732 struct x86_init_paging {
13733 void (*pagetable_setup_start)(pgd_t *base);
13734 void (*pagetable_setup_done)(pgd_t *base);
13735 -};
13736 +} __no_const;
13737
13738 /**
13739 * struct x86_init_timers - platform specific timer setup
13740 @@ -102,7 +102,7 @@ struct x86_init_timers {
13741 void (*tsc_pre_init)(void);
13742 void (*timer_init)(void);
13743 void (*wallclock_init)(void);
13744 -};
13745 +} __no_const;
13746
13747 /**
13748 * struct x86_init_iommu - platform specific iommu setup
13749 @@ -110,7 +110,7 @@ struct x86_init_timers {
13750 */
13751 struct x86_init_iommu {
13752 int (*iommu_init)(void);
13753 -};
13754 +} __no_const;
13755
13756 /**
13757 * struct x86_init_pci - platform specific pci init functions
13758 @@ -124,7 +124,7 @@ struct x86_init_pci {
13759 int (*init)(void);
13760 void (*init_irq)(void);
13761 void (*fixup_irqs)(void);
13762 -};
13763 +} __no_const;
13764
13765 /**
13766 * struct x86_init_ops - functions for platform specific setup
13767 @@ -140,7 +140,7 @@ struct x86_init_ops {
13768 struct x86_init_timers timers;
13769 struct x86_init_iommu iommu;
13770 struct x86_init_pci pci;
13771 -};
13772 +} __no_const;
13773
13774 /**
13775 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13776 @@ -149,7 +149,7 @@ struct x86_init_ops {
13777 struct x86_cpuinit_ops {
13778 void (*setup_percpu_clockev)(void);
13779 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13780 -};
13781 +} __no_const;
13782
13783 /**
13784 * struct x86_platform_ops - platform specific runtime functions
13785 @@ -171,7 +171,7 @@ struct x86_platform_ops {
13786 void (*nmi_init)(void);
13787 unsigned char (*get_nmi_reason)(void);
13788 int (*i8042_detect)(void);
13789 -};
13790 +} __no_const;
13791
13792 struct pci_dev;
13793
13794 @@ -180,7 +180,7 @@ struct x86_msi_ops {
13795 void (*teardown_msi_irq)(unsigned int irq);
13796 void (*teardown_msi_irqs)(struct pci_dev *dev);
13797 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13798 -};
13799 +} __no_const;
13800
13801 extern struct x86_init_ops x86_init;
13802 extern struct x86_cpuinit_ops x86_cpuinit;
13803 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13804 index c6ce245..ffbdab7 100644
13805 --- a/arch/x86/include/asm/xsave.h
13806 +++ b/arch/x86/include/asm/xsave.h
13807 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13808 {
13809 int err;
13810
13811 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13812 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13813 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13814 +#endif
13815 +
13816 /*
13817 * Clear the xsave header first, so that reserved fields are
13818 * initialized to zero.
13819 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13820 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13821 {
13822 int err;
13823 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13824 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13825 u32 lmask = mask;
13826 u32 hmask = mask >> 32;
13827
13828 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13829 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13830 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13831 +#endif
13832 +
13833 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13834 "2:\n"
13835 ".section .fixup,\"ax\"\n"
13836 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13837 index 6a564ac..9b1340c 100644
13838 --- a/arch/x86/kernel/acpi/realmode/Makefile
13839 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13840 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13841 $(call cc-option, -fno-stack-protector) \
13842 $(call cc-option, -mpreferred-stack-boundary=2)
13843 KBUILD_CFLAGS += $(call cc-option, -m32)
13844 +ifdef CONSTIFY_PLUGIN
13845 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13846 +endif
13847 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13848 GCOV_PROFILE := n
13849
13850 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13851 index b4fd836..4358fe3 100644
13852 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13853 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13854 @@ -108,6 +108,9 @@ wakeup_code:
13855 /* Do any other stuff... */
13856
13857 #ifndef CONFIG_64BIT
13858 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13859 + call verify_cpu
13860 +
13861 /* This could also be done in C code... */
13862 movl pmode_cr3, %eax
13863 movl %eax, %cr3
13864 @@ -131,6 +134,7 @@ wakeup_code:
13865 movl pmode_cr0, %eax
13866 movl %eax, %cr0
13867 jmp pmode_return
13868 +# include "../../verify_cpu.S"
13869 #else
13870 pushw $0
13871 pushw trampoline_segment
13872 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13873 index 103b6ab..2004d0a 100644
13874 --- a/arch/x86/kernel/acpi/sleep.c
13875 +++ b/arch/x86/kernel/acpi/sleep.c
13876 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13877 header->trampoline_segment = trampoline_address() >> 4;
13878 #ifdef CONFIG_SMP
13879 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13880 +
13881 + pax_open_kernel();
13882 early_gdt_descr.address =
13883 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13884 + pax_close_kernel();
13885 +
13886 initial_gs = per_cpu_offset(smp_processor_id());
13887 #endif
13888 initial_code = (unsigned long)wakeup_long64;
13889 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13890 index 13ab720..95d5442 100644
13891 --- a/arch/x86/kernel/acpi/wakeup_32.S
13892 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13893 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13894 # and restore the stack ... but you need gdt for this to work
13895 movl saved_context_esp, %esp
13896
13897 - movl %cs:saved_magic, %eax
13898 - cmpl $0x12345678, %eax
13899 + cmpl $0x12345678, saved_magic
13900 jne bogus_magic
13901
13902 # jump to place where we left off
13903 - movl saved_eip, %eax
13904 - jmp *%eax
13905 + jmp *(saved_eip)
13906
13907 bogus_magic:
13908 jmp bogus_magic
13909 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13910 index 1f84794..e23f862 100644
13911 --- a/arch/x86/kernel/alternative.c
13912 +++ b/arch/x86/kernel/alternative.c
13913 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13914 */
13915 for (a = start; a < end; a++) {
13916 instr = (u8 *)&a->instr_offset + a->instr_offset;
13917 +
13918 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13919 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13920 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13921 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13922 +#endif
13923 +
13924 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13925 BUG_ON(a->replacementlen > a->instrlen);
13926 BUG_ON(a->instrlen > sizeof(insnbuf));
13927 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13928 for (poff = start; poff < end; poff++) {
13929 u8 *ptr = (u8 *)poff + *poff;
13930
13931 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13932 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13933 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13934 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13935 +#endif
13936 +
13937 if (!*poff || ptr < text || ptr >= text_end)
13938 continue;
13939 /* turn DS segment override prefix into lock prefix */
13940 - if (*ptr == 0x3e)
13941 + if (*ktla_ktva(ptr) == 0x3e)
13942 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13943 };
13944 mutex_unlock(&text_mutex);
13945 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13946 for (poff = start; poff < end; poff++) {
13947 u8 *ptr = (u8 *)poff + *poff;
13948
13949 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13950 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13951 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13952 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13953 +#endif
13954 +
13955 if (!*poff || ptr < text || ptr >= text_end)
13956 continue;
13957 /* turn lock prefix into DS segment override prefix */
13958 - if (*ptr == 0xf0)
13959 + if (*ktla_ktva(ptr) == 0xf0)
13960 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13961 };
13962 mutex_unlock(&text_mutex);
13963 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13964
13965 BUG_ON(p->len > MAX_PATCH_LEN);
13966 /* prep the buffer with the original instructions */
13967 - memcpy(insnbuf, p->instr, p->len);
13968 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13969 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13970 (unsigned long)p->instr, p->len);
13971
13972 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13973 if (smp_alt_once)
13974 free_init_pages("SMP alternatives",
13975 (unsigned long)__smp_locks,
13976 - (unsigned long)__smp_locks_end);
13977 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13978
13979 restart_nmi();
13980 }
13981 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13982 * instructions. And on the local CPU you need to be protected again NMI or MCE
13983 * handlers seeing an inconsistent instruction while you patch.
13984 */
13985 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13986 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13987 size_t len)
13988 {
13989 unsigned long flags;
13990 local_irq_save(flags);
13991 - memcpy(addr, opcode, len);
13992 +
13993 + pax_open_kernel();
13994 + memcpy(ktla_ktva(addr), opcode, len);
13995 sync_core();
13996 + pax_close_kernel();
13997 +
13998 local_irq_restore(flags);
13999 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14000 that causes hangs on some VIA CPUs. */
14001 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14002 */
14003 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14004 {
14005 - unsigned long flags;
14006 - char *vaddr;
14007 + unsigned char *vaddr = ktla_ktva(addr);
14008 struct page *pages[2];
14009 - int i;
14010 + size_t i;
14011
14012 if (!core_kernel_text((unsigned long)addr)) {
14013 - pages[0] = vmalloc_to_page(addr);
14014 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14015 + pages[0] = vmalloc_to_page(vaddr);
14016 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14017 } else {
14018 - pages[0] = virt_to_page(addr);
14019 + pages[0] = virt_to_page(vaddr);
14020 WARN_ON(!PageReserved(pages[0]));
14021 - pages[1] = virt_to_page(addr + PAGE_SIZE);
14022 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14023 }
14024 BUG_ON(!pages[0]);
14025 - local_irq_save(flags);
14026 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14027 - if (pages[1])
14028 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
14029 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
14030 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14031 - clear_fixmap(FIX_TEXT_POKE0);
14032 - if (pages[1])
14033 - clear_fixmap(FIX_TEXT_POKE1);
14034 - local_flush_tlb();
14035 - sync_core();
14036 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
14037 - that causes hangs on some VIA CPUs. */
14038 + text_poke_early(addr, opcode, len);
14039 for (i = 0; i < len; i++)
14040 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14041 - local_irq_restore(flags);
14042 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14043 return addr;
14044 }
14045
14046 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14047 index 5b3f88e..61232b4 100644
14048 --- a/arch/x86/kernel/apic/apic.c
14049 +++ b/arch/x86/kernel/apic/apic.c
14050 @@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
14051 /*
14052 * Debug level, exported for io_apic.c
14053 */
14054 -unsigned int apic_verbosity;
14055 +int apic_verbosity;
14056
14057 int pic_mode;
14058
14059 @@ -1912,7 +1912,7 @@ void smp_error_interrupt(struct pt_regs *regs)
14060 apic_write(APIC_ESR, 0);
14061 v1 = apic_read(APIC_ESR);
14062 ack_APIC_irq();
14063 - atomic_inc(&irq_err_count);
14064 + atomic_inc_unchecked(&irq_err_count);
14065
14066 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
14067 smp_processor_id(), v0 , v1);
14068 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
14069 index fb07275..e06bb59 100644
14070 --- a/arch/x86/kernel/apic/io_apic.c
14071 +++ b/arch/x86/kernel/apic/io_apic.c
14072 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
14073 }
14074 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
14075
14076 -void lock_vector_lock(void)
14077 +void lock_vector_lock(void) __acquires(vector_lock)
14078 {
14079 /* Used to the online set of cpus does not change
14080 * during assign_irq_vector.
14081 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
14082 raw_spin_lock(&vector_lock);
14083 }
14084
14085 -void unlock_vector_lock(void)
14086 +void unlock_vector_lock(void) __releases(vector_lock)
14087 {
14088 raw_spin_unlock(&vector_lock);
14089 }
14090 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
14091 ack_APIC_irq();
14092 }
14093
14094 -atomic_t irq_mis_count;
14095 +atomic_unchecked_t irq_mis_count;
14096
14097 static void ack_apic_level(struct irq_data *data)
14098 {
14099 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
14100 * at the cpu.
14101 */
14102 if (!(v & (1 << (i & 0x1f)))) {
14103 - atomic_inc(&irq_mis_count);
14104 + atomic_inc_unchecked(&irq_mis_count);
14105
14106 eoi_ioapic_irq(irq, cfg);
14107 }
14108 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14109 index f76623c..aab694f 100644
14110 --- a/arch/x86/kernel/apm_32.c
14111 +++ b/arch/x86/kernel/apm_32.c
14112 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
14113 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14114 * even though they are called in protected mode.
14115 */
14116 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14117 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14118 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14119
14120 static const char driver_version[] = "1.16ac"; /* no spaces */
14121 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
14122 BUG_ON(cpu != 0);
14123 gdt = get_cpu_gdt_table(cpu);
14124 save_desc_40 = gdt[0x40 / 8];
14125 +
14126 + pax_open_kernel();
14127 gdt[0x40 / 8] = bad_bios_desc;
14128 + pax_close_kernel();
14129
14130 apm_irq_save(flags);
14131 APM_DO_SAVE_SEGS;
14132 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
14133 &call->esi);
14134 APM_DO_RESTORE_SEGS;
14135 apm_irq_restore(flags);
14136 +
14137 + pax_open_kernel();
14138 gdt[0x40 / 8] = save_desc_40;
14139 + pax_close_kernel();
14140 +
14141 put_cpu();
14142
14143 return call->eax & 0xff;
14144 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
14145 BUG_ON(cpu != 0);
14146 gdt = get_cpu_gdt_table(cpu);
14147 save_desc_40 = gdt[0x40 / 8];
14148 +
14149 + pax_open_kernel();
14150 gdt[0x40 / 8] = bad_bios_desc;
14151 + pax_close_kernel();
14152
14153 apm_irq_save(flags);
14154 APM_DO_SAVE_SEGS;
14155 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
14156 &call->eax);
14157 APM_DO_RESTORE_SEGS;
14158 apm_irq_restore(flags);
14159 +
14160 + pax_open_kernel();
14161 gdt[0x40 / 8] = save_desc_40;
14162 + pax_close_kernel();
14163 +
14164 put_cpu();
14165 return error;
14166 }
14167 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
14168 * code to that CPU.
14169 */
14170 gdt = get_cpu_gdt_table(0);
14171 +
14172 + pax_open_kernel();
14173 set_desc_base(&gdt[APM_CS >> 3],
14174 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14175 set_desc_base(&gdt[APM_CS_16 >> 3],
14176 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14177 set_desc_base(&gdt[APM_DS >> 3],
14178 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14179 + pax_close_kernel();
14180
14181 proc_create("apm", 0, NULL, &apm_file_ops);
14182
14183 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14184 index 68de2dc..1f3c720 100644
14185 --- a/arch/x86/kernel/asm-offsets.c
14186 +++ b/arch/x86/kernel/asm-offsets.c
14187 @@ -33,6 +33,8 @@ void common(void) {
14188 OFFSET(TI_status, thread_info, status);
14189 OFFSET(TI_addr_limit, thread_info, addr_limit);
14190 OFFSET(TI_preempt_count, thread_info, preempt_count);
14191 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14192 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14193
14194 BLANK();
14195 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14196 @@ -53,8 +55,26 @@ void common(void) {
14197 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14198 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14199 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14200 +
14201 +#ifdef CONFIG_PAX_KERNEXEC
14202 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14203 #endif
14204
14205 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14206 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14207 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14208 +#ifdef CONFIG_X86_64
14209 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14210 +#endif
14211 +#endif
14212 +
14213 +#endif
14214 +
14215 + BLANK();
14216 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14217 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14218 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14219 +
14220 #ifdef CONFIG_XEN
14221 BLANK();
14222 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14223 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14224 index 834e897..dacddc8 100644
14225 --- a/arch/x86/kernel/asm-offsets_64.c
14226 +++ b/arch/x86/kernel/asm-offsets_64.c
14227 @@ -70,6 +70,7 @@ int main(void)
14228 BLANK();
14229 #undef ENTRY
14230
14231 + DEFINE(TSS_size, sizeof(struct tss_struct));
14232 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14233 BLANK();
14234
14235 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14236 index 25f24dc..4094a7f 100644
14237 --- a/arch/x86/kernel/cpu/Makefile
14238 +++ b/arch/x86/kernel/cpu/Makefile
14239 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14240 CFLAGS_REMOVE_perf_event.o = -pg
14241 endif
14242
14243 -# Make sure load_percpu_segment has no stackprotector
14244 -nostackp := $(call cc-option, -fno-stack-protector)
14245 -CFLAGS_common.o := $(nostackp)
14246 -
14247 obj-y := intel_cacheinfo.o scattered.o topology.o
14248 obj-y += proc.o capflags.o powerflags.o common.o
14249 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14250 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14251 index 80ab83d..0a7b34e 100644
14252 --- a/arch/x86/kernel/cpu/amd.c
14253 +++ b/arch/x86/kernel/cpu/amd.c
14254 @@ -670,7 +670,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14255 unsigned int size)
14256 {
14257 /* AMD errata T13 (order #21922) */
14258 - if ((c->x86 == 6)) {
14259 + if (c->x86 == 6) {
14260 /* Duron Rev A0 */
14261 if (c->x86_model == 3 && c->x86_mask == 0)
14262 size = 64;
14263 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14264 index 1a810e4..9fa8201 100644
14265 --- a/arch/x86/kernel/cpu/common.c
14266 +++ b/arch/x86/kernel/cpu/common.c
14267 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14268
14269 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14270
14271 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14272 -#ifdef CONFIG_X86_64
14273 - /*
14274 - * We need valid kernel segments for data and code in long mode too
14275 - * IRET will check the segment types kkeil 2000/10/28
14276 - * Also sysret mandates a special GDT layout
14277 - *
14278 - * TLS descriptors are currently at a different place compared to i386.
14279 - * Hopefully nobody expects them at a fixed place (Wine?)
14280 - */
14281 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14282 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14283 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14284 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14285 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14286 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14287 -#else
14288 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14289 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14290 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14291 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14292 - /*
14293 - * Segments used for calling PnP BIOS have byte granularity.
14294 - * They code segments and data segments have fixed 64k limits,
14295 - * the transfer segment sizes are set at run time.
14296 - */
14297 - /* 32-bit code */
14298 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14299 - /* 16-bit code */
14300 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14301 - /* 16-bit data */
14302 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14303 - /* 16-bit data */
14304 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14305 - /* 16-bit data */
14306 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14307 - /*
14308 - * The APM segments have byte granularity and their bases
14309 - * are set at run time. All have 64k limits.
14310 - */
14311 - /* 32-bit code */
14312 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14313 - /* 16-bit code */
14314 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14315 - /* data */
14316 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14317 -
14318 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14319 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14320 - GDT_STACK_CANARY_INIT
14321 -#endif
14322 -} };
14323 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14324 -
14325 static int __init x86_xsave_setup(char *s)
14326 {
14327 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14328 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
14329 {
14330 struct desc_ptr gdt_descr;
14331
14332 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14333 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14334 gdt_descr.size = GDT_SIZE - 1;
14335 load_gdt(&gdt_descr);
14336 /* Reload the per-cpu base */
14337 @@ -839,6 +785,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14338 /* Filter out anything that depends on CPUID levels we don't have */
14339 filter_cpuid_features(c, true);
14340
14341 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14342 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14343 +#endif
14344 +
14345 /* If the model name is still unset, do table lookup. */
14346 if (!c->x86_model_id[0]) {
14347 const char *p;
14348 @@ -1019,10 +969,12 @@ static __init int setup_disablecpuid(char *arg)
14349 }
14350 __setup("clearcpuid=", setup_disablecpuid);
14351
14352 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14353 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14354 +
14355 #ifdef CONFIG_X86_64
14356 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14357 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14358 - (unsigned long) nmi_idt_table };
14359 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14360
14361 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14362 irq_stack_union) __aligned(PAGE_SIZE);
14363 @@ -1036,7 +988,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14364 EXPORT_PER_CPU_SYMBOL(current_task);
14365
14366 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14367 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14368 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14369 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14370
14371 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14372 @@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14373 {
14374 memset(regs, 0, sizeof(struct pt_regs));
14375 regs->fs = __KERNEL_PERCPU;
14376 - regs->gs = __KERNEL_STACK_CANARY;
14377 + savesegment(gs, regs->gs);
14378
14379 return regs;
14380 }
14381 @@ -1181,7 +1133,7 @@ void __cpuinit cpu_init(void)
14382 int i;
14383
14384 cpu = stack_smp_processor_id();
14385 - t = &per_cpu(init_tss, cpu);
14386 + t = init_tss + cpu;
14387 oist = &per_cpu(orig_ist, cpu);
14388
14389 #ifdef CONFIG_NUMA
14390 @@ -1207,7 +1159,7 @@ void __cpuinit cpu_init(void)
14391 switch_to_new_gdt(cpu);
14392 loadsegment(fs, 0);
14393
14394 - load_idt((const struct desc_ptr *)&idt_descr);
14395 + load_idt(&idt_descr);
14396
14397 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14398 syscall_init();
14399 @@ -1216,7 +1168,6 @@ void __cpuinit cpu_init(void)
14400 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14401 barrier();
14402
14403 - x86_configure_nx();
14404 if (cpu != 0)
14405 enable_x2apic();
14406
14407 @@ -1272,7 +1223,7 @@ void __cpuinit cpu_init(void)
14408 {
14409 int cpu = smp_processor_id();
14410 struct task_struct *curr = current;
14411 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14412 + struct tss_struct *t = init_tss + cpu;
14413 struct thread_struct *thread = &curr->thread;
14414
14415 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14416 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14417 index 3e6ff6c..54b4992 100644
14418 --- a/arch/x86/kernel/cpu/intel.c
14419 +++ b/arch/x86/kernel/cpu/intel.c
14420 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14421 * Update the IDT descriptor and reload the IDT so that
14422 * it uses the read-only mapped virtual address.
14423 */
14424 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14425 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14426 load_idt(&idt_descr);
14427 }
14428 #endif
14429 diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
14430 index fc4beb3..f20a5a7 100644
14431 --- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
14432 +++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
14433 @@ -199,6 +199,8 @@ static void raise_mce(struct mce *m)
14434
14435 /* Error injection interface */
14436 static ssize_t mce_write(struct file *filp, const char __user *ubuf,
14437 + size_t usize, loff_t *off) __size_overflow(3);
14438 +static ssize_t mce_write(struct file *filp, const char __user *ubuf,
14439 size_t usize, loff_t *off)
14440 {
14441 struct mce m;
14442 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14443 index 5a11ae2..a1a1c8a 100644
14444 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14445 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14446 @@ -42,6 +42,7 @@
14447 #include <asm/processor.h>
14448 #include <asm/mce.h>
14449 #include <asm/msr.h>
14450 +#include <asm/local.h>
14451
14452 #include "mce-internal.h"
14453
14454 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14455 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14456 m->cs, m->ip);
14457
14458 - if (m->cs == __KERNEL_CS)
14459 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14460 print_symbol("{%s}", m->ip);
14461 pr_cont("\n");
14462 }
14463 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14464
14465 #define PANIC_TIMEOUT 5 /* 5 seconds */
14466
14467 -static atomic_t mce_paniced;
14468 +static atomic_unchecked_t mce_paniced;
14469
14470 static int fake_panic;
14471 -static atomic_t mce_fake_paniced;
14472 +static atomic_unchecked_t mce_fake_paniced;
14473
14474 /* Panic in progress. Enable interrupts and wait for final IPI */
14475 static void wait_for_panic(void)
14476 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14477 /*
14478 * Make sure only one CPU runs in machine check panic
14479 */
14480 - if (atomic_inc_return(&mce_paniced) > 1)
14481 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14482 wait_for_panic();
14483 barrier();
14484
14485 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14486 console_verbose();
14487 } else {
14488 /* Don't log too much for fake panic */
14489 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14490 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14491 return;
14492 }
14493 /* First print corrected ones that are still unlogged */
14494 @@ -658,7 +659,7 @@ static int mce_timed_out(u64 *t)
14495 * might have been modified by someone else.
14496 */
14497 rmb();
14498 - if (atomic_read(&mce_paniced))
14499 + if (atomic_read_unchecked(&mce_paniced))
14500 wait_for_panic();
14501 if (!monarch_timeout)
14502 goto out;
14503 @@ -1446,7 +1447,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14504 }
14505
14506 /* Call the installed machine check handler for this CPU setup. */
14507 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14508 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14509 unexpected_machine_check;
14510
14511 /*
14512 @@ -1469,7 +1470,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14513 return;
14514 }
14515
14516 + pax_open_kernel();
14517 machine_check_vector = do_machine_check;
14518 + pax_close_kernel();
14519
14520 __mcheck_cpu_init_generic();
14521 __mcheck_cpu_init_vendor(c);
14522 @@ -1483,7 +1486,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14523 */
14524
14525 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14526 -static int mce_chrdev_open_count; /* #times opened */
14527 +static local_t mce_chrdev_open_count; /* #times opened */
14528 static int mce_chrdev_open_exclu; /* already open exclusive? */
14529
14530 static int mce_chrdev_open(struct inode *inode, struct file *file)
14531 @@ -1491,7 +1494,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14532 spin_lock(&mce_chrdev_state_lock);
14533
14534 if (mce_chrdev_open_exclu ||
14535 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14536 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14537 spin_unlock(&mce_chrdev_state_lock);
14538
14539 return -EBUSY;
14540 @@ -1499,7 +1502,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14541
14542 if (file->f_flags & O_EXCL)
14543 mce_chrdev_open_exclu = 1;
14544 - mce_chrdev_open_count++;
14545 + local_inc(&mce_chrdev_open_count);
14546
14547 spin_unlock(&mce_chrdev_state_lock);
14548
14549 @@ -1510,7 +1513,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14550 {
14551 spin_lock(&mce_chrdev_state_lock);
14552
14553 - mce_chrdev_open_count--;
14554 + local_dec(&mce_chrdev_open_count);
14555 mce_chrdev_open_exclu = 0;
14556
14557 spin_unlock(&mce_chrdev_state_lock);
14558 @@ -2229,7 +2232,7 @@ struct dentry *mce_get_debugfs_dir(void)
14559 static void mce_reset(void)
14560 {
14561 cpu_missing = 0;
14562 - atomic_set(&mce_fake_paniced, 0);
14563 + atomic_set_unchecked(&mce_fake_paniced, 0);
14564 atomic_set(&mce_executing, 0);
14565 atomic_set(&mce_callin, 0);
14566 atomic_set(&global_nwo, 0);
14567 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14568 index 5c0e653..0882b0a 100644
14569 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14570 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14571 @@ -12,6 +12,7 @@
14572 #include <asm/system.h>
14573 #include <asm/mce.h>
14574 #include <asm/msr.h>
14575 +#include <asm/pgtable.h>
14576
14577 /* By default disabled */
14578 int mce_p5_enabled __read_mostly;
14579 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14580 if (!cpu_has(c, X86_FEATURE_MCE))
14581 return;
14582
14583 + pax_open_kernel();
14584 machine_check_vector = pentium_machine_check;
14585 + pax_close_kernel();
14586 /* Make sure the vector pointer is visible before we enable MCEs: */
14587 wmb();
14588
14589 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14590 index 54060f5..c1a7577 100644
14591 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14592 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14593 @@ -11,6 +11,7 @@
14594 #include <asm/system.h>
14595 #include <asm/mce.h>
14596 #include <asm/msr.h>
14597 +#include <asm/pgtable.h>
14598
14599 /* Machine check handler for WinChip C6: */
14600 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14601 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14602 {
14603 u32 lo, hi;
14604
14605 + pax_open_kernel();
14606 machine_check_vector = winchip_machine_check;
14607 + pax_close_kernel();
14608 /* Make sure the vector pointer is visible before we enable MCEs: */
14609 wmb();
14610
14611 diff --git a/arch/x86/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
14612 index 7928963..1b16001 100644
14613 --- a/arch/x86/kernel/cpu/mtrr/if.c
14614 +++ b/arch/x86/kernel/cpu/mtrr/if.c
14615 @@ -91,6 +91,8 @@ mtrr_file_del(unsigned long base, unsigned long size,
14616 * "base=%Lx size=%Lx type=%s" or "disable=%d"
14617 */
14618 static ssize_t
14619 +mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos) __size_overflow(3);
14620 +static ssize_t
14621 mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
14622 {
14623 int i, err;
14624 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14625 index 6b96110..0da73eb 100644
14626 --- a/arch/x86/kernel/cpu/mtrr/main.c
14627 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14628 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14629 u64 size_or_mask, size_and_mask;
14630 static bool mtrr_aps_delayed_init;
14631
14632 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14633 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14634
14635 const struct mtrr_ops *mtrr_if;
14636
14637 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14638 index df5e41f..816c719 100644
14639 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14640 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14641 @@ -25,7 +25,7 @@ struct mtrr_ops {
14642 int (*validate_add_page)(unsigned long base, unsigned long size,
14643 unsigned int type);
14644 int (*have_wrcomb)(void);
14645 -};
14646 +} __do_const;
14647
14648 extern int generic_get_free_region(unsigned long base, unsigned long size,
14649 int replace_reg);
14650 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14651 index 5adce10..99284ec 100644
14652 --- a/arch/x86/kernel/cpu/perf_event.c
14653 +++ b/arch/x86/kernel/cpu/perf_event.c
14654 @@ -1665,7 +1665,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14655 break;
14656
14657 perf_callchain_store(entry, frame.return_address);
14658 - fp = frame.next_frame;
14659 + fp = (const void __force_user *)frame.next_frame;
14660 }
14661 }
14662
14663 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14664 index 13ad899..f642b9a 100644
14665 --- a/arch/x86/kernel/crash.c
14666 +++ b/arch/x86/kernel/crash.c
14667 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14668 {
14669 #ifdef CONFIG_X86_32
14670 struct pt_regs fixed_regs;
14671 -#endif
14672
14673 -#ifdef CONFIG_X86_32
14674 - if (!user_mode_vm(regs)) {
14675 + if (!user_mode(regs)) {
14676 crash_fixup_ss_esp(&fixed_regs, regs);
14677 regs = &fixed_regs;
14678 }
14679 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14680 index 37250fe..bf2ec74 100644
14681 --- a/arch/x86/kernel/doublefault_32.c
14682 +++ b/arch/x86/kernel/doublefault_32.c
14683 @@ -11,7 +11,7 @@
14684
14685 #define DOUBLEFAULT_STACKSIZE (1024)
14686 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14687 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14688 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14689
14690 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14691
14692 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14693 unsigned long gdt, tss;
14694
14695 store_gdt(&gdt_desc);
14696 - gdt = gdt_desc.address;
14697 + gdt = (unsigned long)gdt_desc.address;
14698
14699 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14700
14701 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14702 /* 0x2 bit is always set */
14703 .flags = X86_EFLAGS_SF | 0x2,
14704 .sp = STACK_START,
14705 - .es = __USER_DS,
14706 + .es = __KERNEL_DS,
14707 .cs = __KERNEL_CS,
14708 .ss = __KERNEL_DS,
14709 - .ds = __USER_DS,
14710 + .ds = __KERNEL_DS,
14711 .fs = __KERNEL_PERCPU,
14712
14713 .__cr3 = __pa_nodebug(swapper_pg_dir),
14714 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14715 index 4025fe4..d8451c6 100644
14716 --- a/arch/x86/kernel/dumpstack.c
14717 +++ b/arch/x86/kernel/dumpstack.c
14718 @@ -2,6 +2,9 @@
14719 * Copyright (C) 1991, 1992 Linus Torvalds
14720 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14721 */
14722 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14723 +#define __INCLUDED_BY_HIDESYM 1
14724 +#endif
14725 #include <linux/kallsyms.h>
14726 #include <linux/kprobes.h>
14727 #include <linux/uaccess.h>
14728 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
14729 static void
14730 print_ftrace_graph_addr(unsigned long addr, void *data,
14731 const struct stacktrace_ops *ops,
14732 - struct thread_info *tinfo, int *graph)
14733 + struct task_struct *task, int *graph)
14734 {
14735 - struct task_struct *task = tinfo->task;
14736 unsigned long ret_addr;
14737 int index = task->curr_ret_stack;
14738
14739 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14740 static inline void
14741 print_ftrace_graph_addr(unsigned long addr, void *data,
14742 const struct stacktrace_ops *ops,
14743 - struct thread_info *tinfo, int *graph)
14744 + struct task_struct *task, int *graph)
14745 { }
14746 #endif
14747
14748 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14749 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14750 */
14751
14752 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14753 - void *p, unsigned int size, void *end)
14754 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14755 {
14756 - void *t = tinfo;
14757 if (end) {
14758 if (p < end && p >= (end-THREAD_SIZE))
14759 return 1;
14760 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14761 }
14762
14763 unsigned long
14764 -print_context_stack(struct thread_info *tinfo,
14765 +print_context_stack(struct task_struct *task, void *stack_start,
14766 unsigned long *stack, unsigned long bp,
14767 const struct stacktrace_ops *ops, void *data,
14768 unsigned long *end, int *graph)
14769 {
14770 struct stack_frame *frame = (struct stack_frame *)bp;
14771
14772 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14773 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14774 unsigned long addr;
14775
14776 addr = *stack;
14777 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
14778 } else {
14779 ops->address(data, addr, 0);
14780 }
14781 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14782 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14783 }
14784 stack++;
14785 }
14786 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
14787 EXPORT_SYMBOL_GPL(print_context_stack);
14788
14789 unsigned long
14790 -print_context_stack_bp(struct thread_info *tinfo,
14791 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14792 unsigned long *stack, unsigned long bp,
14793 const struct stacktrace_ops *ops, void *data,
14794 unsigned long *end, int *graph)
14795 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14796 struct stack_frame *frame = (struct stack_frame *)bp;
14797 unsigned long *ret_addr = &frame->return_address;
14798
14799 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14800 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14801 unsigned long addr = *ret_addr;
14802
14803 if (!__kernel_text_address(addr))
14804 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14805 ops->address(data, addr, 1);
14806 frame = frame->next_frame;
14807 ret_addr = &frame->return_address;
14808 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14809 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14810 }
14811
14812 return (unsigned long)frame;
14813 @@ -186,7 +186,7 @@ void dump_stack(void)
14814
14815 bp = stack_frame(current, NULL);
14816 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14817 - current->pid, current->comm, print_tainted(),
14818 + task_pid_nr(current), current->comm, print_tainted(),
14819 init_utsname()->release,
14820 (int)strcspn(init_utsname()->version, " "),
14821 init_utsname()->version);
14822 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
14823 }
14824 EXPORT_SYMBOL_GPL(oops_begin);
14825
14826 +extern void gr_handle_kernel_exploit(void);
14827 +
14828 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14829 {
14830 if (regs && kexec_should_crash(current))
14831 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14832 panic("Fatal exception in interrupt");
14833 if (panic_on_oops)
14834 panic("Fatal exception");
14835 - do_exit(signr);
14836 +
14837 + gr_handle_kernel_exploit();
14838 +
14839 + do_group_exit(signr);
14840 }
14841
14842 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14843 @@ -270,7 +275,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14844
14845 show_registers(regs);
14846 #ifdef CONFIG_X86_32
14847 - if (user_mode_vm(regs)) {
14848 + if (user_mode(regs)) {
14849 sp = regs->sp;
14850 ss = regs->ss & 0xffff;
14851 } else {
14852 @@ -298,7 +303,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14853 unsigned long flags = oops_begin();
14854 int sig = SIGSEGV;
14855
14856 - if (!user_mode_vm(regs))
14857 + if (!user_mode(regs))
14858 report_bug(regs->ip, regs);
14859
14860 if (__die(str, regs, err))
14861 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14862 index c99f9ed..2a15d80 100644
14863 --- a/arch/x86/kernel/dumpstack_32.c
14864 +++ b/arch/x86/kernel/dumpstack_32.c
14865 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14866 bp = stack_frame(task, regs);
14867
14868 for (;;) {
14869 - struct thread_info *context;
14870 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14871
14872 - context = (struct thread_info *)
14873 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14874 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14875 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14876
14877 - stack = (unsigned long *)context->previous_esp;
14878 - if (!stack)
14879 + if (stack_start == task_stack_page(task))
14880 break;
14881 + stack = *(unsigned long **)stack_start;
14882 if (ops->stack(data, "IRQ") < 0)
14883 break;
14884 touch_nmi_watchdog();
14885 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14886 * When in-kernel, we also print out the stack and code at the
14887 * time of the fault..
14888 */
14889 - if (!user_mode_vm(regs)) {
14890 + if (!user_mode(regs)) {
14891 unsigned int code_prologue = code_bytes * 43 / 64;
14892 unsigned int code_len = code_bytes;
14893 unsigned char c;
14894 u8 *ip;
14895 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14896
14897 printk(KERN_EMERG "Stack:\n");
14898 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14899
14900 printk(KERN_EMERG "Code: ");
14901
14902 - ip = (u8 *)regs->ip - code_prologue;
14903 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14904 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14905 /* try starting at IP */
14906 - ip = (u8 *)regs->ip;
14907 + ip = (u8 *)regs->ip + cs_base;
14908 code_len = code_len - code_prologue + 1;
14909 }
14910 for (i = 0; i < code_len; i++, ip++) {
14911 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14912 printk(KERN_CONT " Bad EIP value.");
14913 break;
14914 }
14915 - if (ip == (u8 *)regs->ip)
14916 + if (ip == (u8 *)regs->ip + cs_base)
14917 printk(KERN_CONT "<%02x> ", c);
14918 else
14919 printk(KERN_CONT "%02x ", c);
14920 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14921 {
14922 unsigned short ud2;
14923
14924 + ip = ktla_ktva(ip);
14925 if (ip < PAGE_OFFSET)
14926 return 0;
14927 if (probe_kernel_address((unsigned short *)ip, ud2))
14928 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14929
14930 return ud2 == 0x0b0f;
14931 }
14932 +
14933 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14934 +void pax_check_alloca(unsigned long size)
14935 +{
14936 + unsigned long sp = (unsigned long)&sp, stack_left;
14937 +
14938 + /* all kernel stacks are of the same size */
14939 + stack_left = sp & (THREAD_SIZE - 1);
14940 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14941 +}
14942 +EXPORT_SYMBOL(pax_check_alloca);
14943 +#endif
14944 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14945 index 17107bd..b2deecf 100644
14946 --- a/arch/x86/kernel/dumpstack_64.c
14947 +++ b/arch/x86/kernel/dumpstack_64.c
14948 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14949 unsigned long *irq_stack_end =
14950 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14951 unsigned used = 0;
14952 - struct thread_info *tinfo;
14953 int graph = 0;
14954 unsigned long dummy;
14955 + void *stack_start;
14956
14957 if (!task)
14958 task = current;
14959 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14960 * current stack address. If the stacks consist of nested
14961 * exceptions
14962 */
14963 - tinfo = task_thread_info(task);
14964 for (;;) {
14965 char *id;
14966 unsigned long *estack_end;
14967 +
14968 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14969 &used, &id);
14970
14971 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14972 if (ops->stack(data, id) < 0)
14973 break;
14974
14975 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14976 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14977 data, estack_end, &graph);
14978 ops->stack(data, "<EOE>");
14979 /*
14980 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14981 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14982 if (ops->stack(data, "IRQ") < 0)
14983 break;
14984 - bp = ops->walk_stack(tinfo, stack, bp,
14985 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14986 ops, data, irq_stack_end, &graph);
14987 /*
14988 * We link to the next stack (which would be
14989 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14990 /*
14991 * This handles the process stack:
14992 */
14993 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14994 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14995 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14996 put_cpu();
14997 }
14998 EXPORT_SYMBOL(dump_trace);
14999 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
15000
15001 return ud2 == 0x0b0f;
15002 }
15003 +
15004 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15005 +void pax_check_alloca(unsigned long size)
15006 +{
15007 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
15008 + unsigned cpu, used;
15009 + char *id;
15010 +
15011 + /* check the process stack first */
15012 + stack_start = (unsigned long)task_stack_page(current);
15013 + stack_end = stack_start + THREAD_SIZE;
15014 + if (likely(stack_start <= sp && sp < stack_end)) {
15015 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
15016 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15017 + return;
15018 + }
15019 +
15020 + cpu = get_cpu();
15021 +
15022 + /* check the irq stacks */
15023 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
15024 + stack_start = stack_end - IRQ_STACK_SIZE;
15025 + if (stack_start <= sp && sp < stack_end) {
15026 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
15027 + put_cpu();
15028 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15029 + return;
15030 + }
15031 +
15032 + /* check the exception stacks */
15033 + used = 0;
15034 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
15035 + stack_start = stack_end - EXCEPTION_STKSZ;
15036 + if (stack_end && stack_start <= sp && sp < stack_end) {
15037 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
15038 + put_cpu();
15039 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
15040 + return;
15041 + }
15042 +
15043 + put_cpu();
15044 +
15045 + /* unknown stack */
15046 + BUG();
15047 +}
15048 +EXPORT_SYMBOL(pax_check_alloca);
15049 +#endif
15050 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
15051 index 9b9f18b..9fcaa04 100644
15052 --- a/arch/x86/kernel/early_printk.c
15053 +++ b/arch/x86/kernel/early_printk.c
15054 @@ -7,6 +7,7 @@
15055 #include <linux/pci_regs.h>
15056 #include <linux/pci_ids.h>
15057 #include <linux/errno.h>
15058 +#include <linux/sched.h>
15059 #include <asm/io.h>
15060 #include <asm/processor.h>
15061 #include <asm/fcntl.h>
15062 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
15063 index 7b784f4..db6b628 100644
15064 --- a/arch/x86/kernel/entry_32.S
15065 +++ b/arch/x86/kernel/entry_32.S
15066 @@ -179,13 +179,146 @@
15067 /*CFI_REL_OFFSET gs, PT_GS*/
15068 .endm
15069 .macro SET_KERNEL_GS reg
15070 +
15071 +#ifdef CONFIG_CC_STACKPROTECTOR
15072 movl $(__KERNEL_STACK_CANARY), \reg
15073 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
15074 + movl $(__USER_DS), \reg
15075 +#else
15076 + xorl \reg, \reg
15077 +#endif
15078 +
15079 movl \reg, %gs
15080 .endm
15081
15082 #endif /* CONFIG_X86_32_LAZY_GS */
15083
15084 -.macro SAVE_ALL
15085 +.macro pax_enter_kernel
15086 +#ifdef CONFIG_PAX_KERNEXEC
15087 + call pax_enter_kernel
15088 +#endif
15089 +.endm
15090 +
15091 +.macro pax_exit_kernel
15092 +#ifdef CONFIG_PAX_KERNEXEC
15093 + call pax_exit_kernel
15094 +#endif
15095 +.endm
15096 +
15097 +#ifdef CONFIG_PAX_KERNEXEC
15098 +ENTRY(pax_enter_kernel)
15099 +#ifdef CONFIG_PARAVIRT
15100 + pushl %eax
15101 + pushl %ecx
15102 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15103 + mov %eax, %esi
15104 +#else
15105 + mov %cr0, %esi
15106 +#endif
15107 + bts $16, %esi
15108 + jnc 1f
15109 + mov %cs, %esi
15110 + cmp $__KERNEL_CS, %esi
15111 + jz 3f
15112 + ljmp $__KERNEL_CS, $3f
15113 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15114 +2:
15115 +#ifdef CONFIG_PARAVIRT
15116 + mov %esi, %eax
15117 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15118 +#else
15119 + mov %esi, %cr0
15120 +#endif
15121 +3:
15122 +#ifdef CONFIG_PARAVIRT
15123 + popl %ecx
15124 + popl %eax
15125 +#endif
15126 + ret
15127 +ENDPROC(pax_enter_kernel)
15128 +
15129 +ENTRY(pax_exit_kernel)
15130 +#ifdef CONFIG_PARAVIRT
15131 + pushl %eax
15132 + pushl %ecx
15133 +#endif
15134 + mov %cs, %esi
15135 + cmp $__KERNEXEC_KERNEL_CS, %esi
15136 + jnz 2f
15137 +#ifdef CONFIG_PARAVIRT
15138 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15139 + mov %eax, %esi
15140 +#else
15141 + mov %cr0, %esi
15142 +#endif
15143 + btr $16, %esi
15144 + ljmp $__KERNEL_CS, $1f
15145 +1:
15146 +#ifdef CONFIG_PARAVIRT
15147 + mov %esi, %eax
15148 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15149 +#else
15150 + mov %esi, %cr0
15151 +#endif
15152 +2:
15153 +#ifdef CONFIG_PARAVIRT
15154 + popl %ecx
15155 + popl %eax
15156 +#endif
15157 + ret
15158 +ENDPROC(pax_exit_kernel)
15159 +#endif
15160 +
15161 +.macro pax_erase_kstack
15162 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15163 + call pax_erase_kstack
15164 +#endif
15165 +.endm
15166 +
15167 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15168 +/*
15169 + * ebp: thread_info
15170 + * ecx, edx: can be clobbered
15171 + */
15172 +ENTRY(pax_erase_kstack)
15173 + pushl %edi
15174 + pushl %eax
15175 +
15176 + mov TI_lowest_stack(%ebp), %edi
15177 + mov $-0xBEEF, %eax
15178 + std
15179 +
15180 +1: mov %edi, %ecx
15181 + and $THREAD_SIZE_asm - 1, %ecx
15182 + shr $2, %ecx
15183 + repne scasl
15184 + jecxz 2f
15185 +
15186 + cmp $2*16, %ecx
15187 + jc 2f
15188 +
15189 + mov $2*16, %ecx
15190 + repe scasl
15191 + jecxz 2f
15192 + jne 1b
15193 +
15194 +2: cld
15195 + mov %esp, %ecx
15196 + sub %edi, %ecx
15197 + shr $2, %ecx
15198 + rep stosl
15199 +
15200 + mov TI_task_thread_sp0(%ebp), %edi
15201 + sub $128, %edi
15202 + mov %edi, TI_lowest_stack(%ebp)
15203 +
15204 + popl %eax
15205 + popl %edi
15206 + ret
15207 +ENDPROC(pax_erase_kstack)
15208 +#endif
15209 +
15210 +.macro __SAVE_ALL _DS
15211 cld
15212 PUSH_GS
15213 pushl_cfi %fs
15214 @@ -208,7 +341,7 @@
15215 CFI_REL_OFFSET ecx, 0
15216 pushl_cfi %ebx
15217 CFI_REL_OFFSET ebx, 0
15218 - movl $(__USER_DS), %edx
15219 + movl $\_DS, %edx
15220 movl %edx, %ds
15221 movl %edx, %es
15222 movl $(__KERNEL_PERCPU), %edx
15223 @@ -216,6 +349,15 @@
15224 SET_KERNEL_GS %edx
15225 .endm
15226
15227 +.macro SAVE_ALL
15228 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15229 + __SAVE_ALL __KERNEL_DS
15230 + pax_enter_kernel
15231 +#else
15232 + __SAVE_ALL __USER_DS
15233 +#endif
15234 +.endm
15235 +
15236 .macro RESTORE_INT_REGS
15237 popl_cfi %ebx
15238 CFI_RESTORE ebx
15239 @@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
15240 popfl_cfi
15241 jmp syscall_exit
15242 CFI_ENDPROC
15243 -END(ret_from_fork)
15244 +ENDPROC(ret_from_fork)
15245
15246 /*
15247 * Interrupt exit functions should be protected against kprobes
15248 @@ -335,7 +477,15 @@ resume_userspace_sig:
15249 andl $SEGMENT_RPL_MASK, %eax
15250 #endif
15251 cmpl $USER_RPL, %eax
15252 +
15253 +#ifdef CONFIG_PAX_KERNEXEC
15254 + jae resume_userspace
15255 +
15256 + pax_exit_kernel
15257 + jmp resume_kernel
15258 +#else
15259 jb resume_kernel # not returning to v8086 or userspace
15260 +#endif
15261
15262 ENTRY(resume_userspace)
15263 LOCKDEP_SYS_EXIT
15264 @@ -347,8 +497,8 @@ ENTRY(resume_userspace)
15265 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15266 # int/exception return?
15267 jne work_pending
15268 - jmp restore_all
15269 -END(ret_from_exception)
15270 + jmp restore_all_pax
15271 +ENDPROC(ret_from_exception)
15272
15273 #ifdef CONFIG_PREEMPT
15274 ENTRY(resume_kernel)
15275 @@ -363,7 +513,7 @@ need_resched:
15276 jz restore_all
15277 call preempt_schedule_irq
15278 jmp need_resched
15279 -END(resume_kernel)
15280 +ENDPROC(resume_kernel)
15281 #endif
15282 CFI_ENDPROC
15283 /*
15284 @@ -397,23 +547,34 @@ sysenter_past_esp:
15285 /*CFI_REL_OFFSET cs, 0*/
15286 /*
15287 * Push current_thread_info()->sysenter_return to the stack.
15288 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15289 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15290 */
15291 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15292 + pushl_cfi $0
15293 CFI_REL_OFFSET eip, 0
15294
15295 pushl_cfi %eax
15296 SAVE_ALL
15297 + GET_THREAD_INFO(%ebp)
15298 + movl TI_sysenter_return(%ebp),%ebp
15299 + movl %ebp,PT_EIP(%esp)
15300 ENABLE_INTERRUPTS(CLBR_NONE)
15301
15302 /*
15303 * Load the potential sixth argument from user stack.
15304 * Careful about security.
15305 */
15306 + movl PT_OLDESP(%esp),%ebp
15307 +
15308 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15309 + mov PT_OLDSS(%esp),%ds
15310 +1: movl %ds:(%ebp),%ebp
15311 + push %ss
15312 + pop %ds
15313 +#else
15314 cmpl $__PAGE_OFFSET-3,%ebp
15315 jae syscall_fault
15316 1: movl (%ebp),%ebp
15317 +#endif
15318 +
15319 movl %ebp,PT_EBP(%esp)
15320 .section __ex_table,"a"
15321 .align 4
15322 @@ -436,12 +597,24 @@ sysenter_do_call:
15323 testl $_TIF_ALLWORK_MASK, %ecx
15324 jne sysexit_audit
15325 sysenter_exit:
15326 +
15327 +#ifdef CONFIG_PAX_RANDKSTACK
15328 + pushl_cfi %eax
15329 + movl %esp, %eax
15330 + call pax_randomize_kstack
15331 + popl_cfi %eax
15332 +#endif
15333 +
15334 + pax_erase_kstack
15335 +
15336 /* if something modifies registers it must also disable sysexit */
15337 movl PT_EIP(%esp), %edx
15338 movl PT_OLDESP(%esp), %ecx
15339 xorl %ebp,%ebp
15340 TRACE_IRQS_ON
15341 1: mov PT_FS(%esp), %fs
15342 +2: mov PT_DS(%esp), %ds
15343 +3: mov PT_ES(%esp), %es
15344 PTGS_TO_GS
15345 ENABLE_INTERRUPTS_SYSEXIT
15346
15347 @@ -458,6 +631,9 @@ sysenter_audit:
15348 movl %eax,%edx /* 2nd arg: syscall number */
15349 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15350 call __audit_syscall_entry
15351 +
15352 + pax_erase_kstack
15353 +
15354 pushl_cfi %ebx
15355 movl PT_EAX(%esp),%eax /* reload syscall number */
15356 jmp sysenter_do_call
15357 @@ -483,11 +659,17 @@ sysexit_audit:
15358
15359 CFI_ENDPROC
15360 .pushsection .fixup,"ax"
15361 -2: movl $0,PT_FS(%esp)
15362 +4: movl $0,PT_FS(%esp)
15363 + jmp 1b
15364 +5: movl $0,PT_DS(%esp)
15365 + jmp 1b
15366 +6: movl $0,PT_ES(%esp)
15367 jmp 1b
15368 .section __ex_table,"a"
15369 .align 4
15370 - .long 1b,2b
15371 + .long 1b,4b
15372 + .long 2b,5b
15373 + .long 3b,6b
15374 .popsection
15375 PTGS_TO_GS_EX
15376 ENDPROC(ia32_sysenter_target)
15377 @@ -520,6 +702,15 @@ syscall_exit:
15378 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15379 jne syscall_exit_work
15380
15381 +restore_all_pax:
15382 +
15383 +#ifdef CONFIG_PAX_RANDKSTACK
15384 + movl %esp, %eax
15385 + call pax_randomize_kstack
15386 +#endif
15387 +
15388 + pax_erase_kstack
15389 +
15390 restore_all:
15391 TRACE_IRQS_IRET
15392 restore_all_notrace:
15393 @@ -579,14 +770,34 @@ ldt_ss:
15394 * compensating for the offset by changing to the ESPFIX segment with
15395 * a base address that matches for the difference.
15396 */
15397 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15398 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15399 mov %esp, %edx /* load kernel esp */
15400 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15401 mov %dx, %ax /* eax: new kernel esp */
15402 sub %eax, %edx /* offset (low word is 0) */
15403 +#ifdef CONFIG_SMP
15404 + movl PER_CPU_VAR(cpu_number), %ebx
15405 + shll $PAGE_SHIFT_asm, %ebx
15406 + addl $cpu_gdt_table, %ebx
15407 +#else
15408 + movl $cpu_gdt_table, %ebx
15409 +#endif
15410 shr $16, %edx
15411 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15412 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15413 +
15414 +#ifdef CONFIG_PAX_KERNEXEC
15415 + mov %cr0, %esi
15416 + btr $16, %esi
15417 + mov %esi, %cr0
15418 +#endif
15419 +
15420 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15421 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15422 +
15423 +#ifdef CONFIG_PAX_KERNEXEC
15424 + bts $16, %esi
15425 + mov %esi, %cr0
15426 +#endif
15427 +
15428 pushl_cfi $__ESPFIX_SS
15429 pushl_cfi %eax /* new kernel esp */
15430 /* Disable interrupts, but do not irqtrace this section: we
15431 @@ -615,38 +826,30 @@ work_resched:
15432 movl TI_flags(%ebp), %ecx
15433 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15434 # than syscall tracing?
15435 - jz restore_all
15436 + jz restore_all_pax
15437 testb $_TIF_NEED_RESCHED, %cl
15438 jnz work_resched
15439
15440 work_notifysig: # deal with pending signals and
15441 # notify-resume requests
15442 + movl %esp, %eax
15443 #ifdef CONFIG_VM86
15444 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15445 - movl %esp, %eax
15446 - jne work_notifysig_v86 # returning to kernel-space or
15447 + jz 1f # returning to kernel-space or
15448 # vm86-space
15449 - TRACE_IRQS_ON
15450 - ENABLE_INTERRUPTS(CLBR_NONE)
15451 - xorl %edx, %edx
15452 - call do_notify_resume
15453 - jmp resume_userspace_sig
15454
15455 - ALIGN
15456 -work_notifysig_v86:
15457 pushl_cfi %ecx # save ti_flags for do_notify_resume
15458 call save_v86_state # %eax contains pt_regs pointer
15459 popl_cfi %ecx
15460 movl %eax, %esp
15461 -#else
15462 - movl %esp, %eax
15463 +1:
15464 #endif
15465 TRACE_IRQS_ON
15466 ENABLE_INTERRUPTS(CLBR_NONE)
15467 xorl %edx, %edx
15468 call do_notify_resume
15469 jmp resume_userspace_sig
15470 -END(work_pending)
15471 +ENDPROC(work_pending)
15472
15473 # perform syscall exit tracing
15474 ALIGN
15475 @@ -654,11 +857,14 @@ syscall_trace_entry:
15476 movl $-ENOSYS,PT_EAX(%esp)
15477 movl %esp, %eax
15478 call syscall_trace_enter
15479 +
15480 + pax_erase_kstack
15481 +
15482 /* What it returned is what we'll actually use. */
15483 cmpl $(NR_syscalls), %eax
15484 jnae syscall_call
15485 jmp syscall_exit
15486 -END(syscall_trace_entry)
15487 +ENDPROC(syscall_trace_entry)
15488
15489 # perform syscall exit tracing
15490 ALIGN
15491 @@ -671,20 +877,24 @@ syscall_exit_work:
15492 movl %esp, %eax
15493 call syscall_trace_leave
15494 jmp resume_userspace
15495 -END(syscall_exit_work)
15496 +ENDPROC(syscall_exit_work)
15497 CFI_ENDPROC
15498
15499 RING0_INT_FRAME # can't unwind into user space anyway
15500 syscall_fault:
15501 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15502 + push %ss
15503 + pop %ds
15504 +#endif
15505 GET_THREAD_INFO(%ebp)
15506 movl $-EFAULT,PT_EAX(%esp)
15507 jmp resume_userspace
15508 -END(syscall_fault)
15509 +ENDPROC(syscall_fault)
15510
15511 syscall_badsys:
15512 movl $-ENOSYS,PT_EAX(%esp)
15513 jmp resume_userspace
15514 -END(syscall_badsys)
15515 +ENDPROC(syscall_badsys)
15516 CFI_ENDPROC
15517 /*
15518 * End of kprobes section
15519 @@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
15520 CFI_ENDPROC
15521 ENDPROC(ptregs_clone)
15522
15523 + ALIGN;
15524 +ENTRY(kernel_execve)
15525 + CFI_STARTPROC
15526 + pushl_cfi %ebp
15527 + sub $PT_OLDSS+4,%esp
15528 + pushl_cfi %edi
15529 + pushl_cfi %ecx
15530 + pushl_cfi %eax
15531 + lea 3*4(%esp),%edi
15532 + mov $PT_OLDSS/4+1,%ecx
15533 + xorl %eax,%eax
15534 + rep stosl
15535 + popl_cfi %eax
15536 + popl_cfi %ecx
15537 + popl_cfi %edi
15538 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15539 + pushl_cfi %esp
15540 + call sys_execve
15541 + add $4,%esp
15542 + CFI_ADJUST_CFA_OFFSET -4
15543 + GET_THREAD_INFO(%ebp)
15544 + test %eax,%eax
15545 + jz syscall_exit
15546 + add $PT_OLDSS+4,%esp
15547 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15548 + popl_cfi %ebp
15549 + ret
15550 + CFI_ENDPROC
15551 +ENDPROC(kernel_execve)
15552 +
15553 .macro FIXUP_ESPFIX_STACK
15554 /*
15555 * Switch back for ESPFIX stack to the normal zerobased stack
15556 @@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
15557 * normal stack and adjusts ESP with the matching offset.
15558 */
15559 /* fixup the stack */
15560 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15561 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15562 +#ifdef CONFIG_SMP
15563 + movl PER_CPU_VAR(cpu_number), %ebx
15564 + shll $PAGE_SHIFT_asm, %ebx
15565 + addl $cpu_gdt_table, %ebx
15566 +#else
15567 + movl $cpu_gdt_table, %ebx
15568 +#endif
15569 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15570 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15571 shl $16, %eax
15572 addl %esp, %eax /* the adjusted stack pointer */
15573 pushl_cfi $__KERNEL_DS
15574 @@ -819,7 +1066,7 @@ vector=vector+1
15575 .endr
15576 2: jmp common_interrupt
15577 .endr
15578 -END(irq_entries_start)
15579 +ENDPROC(irq_entries_start)
15580
15581 .previous
15582 END(interrupt)
15583 @@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
15584 pushl_cfi $do_coprocessor_error
15585 jmp error_code
15586 CFI_ENDPROC
15587 -END(coprocessor_error)
15588 +ENDPROC(coprocessor_error)
15589
15590 ENTRY(simd_coprocessor_error)
15591 RING0_INT_FRAME
15592 @@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
15593 #endif
15594 jmp error_code
15595 CFI_ENDPROC
15596 -END(simd_coprocessor_error)
15597 +ENDPROC(simd_coprocessor_error)
15598
15599 ENTRY(device_not_available)
15600 RING0_INT_FRAME
15601 @@ -896,7 +1143,7 @@ ENTRY(device_not_available)
15602 pushl_cfi $do_device_not_available
15603 jmp error_code
15604 CFI_ENDPROC
15605 -END(device_not_available)
15606 +ENDPROC(device_not_available)
15607
15608 #ifdef CONFIG_PARAVIRT
15609 ENTRY(native_iret)
15610 @@ -905,12 +1152,12 @@ ENTRY(native_iret)
15611 .align 4
15612 .long native_iret, iret_exc
15613 .previous
15614 -END(native_iret)
15615 +ENDPROC(native_iret)
15616
15617 ENTRY(native_irq_enable_sysexit)
15618 sti
15619 sysexit
15620 -END(native_irq_enable_sysexit)
15621 +ENDPROC(native_irq_enable_sysexit)
15622 #endif
15623
15624 ENTRY(overflow)
15625 @@ -919,7 +1166,7 @@ ENTRY(overflow)
15626 pushl_cfi $do_overflow
15627 jmp error_code
15628 CFI_ENDPROC
15629 -END(overflow)
15630 +ENDPROC(overflow)
15631
15632 ENTRY(bounds)
15633 RING0_INT_FRAME
15634 @@ -927,7 +1174,7 @@ ENTRY(bounds)
15635 pushl_cfi $do_bounds
15636 jmp error_code
15637 CFI_ENDPROC
15638 -END(bounds)
15639 +ENDPROC(bounds)
15640
15641 ENTRY(invalid_op)
15642 RING0_INT_FRAME
15643 @@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15644 pushl_cfi $do_invalid_op
15645 jmp error_code
15646 CFI_ENDPROC
15647 -END(invalid_op)
15648 +ENDPROC(invalid_op)
15649
15650 ENTRY(coprocessor_segment_overrun)
15651 RING0_INT_FRAME
15652 @@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15653 pushl_cfi $do_coprocessor_segment_overrun
15654 jmp error_code
15655 CFI_ENDPROC
15656 -END(coprocessor_segment_overrun)
15657 +ENDPROC(coprocessor_segment_overrun)
15658
15659 ENTRY(invalid_TSS)
15660 RING0_EC_FRAME
15661 pushl_cfi $do_invalid_TSS
15662 jmp error_code
15663 CFI_ENDPROC
15664 -END(invalid_TSS)
15665 +ENDPROC(invalid_TSS)
15666
15667 ENTRY(segment_not_present)
15668 RING0_EC_FRAME
15669 pushl_cfi $do_segment_not_present
15670 jmp error_code
15671 CFI_ENDPROC
15672 -END(segment_not_present)
15673 +ENDPROC(segment_not_present)
15674
15675 ENTRY(stack_segment)
15676 RING0_EC_FRAME
15677 pushl_cfi $do_stack_segment
15678 jmp error_code
15679 CFI_ENDPROC
15680 -END(stack_segment)
15681 +ENDPROC(stack_segment)
15682
15683 ENTRY(alignment_check)
15684 RING0_EC_FRAME
15685 pushl_cfi $do_alignment_check
15686 jmp error_code
15687 CFI_ENDPROC
15688 -END(alignment_check)
15689 +ENDPROC(alignment_check)
15690
15691 ENTRY(divide_error)
15692 RING0_INT_FRAME
15693 @@ -979,7 +1226,7 @@ ENTRY(divide_error)
15694 pushl_cfi $do_divide_error
15695 jmp error_code
15696 CFI_ENDPROC
15697 -END(divide_error)
15698 +ENDPROC(divide_error)
15699
15700 #ifdef CONFIG_X86_MCE
15701 ENTRY(machine_check)
15702 @@ -988,7 +1235,7 @@ ENTRY(machine_check)
15703 pushl_cfi machine_check_vector
15704 jmp error_code
15705 CFI_ENDPROC
15706 -END(machine_check)
15707 +ENDPROC(machine_check)
15708 #endif
15709
15710 ENTRY(spurious_interrupt_bug)
15711 @@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15712 pushl_cfi $do_spurious_interrupt_bug
15713 jmp error_code
15714 CFI_ENDPROC
15715 -END(spurious_interrupt_bug)
15716 +ENDPROC(spurious_interrupt_bug)
15717 /*
15718 * End of kprobes section
15719 */
15720 @@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15721
15722 ENTRY(mcount)
15723 ret
15724 -END(mcount)
15725 +ENDPROC(mcount)
15726
15727 ENTRY(ftrace_caller)
15728 cmpl $0, function_trace_stop
15729 @@ -1141,7 +1388,7 @@ ftrace_graph_call:
15730 .globl ftrace_stub
15731 ftrace_stub:
15732 ret
15733 -END(ftrace_caller)
15734 +ENDPROC(ftrace_caller)
15735
15736 #else /* ! CONFIG_DYNAMIC_FTRACE */
15737
15738 @@ -1177,7 +1424,7 @@ trace:
15739 popl %ecx
15740 popl %eax
15741 jmp ftrace_stub
15742 -END(mcount)
15743 +ENDPROC(mcount)
15744 #endif /* CONFIG_DYNAMIC_FTRACE */
15745 #endif /* CONFIG_FUNCTION_TRACER */
15746
15747 @@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15748 popl %ecx
15749 popl %eax
15750 ret
15751 -END(ftrace_graph_caller)
15752 +ENDPROC(ftrace_graph_caller)
15753
15754 .globl return_to_handler
15755 return_to_handler:
15756 @@ -1253,15 +1500,18 @@ error_code:
15757 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15758 REG_TO_PTGS %ecx
15759 SET_KERNEL_GS %ecx
15760 - movl $(__USER_DS), %ecx
15761 + movl $(__KERNEL_DS), %ecx
15762 movl %ecx, %ds
15763 movl %ecx, %es
15764 +
15765 + pax_enter_kernel
15766 +
15767 TRACE_IRQS_OFF
15768 movl %esp,%eax # pt_regs pointer
15769 call *%edi
15770 jmp ret_from_exception
15771 CFI_ENDPROC
15772 -END(page_fault)
15773 +ENDPROC(page_fault)
15774
15775 /*
15776 * Debug traps and NMI can happen at the one SYSENTER instruction
15777 @@ -1303,7 +1553,7 @@ debug_stack_correct:
15778 call do_debug
15779 jmp ret_from_exception
15780 CFI_ENDPROC
15781 -END(debug)
15782 +ENDPROC(debug)
15783
15784 /*
15785 * NMI is doubly nasty. It can happen _while_ we're handling
15786 @@ -1340,6 +1590,9 @@ nmi_stack_correct:
15787 xorl %edx,%edx # zero error code
15788 movl %esp,%eax # pt_regs pointer
15789 call do_nmi
15790 +
15791 + pax_exit_kernel
15792 +
15793 jmp restore_all_notrace
15794 CFI_ENDPROC
15795
15796 @@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15797 FIXUP_ESPFIX_STACK # %eax == %esp
15798 xorl %edx,%edx # zero error code
15799 call do_nmi
15800 +
15801 + pax_exit_kernel
15802 +
15803 RESTORE_REGS
15804 lss 12+4(%esp), %esp # back to espfix stack
15805 CFI_ADJUST_CFA_OFFSET -24
15806 jmp irq_return
15807 CFI_ENDPROC
15808 -END(nmi)
15809 +ENDPROC(nmi)
15810
15811 ENTRY(int3)
15812 RING0_INT_FRAME
15813 @@ -1393,14 +1649,14 @@ ENTRY(int3)
15814 call do_int3
15815 jmp ret_from_exception
15816 CFI_ENDPROC
15817 -END(int3)
15818 +ENDPROC(int3)
15819
15820 ENTRY(general_protection)
15821 RING0_EC_FRAME
15822 pushl_cfi $do_general_protection
15823 jmp error_code
15824 CFI_ENDPROC
15825 -END(general_protection)
15826 +ENDPROC(general_protection)
15827
15828 #ifdef CONFIG_KVM_GUEST
15829 ENTRY(async_page_fault)
15830 @@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15831 pushl_cfi $do_async_page_fault
15832 jmp error_code
15833 CFI_ENDPROC
15834 -END(async_page_fault)
15835 +ENDPROC(async_page_fault)
15836 #endif
15837
15838 /*
15839 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15840 index 1333d98..b340ca2 100644
15841 --- a/arch/x86/kernel/entry_64.S
15842 +++ b/arch/x86/kernel/entry_64.S
15843 @@ -56,6 +56,8 @@
15844 #include <asm/ftrace.h>
15845 #include <asm/percpu.h>
15846 #include <linux/err.h>
15847 +#include <asm/pgtable.h>
15848 +#include <asm/alternative-asm.h>
15849
15850 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15851 #include <linux/elf-em.h>
15852 @@ -69,8 +71,9 @@
15853 #ifdef CONFIG_FUNCTION_TRACER
15854 #ifdef CONFIG_DYNAMIC_FTRACE
15855 ENTRY(mcount)
15856 + pax_force_retaddr
15857 retq
15858 -END(mcount)
15859 +ENDPROC(mcount)
15860
15861 ENTRY(ftrace_caller)
15862 cmpl $0, function_trace_stop
15863 @@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15864 #endif
15865
15866 GLOBAL(ftrace_stub)
15867 + pax_force_retaddr
15868 retq
15869 -END(ftrace_caller)
15870 +ENDPROC(ftrace_caller)
15871
15872 #else /* ! CONFIG_DYNAMIC_FTRACE */
15873 ENTRY(mcount)
15874 @@ -113,6 +117,7 @@ ENTRY(mcount)
15875 #endif
15876
15877 GLOBAL(ftrace_stub)
15878 + pax_force_retaddr
15879 retq
15880
15881 trace:
15882 @@ -122,12 +127,13 @@ trace:
15883 movq 8(%rbp), %rsi
15884 subq $MCOUNT_INSN_SIZE, %rdi
15885
15886 + pax_force_fptr ftrace_trace_function
15887 call *ftrace_trace_function
15888
15889 MCOUNT_RESTORE_FRAME
15890
15891 jmp ftrace_stub
15892 -END(mcount)
15893 +ENDPROC(mcount)
15894 #endif /* CONFIG_DYNAMIC_FTRACE */
15895 #endif /* CONFIG_FUNCTION_TRACER */
15896
15897 @@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15898
15899 MCOUNT_RESTORE_FRAME
15900
15901 + pax_force_retaddr
15902 retq
15903 -END(ftrace_graph_caller)
15904 +ENDPROC(ftrace_graph_caller)
15905
15906 GLOBAL(return_to_handler)
15907 subq $24, %rsp
15908 @@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15909 movq 8(%rsp), %rdx
15910 movq (%rsp), %rax
15911 addq $24, %rsp
15912 + pax_force_fptr %rdi
15913 jmp *%rdi
15914 #endif
15915
15916 @@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15917 ENDPROC(native_usergs_sysret64)
15918 #endif /* CONFIG_PARAVIRT */
15919
15920 + .macro ljmpq sel, off
15921 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15922 + .byte 0x48; ljmp *1234f(%rip)
15923 + .pushsection .rodata
15924 + .align 16
15925 + 1234: .quad \off; .word \sel
15926 + .popsection
15927 +#else
15928 + pushq $\sel
15929 + pushq $\off
15930 + lretq
15931 +#endif
15932 + .endm
15933 +
15934 + .macro pax_enter_kernel
15935 + pax_set_fptr_mask
15936 +#ifdef CONFIG_PAX_KERNEXEC
15937 + call pax_enter_kernel
15938 +#endif
15939 + .endm
15940 +
15941 + .macro pax_exit_kernel
15942 +#ifdef CONFIG_PAX_KERNEXEC
15943 + call pax_exit_kernel
15944 +#endif
15945 + .endm
15946 +
15947 +#ifdef CONFIG_PAX_KERNEXEC
15948 +ENTRY(pax_enter_kernel)
15949 + pushq %rdi
15950 +
15951 +#ifdef CONFIG_PARAVIRT
15952 + PV_SAVE_REGS(CLBR_RDI)
15953 +#endif
15954 +
15955 + GET_CR0_INTO_RDI
15956 + bts $16,%rdi
15957 + jnc 3f
15958 + mov %cs,%edi
15959 + cmp $__KERNEL_CS,%edi
15960 + jnz 2f
15961 +1:
15962 +
15963 +#ifdef CONFIG_PARAVIRT
15964 + PV_RESTORE_REGS(CLBR_RDI)
15965 +#endif
15966 +
15967 + popq %rdi
15968 + pax_force_retaddr
15969 + retq
15970 +
15971 +2: ljmpq __KERNEL_CS,1f
15972 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15973 +4: SET_RDI_INTO_CR0
15974 + jmp 1b
15975 +ENDPROC(pax_enter_kernel)
15976 +
15977 +ENTRY(pax_exit_kernel)
15978 + pushq %rdi
15979 +
15980 +#ifdef CONFIG_PARAVIRT
15981 + PV_SAVE_REGS(CLBR_RDI)
15982 +#endif
15983 +
15984 + mov %cs,%rdi
15985 + cmp $__KERNEXEC_KERNEL_CS,%edi
15986 + jz 2f
15987 +1:
15988 +
15989 +#ifdef CONFIG_PARAVIRT
15990 + PV_RESTORE_REGS(CLBR_RDI);
15991 +#endif
15992 +
15993 + popq %rdi
15994 + pax_force_retaddr
15995 + retq
15996 +
15997 +2: GET_CR0_INTO_RDI
15998 + btr $16,%rdi
15999 + ljmpq __KERNEL_CS,3f
16000 +3: SET_RDI_INTO_CR0
16001 + jmp 1b
16002 +#ifdef CONFIG_PARAVIRT
16003 + PV_RESTORE_REGS(CLBR_RDI);
16004 +#endif
16005 +
16006 + popq %rdi
16007 + pax_force_retaddr
16008 + retq
16009 +ENDPROC(pax_exit_kernel)
16010 +#endif
16011 +
16012 + .macro pax_enter_kernel_user
16013 + pax_set_fptr_mask
16014 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16015 + call pax_enter_kernel_user
16016 +#endif
16017 + .endm
16018 +
16019 + .macro pax_exit_kernel_user
16020 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16021 + call pax_exit_kernel_user
16022 +#endif
16023 +#ifdef CONFIG_PAX_RANDKSTACK
16024 + pushq %rax
16025 + call pax_randomize_kstack
16026 + popq %rax
16027 +#endif
16028 + .endm
16029 +
16030 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16031 +ENTRY(pax_enter_kernel_user)
16032 + pushq %rdi
16033 + pushq %rbx
16034 +
16035 +#ifdef CONFIG_PARAVIRT
16036 + PV_SAVE_REGS(CLBR_RDI)
16037 +#endif
16038 +
16039 + GET_CR3_INTO_RDI
16040 + mov %rdi,%rbx
16041 + add $__START_KERNEL_map,%rbx
16042 + sub phys_base(%rip),%rbx
16043 +
16044 +#ifdef CONFIG_PARAVIRT
16045 + pushq %rdi
16046 + cmpl $0, pv_info+PARAVIRT_enabled
16047 + jz 1f
16048 + i = 0
16049 + .rept USER_PGD_PTRS
16050 + mov i*8(%rbx),%rsi
16051 + mov $0,%sil
16052 + lea i*8(%rbx),%rdi
16053 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16054 + i = i + 1
16055 + .endr
16056 + jmp 2f
16057 +1:
16058 +#endif
16059 +
16060 + i = 0
16061 + .rept USER_PGD_PTRS
16062 + movb $0,i*8(%rbx)
16063 + i = i + 1
16064 + .endr
16065 +
16066 +#ifdef CONFIG_PARAVIRT
16067 +2: popq %rdi
16068 +#endif
16069 + SET_RDI_INTO_CR3
16070 +
16071 +#ifdef CONFIG_PAX_KERNEXEC
16072 + GET_CR0_INTO_RDI
16073 + bts $16,%rdi
16074 + SET_RDI_INTO_CR0
16075 +#endif
16076 +
16077 +#ifdef CONFIG_PARAVIRT
16078 + PV_RESTORE_REGS(CLBR_RDI)
16079 +#endif
16080 +
16081 + popq %rbx
16082 + popq %rdi
16083 + pax_force_retaddr
16084 + retq
16085 +ENDPROC(pax_enter_kernel_user)
16086 +
16087 +ENTRY(pax_exit_kernel_user)
16088 + push %rdi
16089 +
16090 +#ifdef CONFIG_PARAVIRT
16091 + pushq %rbx
16092 + PV_SAVE_REGS(CLBR_RDI)
16093 +#endif
16094 +
16095 +#ifdef CONFIG_PAX_KERNEXEC
16096 + GET_CR0_INTO_RDI
16097 + btr $16,%rdi
16098 + SET_RDI_INTO_CR0
16099 +#endif
16100 +
16101 + GET_CR3_INTO_RDI
16102 + add $__START_KERNEL_map,%rdi
16103 + sub phys_base(%rip),%rdi
16104 +
16105 +#ifdef CONFIG_PARAVIRT
16106 + cmpl $0, pv_info+PARAVIRT_enabled
16107 + jz 1f
16108 + mov %rdi,%rbx
16109 + i = 0
16110 + .rept USER_PGD_PTRS
16111 + mov i*8(%rbx),%rsi
16112 + mov $0x67,%sil
16113 + lea i*8(%rbx),%rdi
16114 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16115 + i = i + 1
16116 + .endr
16117 + jmp 2f
16118 +1:
16119 +#endif
16120 +
16121 + i = 0
16122 + .rept USER_PGD_PTRS
16123 + movb $0x67,i*8(%rdi)
16124 + i = i + 1
16125 + .endr
16126 +
16127 +#ifdef CONFIG_PARAVIRT
16128 +2: PV_RESTORE_REGS(CLBR_RDI)
16129 + popq %rbx
16130 +#endif
16131 +
16132 + popq %rdi
16133 + pax_force_retaddr
16134 + retq
16135 +ENDPROC(pax_exit_kernel_user)
16136 +#endif
16137 +
16138 +.macro pax_erase_kstack
16139 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16140 + call pax_erase_kstack
16141 +#endif
16142 +.endm
16143 +
16144 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16145 +/*
16146 + * r11: thread_info
16147 + * rcx, rdx: can be clobbered
16148 + */
16149 +ENTRY(pax_erase_kstack)
16150 + pushq %rdi
16151 + pushq %rax
16152 + pushq %r11
16153 +
16154 + GET_THREAD_INFO(%r11)
16155 + mov TI_lowest_stack(%r11), %rdi
16156 + mov $-0xBEEF, %rax
16157 + std
16158 +
16159 +1: mov %edi, %ecx
16160 + and $THREAD_SIZE_asm - 1, %ecx
16161 + shr $3, %ecx
16162 + repne scasq
16163 + jecxz 2f
16164 +
16165 + cmp $2*8, %ecx
16166 + jc 2f
16167 +
16168 + mov $2*8, %ecx
16169 + repe scasq
16170 + jecxz 2f
16171 + jne 1b
16172 +
16173 +2: cld
16174 + mov %esp, %ecx
16175 + sub %edi, %ecx
16176 +
16177 + cmp $THREAD_SIZE_asm, %rcx
16178 + jb 3f
16179 + ud2
16180 +3:
16181 +
16182 + shr $3, %ecx
16183 + rep stosq
16184 +
16185 + mov TI_task_thread_sp0(%r11), %rdi
16186 + sub $256, %rdi
16187 + mov %rdi, TI_lowest_stack(%r11)
16188 +
16189 + popq %r11
16190 + popq %rax
16191 + popq %rdi
16192 + pax_force_retaddr
16193 + ret
16194 +ENDPROC(pax_erase_kstack)
16195 +#endif
16196
16197 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16198 #ifdef CONFIG_TRACE_IRQFLAGS
16199 @@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
16200 .endm
16201
16202 .macro UNFAKE_STACK_FRAME
16203 - addq $8*6, %rsp
16204 - CFI_ADJUST_CFA_OFFSET -(6*8)
16205 + addq $8*6 + ARG_SKIP, %rsp
16206 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16207 .endm
16208
16209 /*
16210 @@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
16211 movq %rsp, %rsi
16212
16213 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16214 - testl $3, CS(%rdi)
16215 + testb $3, CS(%rdi)
16216 je 1f
16217 SWAPGS
16218 /*
16219 @@ -356,9 +640,10 @@ ENTRY(save_rest)
16220 movq_cfi r15, R15+16
16221 movq %r11, 8(%rsp) /* return address */
16222 FIXUP_TOP_OF_STACK %r11, 16
16223 + pax_force_retaddr
16224 ret
16225 CFI_ENDPROC
16226 -END(save_rest)
16227 +ENDPROC(save_rest)
16228
16229 /* save complete stack frame */
16230 .pushsection .kprobes.text, "ax"
16231 @@ -387,9 +672,10 @@ ENTRY(save_paranoid)
16232 js 1f /* negative -> in kernel */
16233 SWAPGS
16234 xorl %ebx,%ebx
16235 -1: ret
16236 +1: pax_force_retaddr_bts
16237 + ret
16238 CFI_ENDPROC
16239 -END(save_paranoid)
16240 +ENDPROC(save_paranoid)
16241 .popsection
16242
16243 /*
16244 @@ -411,7 +697,7 @@ ENTRY(ret_from_fork)
16245
16246 RESTORE_REST
16247
16248 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16249 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16250 jz retint_restore_args
16251
16252 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16253 @@ -421,7 +707,7 @@ ENTRY(ret_from_fork)
16254 jmp ret_from_sys_call # go to the SYSRET fastpath
16255
16256 CFI_ENDPROC
16257 -END(ret_from_fork)
16258 +ENDPROC(ret_from_fork)
16259
16260 /*
16261 * System call entry. Up to 6 arguments in registers are supported.
16262 @@ -457,7 +743,7 @@ END(ret_from_fork)
16263 ENTRY(system_call)
16264 CFI_STARTPROC simple
16265 CFI_SIGNAL_FRAME
16266 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16267 + CFI_DEF_CFA rsp,0
16268 CFI_REGISTER rip,rcx
16269 /*CFI_REGISTER rflags,r11*/
16270 SWAPGS_UNSAFE_STACK
16271 @@ -470,21 +756,23 @@ GLOBAL(system_call_after_swapgs)
16272
16273 movq %rsp,PER_CPU_VAR(old_rsp)
16274 movq PER_CPU_VAR(kernel_stack),%rsp
16275 + SAVE_ARGS 8*6,0
16276 + pax_enter_kernel_user
16277 /*
16278 * No need to follow this irqs off/on section - it's straight
16279 * and short:
16280 */
16281 ENABLE_INTERRUPTS(CLBR_NONE)
16282 - SAVE_ARGS 8,0
16283 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16284 movq %rcx,RIP-ARGOFFSET(%rsp)
16285 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16286 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16287 + GET_THREAD_INFO(%rcx)
16288 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16289 jnz tracesys
16290 system_call_fastpath:
16291 cmpq $__NR_syscall_max,%rax
16292 ja badsys
16293 - movq %r10,%rcx
16294 + movq R10-ARGOFFSET(%rsp),%rcx
16295 call *sys_call_table(,%rax,8) # XXX: rip relative
16296 movq %rax,RAX-ARGOFFSET(%rsp)
16297 /*
16298 @@ -498,10 +786,13 @@ sysret_check:
16299 LOCKDEP_SYS_EXIT
16300 DISABLE_INTERRUPTS(CLBR_NONE)
16301 TRACE_IRQS_OFF
16302 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16303 + GET_THREAD_INFO(%rcx)
16304 + movl TI_flags(%rcx),%edx
16305 andl %edi,%edx
16306 jnz sysret_careful
16307 CFI_REMEMBER_STATE
16308 + pax_exit_kernel_user
16309 + pax_erase_kstack
16310 /*
16311 * sysretq will re-enable interrupts:
16312 */
16313 @@ -553,14 +844,18 @@ badsys:
16314 * jump back to the normal fast path.
16315 */
16316 auditsys:
16317 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16318 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16319 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16320 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16321 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16322 movq %rax,%rsi /* 2nd arg: syscall number */
16323 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16324 call __audit_syscall_entry
16325 +
16326 + pax_erase_kstack
16327 +
16328 LOAD_ARGS 0 /* reload call-clobbered registers */
16329 + pax_set_fptr_mask
16330 jmp system_call_fastpath
16331
16332 /*
16333 @@ -581,7 +876,7 @@ sysret_audit:
16334 /* Do syscall tracing */
16335 tracesys:
16336 #ifdef CONFIG_AUDITSYSCALL
16337 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16338 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16339 jz auditsys
16340 #endif
16341 SAVE_REST
16342 @@ -589,16 +884,20 @@ tracesys:
16343 FIXUP_TOP_OF_STACK %rdi
16344 movq %rsp,%rdi
16345 call syscall_trace_enter
16346 +
16347 + pax_erase_kstack
16348 +
16349 /*
16350 * Reload arg registers from stack in case ptrace changed them.
16351 * We don't reload %rax because syscall_trace_enter() returned
16352 * the value it wants us to use in the table lookup.
16353 */
16354 LOAD_ARGS ARGOFFSET, 1
16355 + pax_set_fptr_mask
16356 RESTORE_REST
16357 cmpq $__NR_syscall_max,%rax
16358 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16359 - movq %r10,%rcx /* fixup for C */
16360 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16361 call *sys_call_table(,%rax,8)
16362 movq %rax,RAX-ARGOFFSET(%rsp)
16363 /* Use IRET because user could have changed frame */
16364 @@ -619,6 +918,7 @@ GLOBAL(int_with_check)
16365 andl %edi,%edx
16366 jnz int_careful
16367 andl $~TS_COMPAT,TI_status(%rcx)
16368 + pax_erase_kstack
16369 jmp retint_swapgs
16370
16371 /* Either reschedule or signal or syscall exit tracking needed. */
16372 @@ -665,7 +965,7 @@ int_restore_rest:
16373 TRACE_IRQS_OFF
16374 jmp int_with_check
16375 CFI_ENDPROC
16376 -END(system_call)
16377 +ENDPROC(system_call)
16378
16379 /*
16380 * Certain special system calls that need to save a complete full stack frame.
16381 @@ -681,7 +981,7 @@ ENTRY(\label)
16382 call \func
16383 jmp ptregscall_common
16384 CFI_ENDPROC
16385 -END(\label)
16386 +ENDPROC(\label)
16387 .endm
16388
16389 PTREGSCALL stub_clone, sys_clone, %r8
16390 @@ -699,9 +999,10 @@ ENTRY(ptregscall_common)
16391 movq_cfi_restore R12+8, r12
16392 movq_cfi_restore RBP+8, rbp
16393 movq_cfi_restore RBX+8, rbx
16394 + pax_force_retaddr
16395 ret $REST_SKIP /* pop extended registers */
16396 CFI_ENDPROC
16397 -END(ptregscall_common)
16398 +ENDPROC(ptregscall_common)
16399
16400 ENTRY(stub_execve)
16401 CFI_STARTPROC
16402 @@ -716,7 +1017,7 @@ ENTRY(stub_execve)
16403 RESTORE_REST
16404 jmp int_ret_from_sys_call
16405 CFI_ENDPROC
16406 -END(stub_execve)
16407 +ENDPROC(stub_execve)
16408
16409 /*
16410 * sigreturn is special because it needs to restore all registers on return.
16411 @@ -734,7 +1035,7 @@ ENTRY(stub_rt_sigreturn)
16412 RESTORE_REST
16413 jmp int_ret_from_sys_call
16414 CFI_ENDPROC
16415 -END(stub_rt_sigreturn)
16416 +ENDPROC(stub_rt_sigreturn)
16417
16418 /*
16419 * Build the entry stubs and pointer table with some assembler magic.
16420 @@ -769,7 +1070,7 @@ vector=vector+1
16421 2: jmp common_interrupt
16422 .endr
16423 CFI_ENDPROC
16424 -END(irq_entries_start)
16425 +ENDPROC(irq_entries_start)
16426
16427 .previous
16428 END(interrupt)
16429 @@ -789,6 +1090,16 @@ END(interrupt)
16430 subq $ORIG_RAX-RBP, %rsp
16431 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16432 SAVE_ARGS_IRQ
16433 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16434 + testb $3, CS(%rdi)
16435 + jnz 1f
16436 + pax_enter_kernel
16437 + jmp 2f
16438 +1: pax_enter_kernel_user
16439 +2:
16440 +#else
16441 + pax_enter_kernel
16442 +#endif
16443 call \func
16444 .endm
16445
16446 @@ -820,7 +1131,7 @@ ret_from_intr:
16447
16448 exit_intr:
16449 GET_THREAD_INFO(%rcx)
16450 - testl $3,CS-ARGOFFSET(%rsp)
16451 + testb $3,CS-ARGOFFSET(%rsp)
16452 je retint_kernel
16453
16454 /* Interrupt came from user space */
16455 @@ -842,12 +1153,15 @@ retint_swapgs: /* return to user-space */
16456 * The iretq could re-enable interrupts:
16457 */
16458 DISABLE_INTERRUPTS(CLBR_ANY)
16459 + pax_exit_kernel_user
16460 TRACE_IRQS_IRETQ
16461 SWAPGS
16462 jmp restore_args
16463
16464 retint_restore_args: /* return to kernel space */
16465 DISABLE_INTERRUPTS(CLBR_ANY)
16466 + pax_exit_kernel
16467 + pax_force_retaddr RIP-ARGOFFSET
16468 /*
16469 * The iretq could re-enable interrupts:
16470 */
16471 @@ -936,7 +1250,7 @@ ENTRY(retint_kernel)
16472 #endif
16473
16474 CFI_ENDPROC
16475 -END(common_interrupt)
16476 +ENDPROC(common_interrupt)
16477 /*
16478 * End of kprobes section
16479 */
16480 @@ -953,7 +1267,7 @@ ENTRY(\sym)
16481 interrupt \do_sym
16482 jmp ret_from_intr
16483 CFI_ENDPROC
16484 -END(\sym)
16485 +ENDPROC(\sym)
16486 .endm
16487
16488 #ifdef CONFIG_SMP
16489 @@ -1026,12 +1340,22 @@ ENTRY(\sym)
16490 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16491 call error_entry
16492 DEFAULT_FRAME 0
16493 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16494 + testb $3, CS(%rsp)
16495 + jnz 1f
16496 + pax_enter_kernel
16497 + jmp 2f
16498 +1: pax_enter_kernel_user
16499 +2:
16500 +#else
16501 + pax_enter_kernel
16502 +#endif
16503 movq %rsp,%rdi /* pt_regs pointer */
16504 xorl %esi,%esi /* no error code */
16505 call \do_sym
16506 jmp error_exit /* %ebx: no swapgs flag */
16507 CFI_ENDPROC
16508 -END(\sym)
16509 +ENDPROC(\sym)
16510 .endm
16511
16512 .macro paranoidzeroentry sym do_sym
16513 @@ -1043,15 +1367,25 @@ ENTRY(\sym)
16514 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16515 call save_paranoid
16516 TRACE_IRQS_OFF
16517 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16518 + testb $3, CS(%rsp)
16519 + jnz 1f
16520 + pax_enter_kernel
16521 + jmp 2f
16522 +1: pax_enter_kernel_user
16523 +2:
16524 +#else
16525 + pax_enter_kernel
16526 +#endif
16527 movq %rsp,%rdi /* pt_regs pointer */
16528 xorl %esi,%esi /* no error code */
16529 call \do_sym
16530 jmp paranoid_exit /* %ebx: no swapgs flag */
16531 CFI_ENDPROC
16532 -END(\sym)
16533 +ENDPROC(\sym)
16534 .endm
16535
16536 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16537 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16538 .macro paranoidzeroentry_ist sym do_sym ist
16539 ENTRY(\sym)
16540 INTR_FRAME
16541 @@ -1061,14 +1395,30 @@ ENTRY(\sym)
16542 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16543 call save_paranoid
16544 TRACE_IRQS_OFF
16545 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16546 + testb $3, CS(%rsp)
16547 + jnz 1f
16548 + pax_enter_kernel
16549 + jmp 2f
16550 +1: pax_enter_kernel_user
16551 +2:
16552 +#else
16553 + pax_enter_kernel
16554 +#endif
16555 movq %rsp,%rdi /* pt_regs pointer */
16556 xorl %esi,%esi /* no error code */
16557 +#ifdef CONFIG_SMP
16558 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16559 + lea init_tss(%r12), %r12
16560 +#else
16561 + lea init_tss(%rip), %r12
16562 +#endif
16563 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16564 call \do_sym
16565 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16566 jmp paranoid_exit /* %ebx: no swapgs flag */
16567 CFI_ENDPROC
16568 -END(\sym)
16569 +ENDPROC(\sym)
16570 .endm
16571
16572 .macro errorentry sym do_sym
16573 @@ -1079,13 +1429,23 @@ ENTRY(\sym)
16574 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16575 call error_entry
16576 DEFAULT_FRAME 0
16577 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16578 + testb $3, CS(%rsp)
16579 + jnz 1f
16580 + pax_enter_kernel
16581 + jmp 2f
16582 +1: pax_enter_kernel_user
16583 +2:
16584 +#else
16585 + pax_enter_kernel
16586 +#endif
16587 movq %rsp,%rdi /* pt_regs pointer */
16588 movq ORIG_RAX(%rsp),%rsi /* get error code */
16589 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16590 call \do_sym
16591 jmp error_exit /* %ebx: no swapgs flag */
16592 CFI_ENDPROC
16593 -END(\sym)
16594 +ENDPROC(\sym)
16595 .endm
16596
16597 /* error code is on the stack already */
16598 @@ -1098,13 +1458,23 @@ ENTRY(\sym)
16599 call save_paranoid
16600 DEFAULT_FRAME 0
16601 TRACE_IRQS_OFF
16602 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16603 + testb $3, CS(%rsp)
16604 + jnz 1f
16605 + pax_enter_kernel
16606 + jmp 2f
16607 +1: pax_enter_kernel_user
16608 +2:
16609 +#else
16610 + pax_enter_kernel
16611 +#endif
16612 movq %rsp,%rdi /* pt_regs pointer */
16613 movq ORIG_RAX(%rsp),%rsi /* get error code */
16614 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16615 call \do_sym
16616 jmp paranoid_exit /* %ebx: no swapgs flag */
16617 CFI_ENDPROC
16618 -END(\sym)
16619 +ENDPROC(\sym)
16620 .endm
16621
16622 zeroentry divide_error do_divide_error
16623 @@ -1134,9 +1504,10 @@ gs_change:
16624 2: mfence /* workaround */
16625 SWAPGS
16626 popfq_cfi
16627 + pax_force_retaddr
16628 ret
16629 CFI_ENDPROC
16630 -END(native_load_gs_index)
16631 +ENDPROC(native_load_gs_index)
16632
16633 .section __ex_table,"a"
16634 .align 8
16635 @@ -1158,13 +1529,14 @@ ENTRY(kernel_thread_helper)
16636 * Here we are in the child and the registers are set as they were
16637 * at kernel_thread() invocation in the parent.
16638 */
16639 + pax_force_fptr %rsi
16640 call *%rsi
16641 # exit
16642 mov %eax, %edi
16643 call do_exit
16644 ud2 # padding for call trace
16645 CFI_ENDPROC
16646 -END(kernel_thread_helper)
16647 +ENDPROC(kernel_thread_helper)
16648
16649 /*
16650 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16651 @@ -1191,11 +1563,11 @@ ENTRY(kernel_execve)
16652 RESTORE_REST
16653 testq %rax,%rax
16654 je int_ret_from_sys_call
16655 - RESTORE_ARGS
16656 UNFAKE_STACK_FRAME
16657 + pax_force_retaddr
16658 ret
16659 CFI_ENDPROC
16660 -END(kernel_execve)
16661 +ENDPROC(kernel_execve)
16662
16663 /* Call softirq on interrupt stack. Interrupts are off. */
16664 ENTRY(call_softirq)
16665 @@ -1213,9 +1585,10 @@ ENTRY(call_softirq)
16666 CFI_DEF_CFA_REGISTER rsp
16667 CFI_ADJUST_CFA_OFFSET -8
16668 decl PER_CPU_VAR(irq_count)
16669 + pax_force_retaddr
16670 ret
16671 CFI_ENDPROC
16672 -END(call_softirq)
16673 +ENDPROC(call_softirq)
16674
16675 #ifdef CONFIG_XEN
16676 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16677 @@ -1253,7 +1626,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16678 decl PER_CPU_VAR(irq_count)
16679 jmp error_exit
16680 CFI_ENDPROC
16681 -END(xen_do_hypervisor_callback)
16682 +ENDPROC(xen_do_hypervisor_callback)
16683
16684 /*
16685 * Hypervisor uses this for application faults while it executes.
16686 @@ -1312,7 +1685,7 @@ ENTRY(xen_failsafe_callback)
16687 SAVE_ALL
16688 jmp error_exit
16689 CFI_ENDPROC
16690 -END(xen_failsafe_callback)
16691 +ENDPROC(xen_failsafe_callback)
16692
16693 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16694 xen_hvm_callback_vector xen_evtchn_do_upcall
16695 @@ -1361,16 +1734,31 @@ ENTRY(paranoid_exit)
16696 TRACE_IRQS_OFF
16697 testl %ebx,%ebx /* swapgs needed? */
16698 jnz paranoid_restore
16699 - testl $3,CS(%rsp)
16700 + testb $3,CS(%rsp)
16701 jnz paranoid_userspace
16702 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16703 + pax_exit_kernel
16704 + TRACE_IRQS_IRETQ 0
16705 + SWAPGS_UNSAFE_STACK
16706 + RESTORE_ALL 8
16707 + pax_force_retaddr_bts
16708 + jmp irq_return
16709 +#endif
16710 paranoid_swapgs:
16711 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16712 + pax_exit_kernel_user
16713 +#else
16714 + pax_exit_kernel
16715 +#endif
16716 TRACE_IRQS_IRETQ 0
16717 SWAPGS_UNSAFE_STACK
16718 RESTORE_ALL 8
16719 jmp irq_return
16720 paranoid_restore:
16721 + pax_exit_kernel
16722 TRACE_IRQS_IRETQ 0
16723 RESTORE_ALL 8
16724 + pax_force_retaddr_bts
16725 jmp irq_return
16726 paranoid_userspace:
16727 GET_THREAD_INFO(%rcx)
16728 @@ -1399,7 +1787,7 @@ paranoid_schedule:
16729 TRACE_IRQS_OFF
16730 jmp paranoid_userspace
16731 CFI_ENDPROC
16732 -END(paranoid_exit)
16733 +ENDPROC(paranoid_exit)
16734
16735 /*
16736 * Exception entry point. This expects an error code/orig_rax on the stack.
16737 @@ -1426,12 +1814,13 @@ ENTRY(error_entry)
16738 movq_cfi r14, R14+8
16739 movq_cfi r15, R15+8
16740 xorl %ebx,%ebx
16741 - testl $3,CS+8(%rsp)
16742 + testb $3,CS+8(%rsp)
16743 je error_kernelspace
16744 error_swapgs:
16745 SWAPGS
16746 error_sti:
16747 TRACE_IRQS_OFF
16748 + pax_force_retaddr_bts
16749 ret
16750
16751 /*
16752 @@ -1458,7 +1847,7 @@ bstep_iret:
16753 movq %rcx,RIP+8(%rsp)
16754 jmp error_swapgs
16755 CFI_ENDPROC
16756 -END(error_entry)
16757 +ENDPROC(error_entry)
16758
16759
16760 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16761 @@ -1478,7 +1867,7 @@ ENTRY(error_exit)
16762 jnz retint_careful
16763 jmp retint_swapgs
16764 CFI_ENDPROC
16765 -END(error_exit)
16766 +ENDPROC(error_exit)
16767
16768 /*
16769 * Test if a given stack is an NMI stack or not.
16770 @@ -1535,9 +1924,11 @@ ENTRY(nmi)
16771 * If %cs was not the kernel segment, then the NMI triggered in user
16772 * space, which means it is definitely not nested.
16773 */
16774 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16775 + je 1f
16776 cmpl $__KERNEL_CS, 16(%rsp)
16777 jne first_nmi
16778 -
16779 +1:
16780 /*
16781 * Check the special variable on the stack to see if NMIs are
16782 * executing.
16783 @@ -1659,6 +2050,16 @@ restart_nmi:
16784 */
16785 call save_paranoid
16786 DEFAULT_FRAME 0
16787 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16788 + testb $3, CS(%rsp)
16789 + jnz 1f
16790 + pax_enter_kernel
16791 + jmp 2f
16792 +1: pax_enter_kernel_user
16793 +2:
16794 +#else
16795 + pax_enter_kernel
16796 +#endif
16797 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16798 movq %rsp,%rdi
16799 movq $-1,%rsi
16800 @@ -1666,14 +2067,25 @@ restart_nmi:
16801 testl %ebx,%ebx /* swapgs needed? */
16802 jnz nmi_restore
16803 nmi_swapgs:
16804 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16805 + pax_exit_kernel_user
16806 +#else
16807 + pax_exit_kernel
16808 +#endif
16809 SWAPGS_UNSAFE_STACK
16810 + RESTORE_ALL 8
16811 + /* Clear the NMI executing stack variable */
16812 + movq $0, 10*8(%rsp)
16813 + jmp irq_return
16814 nmi_restore:
16815 + pax_exit_kernel
16816 RESTORE_ALL 8
16817 + pax_force_retaddr_bts
16818 /* Clear the NMI executing stack variable */
16819 movq $0, 10*8(%rsp)
16820 jmp irq_return
16821 CFI_ENDPROC
16822 -END(nmi)
16823 +ENDPROC(nmi)
16824
16825 /*
16826 * If an NMI hit an iret because of an exception or breakpoint,
16827 @@ -1700,7 +2112,7 @@ ENTRY(ignore_sysret)
16828 mov $-ENOSYS,%eax
16829 sysret
16830 CFI_ENDPROC
16831 -END(ignore_sysret)
16832 +ENDPROC(ignore_sysret)
16833
16834 /*
16835 * End of kprobes section
16836 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16837 index c9a281f..ce2f317 100644
16838 --- a/arch/x86/kernel/ftrace.c
16839 +++ b/arch/x86/kernel/ftrace.c
16840 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16841 static const void *mod_code_newcode; /* holds the text to write to the IP */
16842
16843 static unsigned nmi_wait_count;
16844 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16845 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16846
16847 int ftrace_arch_read_dyn_info(char *buf, int size)
16848 {
16849 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16850
16851 r = snprintf(buf, size, "%u %u",
16852 nmi_wait_count,
16853 - atomic_read(&nmi_update_count));
16854 + atomic_read_unchecked(&nmi_update_count));
16855 return r;
16856 }
16857
16858 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16859
16860 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16861 smp_rmb();
16862 + pax_open_kernel();
16863 ftrace_mod_code();
16864 - atomic_inc(&nmi_update_count);
16865 + pax_close_kernel();
16866 + atomic_inc_unchecked(&nmi_update_count);
16867 }
16868 /* Must have previous changes seen before executions */
16869 smp_mb();
16870 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16871 {
16872 unsigned char replaced[MCOUNT_INSN_SIZE];
16873
16874 + ip = ktla_ktva(ip);
16875 +
16876 /*
16877 * Note: Due to modules and __init, code can
16878 * disappear and change, we need to protect against faulting
16879 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16880 unsigned char old[MCOUNT_INSN_SIZE], *new;
16881 int ret;
16882
16883 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16884 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16885 new = ftrace_call_replace(ip, (unsigned long)func);
16886 ret = ftrace_modify_code(ip, old, new);
16887
16888 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16889 {
16890 unsigned char code[MCOUNT_INSN_SIZE];
16891
16892 + ip = ktla_ktva(ip);
16893 +
16894 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16895 return -EFAULT;
16896
16897 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16898 index 51ff186..9e77418 100644
16899 --- a/arch/x86/kernel/head32.c
16900 +++ b/arch/x86/kernel/head32.c
16901 @@ -19,6 +19,7 @@
16902 #include <asm/io_apic.h>
16903 #include <asm/bios_ebda.h>
16904 #include <asm/tlbflush.h>
16905 +#include <asm/boot.h>
16906
16907 static void __init i386_default_early_setup(void)
16908 {
16909 @@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16910
16911 void __init i386_start_kernel(void)
16912 {
16913 - memblock_reserve(__pa_symbol(&_text),
16914 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16915 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16916
16917 #ifdef CONFIG_BLK_DEV_INITRD
16918 /* Reserve INITRD */
16919 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16920 index ce0be7c..c41476e 100644
16921 --- a/arch/x86/kernel/head_32.S
16922 +++ b/arch/x86/kernel/head_32.S
16923 @@ -25,6 +25,12 @@
16924 /* Physical address */
16925 #define pa(X) ((X) - __PAGE_OFFSET)
16926
16927 +#ifdef CONFIG_PAX_KERNEXEC
16928 +#define ta(X) (X)
16929 +#else
16930 +#define ta(X) ((X) - __PAGE_OFFSET)
16931 +#endif
16932 +
16933 /*
16934 * References to members of the new_cpu_data structure.
16935 */
16936 @@ -54,11 +60,7 @@
16937 * and small than max_low_pfn, otherwise will waste some page table entries
16938 */
16939
16940 -#if PTRS_PER_PMD > 1
16941 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16942 -#else
16943 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16944 -#endif
16945 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16946
16947 /* Number of possible pages in the lowmem region */
16948 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16949 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16950 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16951
16952 /*
16953 + * Real beginning of normal "text" segment
16954 + */
16955 +ENTRY(stext)
16956 +ENTRY(_stext)
16957 +
16958 +/*
16959 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16960 * %esi points to the real-mode code as a 32-bit pointer.
16961 * CS and DS must be 4 GB flat segments, but we don't depend on
16962 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16963 * can.
16964 */
16965 __HEAD
16966 +
16967 +#ifdef CONFIG_PAX_KERNEXEC
16968 + jmp startup_32
16969 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16970 +.fill PAGE_SIZE-5,1,0xcc
16971 +#endif
16972 +
16973 ENTRY(startup_32)
16974 movl pa(stack_start),%ecx
16975
16976 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16977 2:
16978 leal -__PAGE_OFFSET(%ecx),%esp
16979
16980 +#ifdef CONFIG_SMP
16981 + movl $pa(cpu_gdt_table),%edi
16982 + movl $__per_cpu_load,%eax
16983 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16984 + rorl $16,%eax
16985 + movb %al,__KERNEL_PERCPU + 4(%edi)
16986 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16987 + movl $__per_cpu_end - 1,%eax
16988 + subl $__per_cpu_start,%eax
16989 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16990 +#endif
16991 +
16992 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16993 + movl $NR_CPUS,%ecx
16994 + movl $pa(cpu_gdt_table),%edi
16995 +1:
16996 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16997 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16998 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16999 + addl $PAGE_SIZE_asm,%edi
17000 + loop 1b
17001 +#endif
17002 +
17003 +#ifdef CONFIG_PAX_KERNEXEC
17004 + movl $pa(boot_gdt),%edi
17005 + movl $__LOAD_PHYSICAL_ADDR,%eax
17006 + movw %ax,__BOOT_CS + 2(%edi)
17007 + rorl $16,%eax
17008 + movb %al,__BOOT_CS + 4(%edi)
17009 + movb %ah,__BOOT_CS + 7(%edi)
17010 + rorl $16,%eax
17011 +
17012 + ljmp $(__BOOT_CS),$1f
17013 +1:
17014 +
17015 + movl $NR_CPUS,%ecx
17016 + movl $pa(cpu_gdt_table),%edi
17017 + addl $__PAGE_OFFSET,%eax
17018 +1:
17019 + movw %ax,__KERNEL_CS + 2(%edi)
17020 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
17021 + rorl $16,%eax
17022 + movb %al,__KERNEL_CS + 4(%edi)
17023 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
17024 + movb %ah,__KERNEL_CS + 7(%edi)
17025 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
17026 + rorl $16,%eax
17027 + addl $PAGE_SIZE_asm,%edi
17028 + loop 1b
17029 +#endif
17030 +
17031 /*
17032 * Clear BSS first so that there are no surprises...
17033 */
17034 @@ -195,8 +261,11 @@ ENTRY(startup_32)
17035 movl %eax, pa(max_pfn_mapped)
17036
17037 /* Do early initialization of the fixmap area */
17038 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17039 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
17040 +#ifdef CONFIG_COMPAT_VDSO
17041 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
17042 +#else
17043 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
17044 +#endif
17045 #else /* Not PAE */
17046
17047 page_pde_offset = (__PAGE_OFFSET >> 20);
17048 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17049 movl %eax, pa(max_pfn_mapped)
17050
17051 /* Do early initialization of the fixmap area */
17052 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
17053 - movl %eax,pa(initial_page_table+0xffc)
17054 +#ifdef CONFIG_COMPAT_VDSO
17055 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
17056 +#else
17057 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
17058 +#endif
17059 #endif
17060
17061 #ifdef CONFIG_PARAVIRT
17062 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
17063 cmpl $num_subarch_entries, %eax
17064 jae bad_subarch
17065
17066 - movl pa(subarch_entries)(,%eax,4), %eax
17067 - subl $__PAGE_OFFSET, %eax
17068 - jmp *%eax
17069 + jmp *pa(subarch_entries)(,%eax,4)
17070
17071 bad_subarch:
17072 WEAK(lguest_entry)
17073 @@ -255,10 +325,10 @@ WEAK(xen_entry)
17074 __INITDATA
17075
17076 subarch_entries:
17077 - .long default_entry /* normal x86/PC */
17078 - .long lguest_entry /* lguest hypervisor */
17079 - .long xen_entry /* Xen hypervisor */
17080 - .long default_entry /* Moorestown MID */
17081 + .long ta(default_entry) /* normal x86/PC */
17082 + .long ta(lguest_entry) /* lguest hypervisor */
17083 + .long ta(xen_entry) /* Xen hypervisor */
17084 + .long ta(default_entry) /* Moorestown MID */
17085 num_subarch_entries = (. - subarch_entries) / 4
17086 .previous
17087 #else
17088 @@ -312,6 +382,7 @@ default_entry:
17089 orl %edx,%eax
17090 movl %eax,%cr4
17091
17092 +#ifdef CONFIG_X86_PAE
17093 testb $X86_CR4_PAE, %al # check if PAE is enabled
17094 jz 6f
17095
17096 @@ -340,6 +411,9 @@ default_entry:
17097 /* Make changes effective */
17098 wrmsr
17099
17100 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17101 +#endif
17102 +
17103 6:
17104
17105 /*
17106 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
17107 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17108 movl %eax,%ss # after changing gdt.
17109
17110 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17111 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17112 movl %eax,%ds
17113 movl %eax,%es
17114
17115 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
17116 */
17117 cmpb $0,ready
17118 jne 1f
17119 - movl $gdt_page,%eax
17120 + movl $cpu_gdt_table,%eax
17121 movl $stack_canary,%ecx
17122 +#ifdef CONFIG_SMP
17123 + addl $__per_cpu_load,%ecx
17124 +#endif
17125 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17126 shrl $16, %ecx
17127 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17128 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
17129 1:
17130 -#endif
17131 movl $(__KERNEL_STACK_CANARY),%eax
17132 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17133 + movl $(__USER_DS),%eax
17134 +#else
17135 + xorl %eax,%eax
17136 +#endif
17137 movl %eax,%gs
17138
17139 xorl %eax,%eax # Clear LDT
17140 @@ -558,22 +639,22 @@ early_page_fault:
17141 jmp early_fault
17142
17143 early_fault:
17144 - cld
17145 #ifdef CONFIG_PRINTK
17146 + cmpl $1,%ss:early_recursion_flag
17147 + je hlt_loop
17148 + incl %ss:early_recursion_flag
17149 + cld
17150 pusha
17151 movl $(__KERNEL_DS),%eax
17152 movl %eax,%ds
17153 movl %eax,%es
17154 - cmpl $2,early_recursion_flag
17155 - je hlt_loop
17156 - incl early_recursion_flag
17157 movl %cr2,%eax
17158 pushl %eax
17159 pushl %edx /* trapno */
17160 pushl $fault_msg
17161 call printk
17162 +; call dump_stack
17163 #endif
17164 - call dump_stack
17165 hlt_loop:
17166 hlt
17167 jmp hlt_loop
17168 @@ -581,8 +662,11 @@ hlt_loop:
17169 /* This is the default interrupt "handler" :-) */
17170 ALIGN
17171 ignore_int:
17172 - cld
17173 #ifdef CONFIG_PRINTK
17174 + cmpl $2,%ss:early_recursion_flag
17175 + je hlt_loop
17176 + incl %ss:early_recursion_flag
17177 + cld
17178 pushl %eax
17179 pushl %ecx
17180 pushl %edx
17181 @@ -591,9 +675,6 @@ ignore_int:
17182 movl $(__KERNEL_DS),%eax
17183 movl %eax,%ds
17184 movl %eax,%es
17185 - cmpl $2,early_recursion_flag
17186 - je hlt_loop
17187 - incl early_recursion_flag
17188 pushl 16(%esp)
17189 pushl 24(%esp)
17190 pushl 32(%esp)
17191 @@ -622,29 +703,43 @@ ENTRY(initial_code)
17192 /*
17193 * BSS section
17194 */
17195 -__PAGE_ALIGNED_BSS
17196 - .align PAGE_SIZE
17197 #ifdef CONFIG_X86_PAE
17198 +.section .initial_pg_pmd,"a",@progbits
17199 initial_pg_pmd:
17200 .fill 1024*KPMDS,4,0
17201 #else
17202 +.section .initial_page_table,"a",@progbits
17203 ENTRY(initial_page_table)
17204 .fill 1024,4,0
17205 #endif
17206 +.section .initial_pg_fixmap,"a",@progbits
17207 initial_pg_fixmap:
17208 .fill 1024,4,0
17209 +.section .empty_zero_page,"a",@progbits
17210 ENTRY(empty_zero_page)
17211 .fill 4096,1,0
17212 +.section .swapper_pg_dir,"a",@progbits
17213 ENTRY(swapper_pg_dir)
17214 +#ifdef CONFIG_X86_PAE
17215 + .fill 4,8,0
17216 +#else
17217 .fill 1024,4,0
17218 +#endif
17219 +
17220 +/*
17221 + * The IDT has to be page-aligned to simplify the Pentium
17222 + * F0 0F bug workaround.. We have a special link segment
17223 + * for this.
17224 + */
17225 +.section .idt,"a",@progbits
17226 +ENTRY(idt_table)
17227 + .fill 256,8,0
17228
17229 /*
17230 * This starts the data section.
17231 */
17232 #ifdef CONFIG_X86_PAE
17233 -__PAGE_ALIGNED_DATA
17234 - /* Page-aligned for the benefit of paravirt? */
17235 - .align PAGE_SIZE
17236 +.section .initial_page_table,"a",@progbits
17237 ENTRY(initial_page_table)
17238 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17239 # if KPMDS == 3
17240 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
17241 # error "Kernel PMDs should be 1, 2 or 3"
17242 # endif
17243 .align PAGE_SIZE /* needs to be page-sized too */
17244 +
17245 +#ifdef CONFIG_PAX_PER_CPU_PGD
17246 +ENTRY(cpu_pgd)
17247 + .rept NR_CPUS
17248 + .fill 4,8,0
17249 + .endr
17250 +#endif
17251 +
17252 #endif
17253
17254 .data
17255 .balign 4
17256 ENTRY(stack_start)
17257 - .long init_thread_union+THREAD_SIZE
17258 + .long init_thread_union+THREAD_SIZE-8
17259
17260 +ready: .byte 0
17261 +
17262 +.section .rodata,"a",@progbits
17263 early_recursion_flag:
17264 .long 0
17265
17266 -ready: .byte 0
17267 -
17268 int_msg:
17269 .asciz "Unknown interrupt or fault at: %p %p %p\n"
17270
17271 @@ -707,7 +811,7 @@ fault_msg:
17272 .word 0 # 32 bit align gdt_desc.address
17273 boot_gdt_descr:
17274 .word __BOOT_DS+7
17275 - .long boot_gdt - __PAGE_OFFSET
17276 + .long pa(boot_gdt)
17277
17278 .word 0 # 32-bit align idt_desc.address
17279 idt_descr:
17280 @@ -718,7 +822,7 @@ idt_descr:
17281 .word 0 # 32 bit align gdt_desc.address
17282 ENTRY(early_gdt_descr)
17283 .word GDT_ENTRIES*8-1
17284 - .long gdt_page /* Overwritten for secondary CPUs */
17285 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17286
17287 /*
17288 * The boot_gdt must mirror the equivalent in setup.S and is
17289 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
17290 .align L1_CACHE_BYTES
17291 ENTRY(boot_gdt)
17292 .fill GDT_ENTRY_BOOT_CS,8,0
17293 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17294 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17295 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17296 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17297 +
17298 + .align PAGE_SIZE_asm
17299 +ENTRY(cpu_gdt_table)
17300 + .rept NR_CPUS
17301 + .quad 0x0000000000000000 /* NULL descriptor */
17302 + .quad 0x0000000000000000 /* 0x0b reserved */
17303 + .quad 0x0000000000000000 /* 0x13 reserved */
17304 + .quad 0x0000000000000000 /* 0x1b reserved */
17305 +
17306 +#ifdef CONFIG_PAX_KERNEXEC
17307 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17308 +#else
17309 + .quad 0x0000000000000000 /* 0x20 unused */
17310 +#endif
17311 +
17312 + .quad 0x0000000000000000 /* 0x28 unused */
17313 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17314 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17315 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17316 + .quad 0x0000000000000000 /* 0x4b reserved */
17317 + .quad 0x0000000000000000 /* 0x53 reserved */
17318 + .quad 0x0000000000000000 /* 0x5b reserved */
17319 +
17320 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17321 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17322 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17323 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17324 +
17325 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17326 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17327 +
17328 + /*
17329 + * Segments used for calling PnP BIOS have byte granularity.
17330 + * The code segments and data segments have fixed 64k limits,
17331 + * the transfer segment sizes are set at run time.
17332 + */
17333 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17334 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17335 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17336 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17337 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17338 +
17339 + /*
17340 + * The APM segments have byte granularity and their bases
17341 + * are set at run time. All have 64k limits.
17342 + */
17343 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17344 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17345 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17346 +
17347 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17348 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17349 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17350 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17351 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17352 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17353 +
17354 + /* Be sure this is zeroed to avoid false validations in Xen */
17355 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17356 + .endr
17357 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17358 index 40f4eb3..6d24d9d 100644
17359 --- a/arch/x86/kernel/head_64.S
17360 +++ b/arch/x86/kernel/head_64.S
17361 @@ -19,6 +19,8 @@
17362 #include <asm/cache.h>
17363 #include <asm/processor-flags.h>
17364 #include <asm/percpu.h>
17365 +#include <asm/cpufeature.h>
17366 +#include <asm/alternative-asm.h>
17367
17368 #ifdef CONFIG_PARAVIRT
17369 #include <asm/asm-offsets.h>
17370 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17371 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17372 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17373 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17374 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17375 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17376 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17377 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17378 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17379 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17380
17381 .text
17382 __HEAD
17383 @@ -85,35 +93,23 @@ startup_64:
17384 */
17385 addq %rbp, init_level4_pgt + 0(%rip)
17386 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17387 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17388 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17389 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17390 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17391
17392 addq %rbp, level3_ident_pgt + 0(%rip)
17393 +#ifndef CONFIG_XEN
17394 + addq %rbp, level3_ident_pgt + 8(%rip)
17395 +#endif
17396
17397 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17398 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17399 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17400 +
17401 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17402 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17403
17404 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17405 -
17406 - /* Add an Identity mapping if I am above 1G */
17407 - leaq _text(%rip), %rdi
17408 - andq $PMD_PAGE_MASK, %rdi
17409 -
17410 - movq %rdi, %rax
17411 - shrq $PUD_SHIFT, %rax
17412 - andq $(PTRS_PER_PUD - 1), %rax
17413 - jz ident_complete
17414 -
17415 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17416 - leaq level3_ident_pgt(%rip), %rbx
17417 - movq %rdx, 0(%rbx, %rax, 8)
17418 -
17419 - movq %rdi, %rax
17420 - shrq $PMD_SHIFT, %rax
17421 - andq $(PTRS_PER_PMD - 1), %rax
17422 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17423 - leaq level2_spare_pgt(%rip), %rbx
17424 - movq %rdx, 0(%rbx, %rax, 8)
17425 -ident_complete:
17426 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17427
17428 /*
17429 * Fixup the kernel text+data virtual addresses. Note that
17430 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
17431 * after the boot processor executes this code.
17432 */
17433
17434 - /* Enable PAE mode and PGE */
17435 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17436 + /* Enable PAE mode and PSE/PGE */
17437 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17438 movq %rax, %cr4
17439
17440 /* Setup early boot stage 4 level pagetables. */
17441 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
17442 movl $MSR_EFER, %ecx
17443 rdmsr
17444 btsl $_EFER_SCE, %eax /* Enable System Call */
17445 - btl $20,%edi /* No Execute supported? */
17446 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17447 jnc 1f
17448 btsl $_EFER_NX, %eax
17449 + leaq init_level4_pgt(%rip), %rdi
17450 +#ifndef CONFIG_EFI
17451 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17452 +#endif
17453 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17454 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17455 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17456 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17457 1: wrmsr /* Make changes effective */
17458
17459 /* Setup cr0 */
17460 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
17461 * jump. In addition we need to ensure %cs is set so we make this
17462 * a far return.
17463 */
17464 + pax_set_fptr_mask
17465 movq initial_code(%rip),%rax
17466 pushq $0 # fake return address to stop unwinder
17467 pushq $__KERNEL_CS # set correct cs
17468 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
17469 bad_address:
17470 jmp bad_address
17471
17472 - .section ".init.text","ax"
17473 + __INIT
17474 #ifdef CONFIG_EARLY_PRINTK
17475 .globl early_idt_handlers
17476 early_idt_handlers:
17477 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
17478 #endif /* EARLY_PRINTK */
17479 1: hlt
17480 jmp 1b
17481 + .previous
17482
17483 #ifdef CONFIG_EARLY_PRINTK
17484 + __INITDATA
17485 early_recursion_flag:
17486 .long 0
17487 + .previous
17488
17489 + .section .rodata,"a",@progbits
17490 early_idt_msg:
17491 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17492 early_idt_ripmsg:
17493 .asciz "RIP %s\n"
17494 + .previous
17495 #endif /* CONFIG_EARLY_PRINTK */
17496 - .previous
17497
17498 + .section .rodata,"a",@progbits
17499 #define NEXT_PAGE(name) \
17500 .balign PAGE_SIZE; \
17501 ENTRY(name)
17502 @@ -338,7 +348,6 @@ ENTRY(name)
17503 i = i + 1 ; \
17504 .endr
17505
17506 - .data
17507 /*
17508 * This default setting generates an ident mapping at address 0x100000
17509 * and a mapping for the kernel that precisely maps virtual address
17510 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
17511 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17512 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17513 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17514 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17515 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17516 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17517 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17518 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17519 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17520 .org init_level4_pgt + L4_START_KERNEL*8, 0
17521 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17522 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17523
17524 +#ifdef CONFIG_PAX_PER_CPU_PGD
17525 +NEXT_PAGE(cpu_pgd)
17526 + .rept NR_CPUS
17527 + .fill 512,8,0
17528 + .endr
17529 +#endif
17530 +
17531 NEXT_PAGE(level3_ident_pgt)
17532 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17533 +#ifdef CONFIG_XEN
17534 .fill 511,8,0
17535 +#else
17536 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17537 + .fill 510,8,0
17538 +#endif
17539 +
17540 +NEXT_PAGE(level3_vmalloc_start_pgt)
17541 + .fill 512,8,0
17542 +
17543 +NEXT_PAGE(level3_vmalloc_end_pgt)
17544 + .fill 512,8,0
17545 +
17546 +NEXT_PAGE(level3_vmemmap_pgt)
17547 + .fill L3_VMEMMAP_START,8,0
17548 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17549
17550 NEXT_PAGE(level3_kernel_pgt)
17551 .fill L3_START_KERNEL,8,0
17552 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
17553 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17554 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17555
17556 +NEXT_PAGE(level2_vmemmap_pgt)
17557 + .fill 512,8,0
17558 +
17559 NEXT_PAGE(level2_fixmap_pgt)
17560 - .fill 506,8,0
17561 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17562 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17563 - .fill 5,8,0
17564 + .fill 507,8,0
17565 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17566 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17567 + .fill 4,8,0
17568
17569 -NEXT_PAGE(level1_fixmap_pgt)
17570 +NEXT_PAGE(level1_vsyscall_pgt)
17571 .fill 512,8,0
17572
17573 -NEXT_PAGE(level2_ident_pgt)
17574 - /* Since I easily can, map the first 1G.
17575 + /* Since I easily can, map the first 2G.
17576 * Don't set NX because code runs from these pages.
17577 */
17578 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17579 +NEXT_PAGE(level2_ident_pgt)
17580 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17581
17582 NEXT_PAGE(level2_kernel_pgt)
17583 /*
17584 @@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
17585 * If you want to increase this then increase MODULES_VADDR
17586 * too.)
17587 */
17588 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17589 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17590 -
17591 -NEXT_PAGE(level2_spare_pgt)
17592 - .fill 512, 8, 0
17593 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17594
17595 #undef PMDS
17596 #undef NEXT_PAGE
17597
17598 - .data
17599 + .align PAGE_SIZE
17600 +ENTRY(cpu_gdt_table)
17601 + .rept NR_CPUS
17602 + .quad 0x0000000000000000 /* NULL descriptor */
17603 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17604 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17605 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17606 + .quad 0x00cffb000000ffff /* __USER32_CS */
17607 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17608 + .quad 0x00affb000000ffff /* __USER_CS */
17609 +
17610 +#ifdef CONFIG_PAX_KERNEXEC
17611 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17612 +#else
17613 + .quad 0x0 /* unused */
17614 +#endif
17615 +
17616 + .quad 0,0 /* TSS */
17617 + .quad 0,0 /* LDT */
17618 + .quad 0,0,0 /* three TLS descriptors */
17619 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17620 + /* asm/segment.h:GDT_ENTRIES must match this */
17621 +
17622 + /* zero the remaining page */
17623 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17624 + .endr
17625 +
17626 .align 16
17627 .globl early_gdt_descr
17628 early_gdt_descr:
17629 .word GDT_ENTRIES*8-1
17630 early_gdt_descr_base:
17631 - .quad INIT_PER_CPU_VAR(gdt_page)
17632 + .quad cpu_gdt_table
17633
17634 ENTRY(phys_base)
17635 /* This must match the first entry in level2_kernel_pgt */
17636 .quad 0x0000000000000000
17637
17638 #include "../../x86/xen/xen-head.S"
17639 -
17640 - .section .bss, "aw", @nobits
17641 +
17642 + .section .rodata,"a",@progbits
17643 .align L1_CACHE_BYTES
17644 ENTRY(idt_table)
17645 - .skip IDT_ENTRIES * 16
17646 + .fill 512,8,0
17647
17648 .align L1_CACHE_BYTES
17649 ENTRY(nmi_idt_table)
17650 - .skip IDT_ENTRIES * 16
17651 + .fill 512,8,0
17652
17653 __PAGE_ALIGNED_BSS
17654 .align PAGE_SIZE
17655 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17656 index 9c3bd4a..e1d9b35 100644
17657 --- a/arch/x86/kernel/i386_ksyms_32.c
17658 +++ b/arch/x86/kernel/i386_ksyms_32.c
17659 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17660 EXPORT_SYMBOL(cmpxchg8b_emu);
17661 #endif
17662
17663 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17664 +
17665 /* Networking helper routines. */
17666 EXPORT_SYMBOL(csum_partial_copy_generic);
17667 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17668 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17669
17670 EXPORT_SYMBOL(__get_user_1);
17671 EXPORT_SYMBOL(__get_user_2);
17672 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17673
17674 EXPORT_SYMBOL(csum_partial);
17675 EXPORT_SYMBOL(empty_zero_page);
17676 +
17677 +#ifdef CONFIG_PAX_KERNEXEC
17678 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17679 +#endif
17680 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17681 index f239f30..aab2a58 100644
17682 --- a/arch/x86/kernel/i387.c
17683 +++ b/arch/x86/kernel/i387.c
17684 @@ -189,6 +189,9 @@ int xfpregs_active(struct task_struct *target, const struct user_regset *regset)
17685
17686 int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17687 unsigned int pos, unsigned int count,
17688 + void *kbuf, void __user *ubuf) __size_overflow(4);
17689 +int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17690 + unsigned int pos, unsigned int count,
17691 void *kbuf, void __user *ubuf)
17692 {
17693 int ret;
17694 @@ -208,6 +211,9 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
17695
17696 int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17697 unsigned int pos, unsigned int count,
17698 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17699 +int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17700 + unsigned int pos, unsigned int count,
17701 const void *kbuf, const void __user *ubuf)
17702 {
17703 int ret;
17704 @@ -241,6 +247,9 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
17705
17706 int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17707 unsigned int pos, unsigned int count,
17708 + void *kbuf, void __user *ubuf) __size_overflow(4);
17709 +int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17710 + unsigned int pos, unsigned int count,
17711 void *kbuf, void __user *ubuf)
17712 {
17713 int ret;
17714 @@ -270,6 +279,9 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
17715
17716 int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17717 unsigned int pos, unsigned int count,
17718 + const void *kbuf, const void __user *ubuf) __size_overflow(4);
17719 +int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
17720 + unsigned int pos, unsigned int count,
17721 const void *kbuf, const void __user *ubuf)
17722 {
17723 int ret;
17724 @@ -440,6 +452,9 @@ static void convert_to_fxsr(struct task_struct *tsk,
17725
17726 int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17727 unsigned int pos, unsigned int count,
17728 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
17729 +int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17730 + unsigned int pos, unsigned int count,
17731 void *kbuf, void __user *ubuf)
17732 {
17733 struct user_i387_ia32_struct env;
17734 @@ -472,6 +487,9 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
17735
17736 int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17737 unsigned int pos, unsigned int count,
17738 + const void *kbuf, const void __user *ubuf) __size_overflow(3,4);
17739 +int fpregs_set(struct task_struct *target, const struct user_regset *regset,
17740 + unsigned int pos, unsigned int count,
17741 const void *kbuf, const void __user *ubuf)
17742 {
17743 struct user_i387_ia32_struct env;
17744 @@ -620,6 +638,8 @@ static inline int restore_i387_fsave(struct _fpstate_ia32 __user *buf)
17745 }
17746
17747 static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17748 + unsigned int size) __size_overflow(2);
17749 +static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
17750 unsigned int size)
17751 {
17752 struct task_struct *tsk = current;
17753 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17754 index 6104852..6114160 100644
17755 --- a/arch/x86/kernel/i8259.c
17756 +++ b/arch/x86/kernel/i8259.c
17757 @@ -210,7 +210,7 @@ spurious_8259A_irq:
17758 "spurious 8259A interrupt: IRQ%d.\n", irq);
17759 spurious_irq_mask |= irqmask;
17760 }
17761 - atomic_inc(&irq_err_count);
17762 + atomic_inc_unchecked(&irq_err_count);
17763 /*
17764 * Theoretically we do not have to handle this IRQ,
17765 * but in Linux this does not cause problems and is
17766 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17767 index 43e9ccf..44ccf6f 100644
17768 --- a/arch/x86/kernel/init_task.c
17769 +++ b/arch/x86/kernel/init_task.c
17770 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17771 * way process stacks are handled. This is done by having a special
17772 * "init_task" linker map entry..
17773 */
17774 -union thread_union init_thread_union __init_task_data =
17775 - { INIT_THREAD_INFO(init_task) };
17776 +union thread_union init_thread_union __init_task_data;
17777
17778 /*
17779 * Initial task structure.
17780 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17781 * section. Since TSS's are completely CPU-local, we want them
17782 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17783 */
17784 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17785 -
17786 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17787 +EXPORT_SYMBOL(init_tss);
17788 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17789 index 8c96897..be66bfa 100644
17790 --- a/arch/x86/kernel/ioport.c
17791 +++ b/arch/x86/kernel/ioport.c
17792 @@ -6,6 +6,7 @@
17793 #include <linux/sched.h>
17794 #include <linux/kernel.h>
17795 #include <linux/capability.h>
17796 +#include <linux/security.h>
17797 #include <linux/errno.h>
17798 #include <linux/types.h>
17799 #include <linux/ioport.h>
17800 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17801
17802 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17803 return -EINVAL;
17804 +#ifdef CONFIG_GRKERNSEC_IO
17805 + if (turn_on && grsec_disable_privio) {
17806 + gr_handle_ioperm();
17807 + return -EPERM;
17808 + }
17809 +#endif
17810 if (turn_on && !capable(CAP_SYS_RAWIO))
17811 return -EPERM;
17812
17813 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17814 * because the ->io_bitmap_max value must match the bitmap
17815 * contents:
17816 */
17817 - tss = &per_cpu(init_tss, get_cpu());
17818 + tss = init_tss + get_cpu();
17819
17820 if (turn_on)
17821 bitmap_clear(t->io_bitmap_ptr, from, num);
17822 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17823 return -EINVAL;
17824 /* Trying to gain more privileges? */
17825 if (level > old) {
17826 +#ifdef CONFIG_GRKERNSEC_IO
17827 + if (grsec_disable_privio) {
17828 + gr_handle_iopl();
17829 + return -EPERM;
17830 + }
17831 +#endif
17832 if (!capable(CAP_SYS_RAWIO))
17833 return -EPERM;
17834 }
17835 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17836 index 7943e0c..dd32c5c 100644
17837 --- a/arch/x86/kernel/irq.c
17838 +++ b/arch/x86/kernel/irq.c
17839 @@ -18,7 +18,7 @@
17840 #include <asm/mce.h>
17841 #include <asm/hw_irq.h>
17842
17843 -atomic_t irq_err_count;
17844 +atomic_unchecked_t irq_err_count;
17845
17846 /* Function pointer for generic interrupt vector handling */
17847 void (*x86_platform_ipi_callback)(void) = NULL;
17848 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17849 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17850 seq_printf(p, " Machine check polls\n");
17851 #endif
17852 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17853 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17854 #if defined(CONFIG_X86_IO_APIC)
17855 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17856 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17857 #endif
17858 return 0;
17859 }
17860 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17861
17862 u64 arch_irq_stat(void)
17863 {
17864 - u64 sum = atomic_read(&irq_err_count);
17865 + u64 sum = atomic_read_unchecked(&irq_err_count);
17866
17867 #ifdef CONFIG_X86_IO_APIC
17868 - sum += atomic_read(&irq_mis_count);
17869 + sum += atomic_read_unchecked(&irq_mis_count);
17870 #endif
17871 return sum;
17872 }
17873 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17874 index 40fc861..9b8739b 100644
17875 --- a/arch/x86/kernel/irq_32.c
17876 +++ b/arch/x86/kernel/irq_32.c
17877 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17878 __asm__ __volatile__("andl %%esp,%0" :
17879 "=r" (sp) : "0" (THREAD_SIZE - 1));
17880
17881 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17882 + return sp < STACK_WARN;
17883 }
17884
17885 static void print_stack_overflow(void)
17886 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17887 * per-CPU IRQ handling contexts (thread information and stack)
17888 */
17889 union irq_ctx {
17890 - struct thread_info tinfo;
17891 - u32 stack[THREAD_SIZE/sizeof(u32)];
17892 + unsigned long previous_esp;
17893 + u32 stack[THREAD_SIZE/sizeof(u32)];
17894 } __attribute__((aligned(THREAD_SIZE)));
17895
17896 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17897 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17898 static inline int
17899 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17900 {
17901 - union irq_ctx *curctx, *irqctx;
17902 + union irq_ctx *irqctx;
17903 u32 *isp, arg1, arg2;
17904
17905 - curctx = (union irq_ctx *) current_thread_info();
17906 irqctx = __this_cpu_read(hardirq_ctx);
17907
17908 /*
17909 @@ -92,21 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17910 * handler) we can't do that and just have to keep using the
17911 * current stack (which is the irq stack already after all)
17912 */
17913 - if (unlikely(curctx == irqctx))
17914 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17915 return 0;
17916
17917 /* build the stack frame on the IRQ stack */
17918 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17919 - irqctx->tinfo.task = curctx->tinfo.task;
17920 - irqctx->tinfo.previous_esp = current_stack_pointer;
17921 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17922 + irqctx->previous_esp = current_stack_pointer;
17923
17924 - /*
17925 - * Copy the softirq bits in preempt_count so that the
17926 - * softirq checks work in the hardirq context.
17927 - */
17928 - irqctx->tinfo.preempt_count =
17929 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17930 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17931 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17932 + __set_fs(MAKE_MM_SEG(0));
17933 +#endif
17934
17935 if (unlikely(overflow))
17936 call_on_stack(print_stack_overflow, isp);
17937 @@ -118,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17938 : "0" (irq), "1" (desc), "2" (isp),
17939 "D" (desc->handle_irq)
17940 : "memory", "cc", "ecx");
17941 +
17942 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17943 + __set_fs(current_thread_info()->addr_limit);
17944 +#endif
17945 +
17946 return 1;
17947 }
17948
17949 @@ -126,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17950 */
17951 void __cpuinit irq_ctx_init(int cpu)
17952 {
17953 - union irq_ctx *irqctx;
17954 -
17955 if (per_cpu(hardirq_ctx, cpu))
17956 return;
17957
17958 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17959 - THREAD_FLAGS,
17960 - THREAD_ORDER));
17961 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17962 - irqctx->tinfo.cpu = cpu;
17963 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17964 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17965 -
17966 - per_cpu(hardirq_ctx, cpu) = irqctx;
17967 -
17968 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17969 - THREAD_FLAGS,
17970 - THREAD_ORDER));
17971 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17972 - irqctx->tinfo.cpu = cpu;
17973 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17974 -
17975 - per_cpu(softirq_ctx, cpu) = irqctx;
17976 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17977 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17978
17979 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17980 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17981 @@ -157,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17982 asmlinkage void do_softirq(void)
17983 {
17984 unsigned long flags;
17985 - struct thread_info *curctx;
17986 union irq_ctx *irqctx;
17987 u32 *isp;
17988
17989 @@ -167,15 +147,22 @@ asmlinkage void do_softirq(void)
17990 local_irq_save(flags);
17991
17992 if (local_softirq_pending()) {
17993 - curctx = current_thread_info();
17994 irqctx = __this_cpu_read(softirq_ctx);
17995 - irqctx->tinfo.task = curctx->task;
17996 - irqctx->tinfo.previous_esp = current_stack_pointer;
17997 + irqctx->previous_esp = current_stack_pointer;
17998
17999 /* build the stack frame on the softirq stack */
18000 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18001 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18002 +
18003 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18004 + __set_fs(MAKE_MM_SEG(0));
18005 +#endif
18006
18007 call_on_stack(__do_softirq, isp);
18008 +
18009 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18010 + __set_fs(current_thread_info()->addr_limit);
18011 +#endif
18012 +
18013 /*
18014 * Shouldn't happen, we returned above if in_interrupt():
18015 */
18016 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
18017 index d04d3ec..ea4b374 100644
18018 --- a/arch/x86/kernel/irq_64.c
18019 +++ b/arch/x86/kernel/irq_64.c
18020 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
18021 u64 estack_top, estack_bottom;
18022 u64 curbase = (u64)task_stack_page(current);
18023
18024 - if (user_mode_vm(regs))
18025 + if (user_mode(regs))
18026 return;
18027
18028 if (regs->sp >= curbase + sizeof(struct thread_info) +
18029 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
18030 index 90fcf62..e682cdd 100644
18031 --- a/arch/x86/kernel/kdebugfs.c
18032 +++ b/arch/x86/kernel/kdebugfs.c
18033 @@ -28,6 +28,8 @@ struct setup_data_node {
18034 };
18035
18036 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
18037 + size_t count, loff_t *ppos) __size_overflow(3);
18038 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
18039 size_t count, loff_t *ppos)
18040 {
18041 struct setup_data_node *node = file->private_data;
18042 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
18043 index 2f45c4c..d95504f 100644
18044 --- a/arch/x86/kernel/kgdb.c
18045 +++ b/arch/x86/kernel/kgdb.c
18046 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
18047 #ifdef CONFIG_X86_32
18048 switch (regno) {
18049 case GDB_SS:
18050 - if (!user_mode_vm(regs))
18051 + if (!user_mode(regs))
18052 *(unsigned long *)mem = __KERNEL_DS;
18053 break;
18054 case GDB_SP:
18055 - if (!user_mode_vm(regs))
18056 + if (!user_mode(regs))
18057 *(unsigned long *)mem = kernel_stack_pointer(regs);
18058 break;
18059 case GDB_GS:
18060 @@ -475,12 +475,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
18061 case 'k':
18062 /* clear the trace bit */
18063 linux_regs->flags &= ~X86_EFLAGS_TF;
18064 - atomic_set(&kgdb_cpu_doing_single_step, -1);
18065 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
18066
18067 /* set the trace bit if we're stepping */
18068 if (remcomInBuffer[0] == 's') {
18069 linux_regs->flags |= X86_EFLAGS_TF;
18070 - atomic_set(&kgdb_cpu_doing_single_step,
18071 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
18072 raw_smp_processor_id());
18073 }
18074
18075 @@ -545,7 +545,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
18076
18077 switch (cmd) {
18078 case DIE_DEBUG:
18079 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
18080 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
18081 if (user_mode(regs))
18082 return single_step_cont(regs, args);
18083 break;
18084 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
18085 index 7da647d..56fe348 100644
18086 --- a/arch/x86/kernel/kprobes.c
18087 +++ b/arch/x86/kernel/kprobes.c
18088 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
18089 } __attribute__((packed)) *insn;
18090
18091 insn = (struct __arch_relative_insn *)from;
18092 +
18093 + pax_open_kernel();
18094 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
18095 insn->op = op;
18096 + pax_close_kernel();
18097 }
18098
18099 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
18100 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
18101 kprobe_opcode_t opcode;
18102 kprobe_opcode_t *orig_opcodes = opcodes;
18103
18104 - if (search_exception_tables((unsigned long)opcodes))
18105 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
18106 return 0; /* Page fault may occur on this address. */
18107
18108 retry:
18109 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
18110 }
18111 }
18112 insn_get_length(&insn);
18113 + pax_open_kernel();
18114 memcpy(dest, insn.kaddr, insn.length);
18115 + pax_close_kernel();
18116
18117 #ifdef CONFIG_X86_64
18118 if (insn_rip_relative(&insn)) {
18119 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
18120 (u8 *) dest;
18121 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18122 disp = (u8 *) dest + insn_offset_displacement(&insn);
18123 + pax_open_kernel();
18124 *(s32 *) disp = (s32) newdisp;
18125 + pax_close_kernel();
18126 }
18127 #endif
18128 return insn.length;
18129 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
18130 */
18131 __copy_instruction(p->ainsn.insn, p->addr, 0);
18132
18133 - if (can_boost(p->addr))
18134 + if (can_boost(ktla_ktva(p->addr)))
18135 p->ainsn.boostable = 0;
18136 else
18137 p->ainsn.boostable = -1;
18138
18139 - p->opcode = *p->addr;
18140 + p->opcode = *(ktla_ktva(p->addr));
18141 }
18142
18143 int __kprobes arch_prepare_kprobe(struct kprobe *p)
18144 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
18145 * nor set current_kprobe, because it doesn't use single
18146 * stepping.
18147 */
18148 - regs->ip = (unsigned long)p->ainsn.insn;
18149 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18150 preempt_enable_no_resched();
18151 return;
18152 }
18153 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
18154 if (p->opcode == BREAKPOINT_INSTRUCTION)
18155 regs->ip = (unsigned long)p->addr;
18156 else
18157 - regs->ip = (unsigned long)p->ainsn.insn;
18158 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18159 }
18160
18161 /*
18162 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18163 setup_singlestep(p, regs, kcb, 0);
18164 return 1;
18165 }
18166 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18167 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18168 /*
18169 * The breakpoint instruction was removed right
18170 * after we hit it. Another cpu has removed
18171 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18172 " movq %rax, 152(%rsp)\n"
18173 RESTORE_REGS_STRING
18174 " popfq\n"
18175 +#ifdef KERNEXEC_PLUGIN
18176 + " btsq $63,(%rsp)\n"
18177 +#endif
18178 #else
18179 " pushf\n"
18180 SAVE_REGS_STRING
18181 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
18182 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18183 {
18184 unsigned long *tos = stack_addr(regs);
18185 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18186 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18187 unsigned long orig_ip = (unsigned long)p->addr;
18188 kprobe_opcode_t *insn = p->ainsn.insn;
18189
18190 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
18191 struct die_args *args = data;
18192 int ret = NOTIFY_DONE;
18193
18194 - if (args->regs && user_mode_vm(args->regs))
18195 + if (args->regs && user_mode(args->regs))
18196 return ret;
18197
18198 switch (val) {
18199 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18200 * Verify if the address gap is in 2GB range, because this uses
18201 * a relative jump.
18202 */
18203 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
18204 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
18205 if (abs(rel) > 0x7fffffff)
18206 return -ERANGE;
18207
18208 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
18209 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
18210
18211 /* Set probe function call */
18212 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
18213 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
18214
18215 /* Set returning jmp instruction at the tail of out-of-line buffer */
18216 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
18217 - (u8 *)op->kp.addr + op->optinsn.size);
18218 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
18219
18220 flush_icache_range((unsigned long) buf,
18221 (unsigned long) buf + TMPL_END_IDX +
18222 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
18223 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
18224
18225 /* Backup instructions which will be replaced by jump address */
18226 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
18227 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
18228 RELATIVE_ADDR_SIZE);
18229
18230 insn_buf[0] = RELATIVEJUMP_OPCODE;
18231 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18232 index ea69726..a305f16 100644
18233 --- a/arch/x86/kernel/ldt.c
18234 +++ b/arch/x86/kernel/ldt.c
18235 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18236 if (reload) {
18237 #ifdef CONFIG_SMP
18238 preempt_disable();
18239 - load_LDT(pc);
18240 + load_LDT_nolock(pc);
18241 if (!cpumask_equal(mm_cpumask(current->mm),
18242 cpumask_of(smp_processor_id())))
18243 smp_call_function(flush_ldt, current->mm, 1);
18244 preempt_enable();
18245 #else
18246 - load_LDT(pc);
18247 + load_LDT_nolock(pc);
18248 #endif
18249 }
18250 if (oldsize) {
18251 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18252 return err;
18253
18254 for (i = 0; i < old->size; i++)
18255 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18256 + write_ldt_entry(new->ldt, i, old->ldt + i);
18257 return 0;
18258 }
18259
18260 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18261 retval = copy_ldt(&mm->context, &old_mm->context);
18262 mutex_unlock(&old_mm->context.lock);
18263 }
18264 +
18265 + if (tsk == current) {
18266 + mm->context.vdso = 0;
18267 +
18268 +#ifdef CONFIG_X86_32
18269 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18270 + mm->context.user_cs_base = 0UL;
18271 + mm->context.user_cs_limit = ~0UL;
18272 +
18273 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18274 + cpus_clear(mm->context.cpu_user_cs_mask);
18275 +#endif
18276 +
18277 +#endif
18278 +#endif
18279 +
18280 + }
18281 +
18282 return retval;
18283 }
18284
18285 @@ -141,6 +159,7 @@ void destroy_context(struct mm_struct *mm)
18286 }
18287 }
18288
18289 +static int read_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
18290 static int read_ldt(void __user *ptr, unsigned long bytecount)
18291 {
18292 int err;
18293 @@ -175,6 +194,7 @@ error_return:
18294 return err;
18295 }
18296
18297 +static int read_default_ldt(void __user *ptr, unsigned long bytecount) __size_overflow(2);
18298 static int read_default_ldt(void __user *ptr, unsigned long bytecount)
18299 {
18300 /* CHECKME: Can we use _one_ random number ? */
18301 @@ -230,6 +250,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18302 }
18303 }
18304
18305 +#ifdef CONFIG_PAX_SEGMEXEC
18306 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18307 + error = -EINVAL;
18308 + goto out_unlock;
18309 + }
18310 +#endif
18311 +
18312 fill_ldt(&ldt, &ldt_info);
18313 if (oldmode)
18314 ldt.avl = 0;
18315 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18316 index a3fa43b..8966f4c 100644
18317 --- a/arch/x86/kernel/machine_kexec_32.c
18318 +++ b/arch/x86/kernel/machine_kexec_32.c
18319 @@ -27,7 +27,7 @@
18320 #include <asm/cacheflush.h>
18321 #include <asm/debugreg.h>
18322
18323 -static void set_idt(void *newidt, __u16 limit)
18324 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18325 {
18326 struct desc_ptr curidt;
18327
18328 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
18329 }
18330
18331
18332 -static void set_gdt(void *newgdt, __u16 limit)
18333 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18334 {
18335 struct desc_ptr curgdt;
18336
18337 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
18338 }
18339
18340 control_page = page_address(image->control_code_page);
18341 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18342 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18343
18344 relocate_kernel_ptr = control_page;
18345 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18346 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18347 index 3ca42d0..79d24cd 100644
18348 --- a/arch/x86/kernel/microcode_intel.c
18349 +++ b/arch/x86/kernel/microcode_intel.c
18350 @@ -434,15 +434,16 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18351 return ret;
18352 }
18353
18354 +static int get_ucode_user(void *to, const void *from, size_t n) __size_overflow(3);
18355 static int get_ucode_user(void *to, const void *from, size_t n)
18356 {
18357 - return copy_from_user(to, from, n);
18358 + return copy_from_user(to, (const void __force_user *)from, n);
18359 }
18360
18361 static enum ucode_state
18362 request_microcode_user(int cpu, const void __user *buf, size_t size)
18363 {
18364 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18365 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18366 }
18367
18368 static void microcode_fini_cpu(int cpu)
18369 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18370 index 925179f..1f0d561 100644
18371 --- a/arch/x86/kernel/module.c
18372 +++ b/arch/x86/kernel/module.c
18373 @@ -36,15 +36,61 @@
18374 #define DEBUGP(fmt...)
18375 #endif
18376
18377 -void *module_alloc(unsigned long size)
18378 +static inline void *__module_alloc(unsigned long size, pgprot_t prot) __size_overflow(1);
18379 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18380 {
18381 - if (PAGE_ALIGN(size) > MODULES_LEN)
18382 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18383 return NULL;
18384 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18385 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18386 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18387 -1, __builtin_return_address(0));
18388 }
18389
18390 +void *module_alloc(unsigned long size)
18391 +{
18392 +
18393 +#ifdef CONFIG_PAX_KERNEXEC
18394 + return __module_alloc(size, PAGE_KERNEL);
18395 +#else
18396 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18397 +#endif
18398 +
18399 +}
18400 +
18401 +#ifdef CONFIG_PAX_KERNEXEC
18402 +#ifdef CONFIG_X86_32
18403 +void *module_alloc_exec(unsigned long size)
18404 +{
18405 + struct vm_struct *area;
18406 +
18407 + if (size == 0)
18408 + return NULL;
18409 +
18410 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18411 + return area ? area->addr : NULL;
18412 +}
18413 +EXPORT_SYMBOL(module_alloc_exec);
18414 +
18415 +void module_free_exec(struct module *mod, void *module_region)
18416 +{
18417 + vunmap(module_region);
18418 +}
18419 +EXPORT_SYMBOL(module_free_exec);
18420 +#else
18421 +void module_free_exec(struct module *mod, void *module_region)
18422 +{
18423 + module_free(mod, module_region);
18424 +}
18425 +EXPORT_SYMBOL(module_free_exec);
18426 +
18427 +void *module_alloc_exec(unsigned long size)
18428 +{
18429 + return __module_alloc(size, PAGE_KERNEL_RX);
18430 +}
18431 +EXPORT_SYMBOL(module_alloc_exec);
18432 +#endif
18433 +#endif
18434 +
18435 #ifdef CONFIG_X86_32
18436 int apply_relocate(Elf32_Shdr *sechdrs,
18437 const char *strtab,
18438 @@ -55,14 +101,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18439 unsigned int i;
18440 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18441 Elf32_Sym *sym;
18442 - uint32_t *location;
18443 + uint32_t *plocation, location;
18444
18445 DEBUGP("Applying relocate section %u to %u\n", relsec,
18446 sechdrs[relsec].sh_info);
18447 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18448 /* This is where to make the change */
18449 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18450 - + rel[i].r_offset;
18451 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18452 + location = (uint32_t)plocation;
18453 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18454 + plocation = ktla_ktva((void *)plocation);
18455 /* This is the symbol it is referring to. Note that all
18456 undefined symbols have been resolved. */
18457 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18458 @@ -71,11 +119,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18459 switch (ELF32_R_TYPE(rel[i].r_info)) {
18460 case R_386_32:
18461 /* We add the value into the location given */
18462 - *location += sym->st_value;
18463 + pax_open_kernel();
18464 + *plocation += sym->st_value;
18465 + pax_close_kernel();
18466 break;
18467 case R_386_PC32:
18468 /* Add the value, subtract its postition */
18469 - *location += sym->st_value - (uint32_t)location;
18470 + pax_open_kernel();
18471 + *plocation += sym->st_value - location;
18472 + pax_close_kernel();
18473 break;
18474 default:
18475 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18476 @@ -120,21 +172,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18477 case R_X86_64_NONE:
18478 break;
18479 case R_X86_64_64:
18480 + pax_open_kernel();
18481 *(u64 *)loc = val;
18482 + pax_close_kernel();
18483 break;
18484 case R_X86_64_32:
18485 + pax_open_kernel();
18486 *(u32 *)loc = val;
18487 + pax_close_kernel();
18488 if (val != *(u32 *)loc)
18489 goto overflow;
18490 break;
18491 case R_X86_64_32S:
18492 + pax_open_kernel();
18493 *(s32 *)loc = val;
18494 + pax_close_kernel();
18495 if ((s64)val != *(s32 *)loc)
18496 goto overflow;
18497 break;
18498 case R_X86_64_PC32:
18499 val -= (u64)loc;
18500 + pax_open_kernel();
18501 *(u32 *)loc = val;
18502 + pax_close_kernel();
18503 +
18504 #if 0
18505 if ((s64)val != *(s32 *)loc)
18506 goto overflow;
18507 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18508 index 47acaf3..ec48ab6 100644
18509 --- a/arch/x86/kernel/nmi.c
18510 +++ b/arch/x86/kernel/nmi.c
18511 @@ -505,6 +505,17 @@ static inline void nmi_nesting_postprocess(void)
18512 dotraplinkage notrace __kprobes void
18513 do_nmi(struct pt_regs *regs, long error_code)
18514 {
18515 +
18516 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18517 + if (!user_mode(regs)) {
18518 + unsigned long cs = regs->cs & 0xFFFF;
18519 + unsigned long ip = ktva_ktla(regs->ip);
18520 +
18521 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18522 + regs->ip = ip;
18523 + }
18524 +#endif
18525 +
18526 nmi_nesting_preprocess(regs);
18527
18528 nmi_enter();
18529 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18530 index 676b8c7..870ba04 100644
18531 --- a/arch/x86/kernel/paravirt-spinlocks.c
18532 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18533 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18534 arch_spin_lock(lock);
18535 }
18536
18537 -struct pv_lock_ops pv_lock_ops = {
18538 +struct pv_lock_ops pv_lock_ops __read_only = {
18539 #ifdef CONFIG_SMP
18540 .spin_is_locked = __ticket_spin_is_locked,
18541 .spin_is_contended = __ticket_spin_is_contended,
18542 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18543 index d90272e..6bb013b 100644
18544 --- a/arch/x86/kernel/paravirt.c
18545 +++ b/arch/x86/kernel/paravirt.c
18546 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
18547 {
18548 return x;
18549 }
18550 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18551 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18552 +#endif
18553
18554 void __init default_banner(void)
18555 {
18556 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18557 if (opfunc == NULL)
18558 /* If there's no function, patch it with a ud2a (BUG) */
18559 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18560 - else if (opfunc == _paravirt_nop)
18561 + else if (opfunc == (void *)_paravirt_nop)
18562 /* If the operation is a nop, then nop the callsite */
18563 ret = paravirt_patch_nop();
18564
18565 /* identity functions just return their single argument */
18566 - else if (opfunc == _paravirt_ident_32)
18567 + else if (opfunc == (void *)_paravirt_ident_32)
18568 ret = paravirt_patch_ident_32(insnbuf, len);
18569 - else if (opfunc == _paravirt_ident_64)
18570 + else if (opfunc == (void *)_paravirt_ident_64)
18571 ret = paravirt_patch_ident_64(insnbuf, len);
18572 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18573 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18574 + ret = paravirt_patch_ident_64(insnbuf, len);
18575 +#endif
18576
18577 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18578 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18579 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18580 if (insn_len > len || start == NULL)
18581 insn_len = len;
18582 else
18583 - memcpy(insnbuf, start, insn_len);
18584 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18585
18586 return insn_len;
18587 }
18588 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
18589 preempt_enable();
18590 }
18591
18592 -struct pv_info pv_info = {
18593 +struct pv_info pv_info __read_only = {
18594 .name = "bare hardware",
18595 .paravirt_enabled = 0,
18596 .kernel_rpl = 0,
18597 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
18598 #endif
18599 };
18600
18601 -struct pv_init_ops pv_init_ops = {
18602 +struct pv_init_ops pv_init_ops __read_only = {
18603 .patch = native_patch,
18604 };
18605
18606 -struct pv_time_ops pv_time_ops = {
18607 +struct pv_time_ops pv_time_ops __read_only = {
18608 .sched_clock = native_sched_clock,
18609 .steal_clock = native_steal_clock,
18610 };
18611
18612 -struct pv_irq_ops pv_irq_ops = {
18613 +struct pv_irq_ops pv_irq_ops __read_only = {
18614 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18615 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18616 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18617 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
18618 #endif
18619 };
18620
18621 -struct pv_cpu_ops pv_cpu_ops = {
18622 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18623 .cpuid = native_cpuid,
18624 .get_debugreg = native_get_debugreg,
18625 .set_debugreg = native_set_debugreg,
18626 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18627 .end_context_switch = paravirt_nop,
18628 };
18629
18630 -struct pv_apic_ops pv_apic_ops = {
18631 +struct pv_apic_ops pv_apic_ops __read_only = {
18632 #ifdef CONFIG_X86_LOCAL_APIC
18633 .startup_ipi_hook = paravirt_nop,
18634 #endif
18635 };
18636
18637 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18638 +#ifdef CONFIG_X86_32
18639 +#ifdef CONFIG_X86_PAE
18640 +/* 64-bit pagetable entries */
18641 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18642 +#else
18643 /* 32-bit pagetable entries */
18644 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18645 +#endif
18646 #else
18647 /* 64-bit pagetable entries */
18648 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18649 #endif
18650
18651 -struct pv_mmu_ops pv_mmu_ops = {
18652 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18653
18654 .read_cr2 = native_read_cr2,
18655 .write_cr2 = native_write_cr2,
18656 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18657 .make_pud = PTE_IDENT,
18658
18659 .set_pgd = native_set_pgd,
18660 + .set_pgd_batched = native_set_pgd_batched,
18661 #endif
18662 #endif /* PAGETABLE_LEVELS >= 3 */
18663
18664 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18665 },
18666
18667 .set_fixmap = native_set_fixmap,
18668 +
18669 +#ifdef CONFIG_PAX_KERNEXEC
18670 + .pax_open_kernel = native_pax_open_kernel,
18671 + .pax_close_kernel = native_pax_close_kernel,
18672 +#endif
18673 +
18674 };
18675
18676 EXPORT_SYMBOL_GPL(pv_time_ops);
18677 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18678 index 35ccf75..7a15747 100644
18679 --- a/arch/x86/kernel/pci-iommu_table.c
18680 +++ b/arch/x86/kernel/pci-iommu_table.c
18681 @@ -2,7 +2,7 @@
18682 #include <asm/iommu_table.h>
18683 #include <linux/string.h>
18684 #include <linux/kallsyms.h>
18685 -
18686 +#include <linux/sched.h>
18687
18688 #define DEBUG 1
18689
18690 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18691 index 15763af..da59ada 100644
18692 --- a/arch/x86/kernel/process.c
18693 +++ b/arch/x86/kernel/process.c
18694 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
18695
18696 void free_thread_info(struct thread_info *ti)
18697 {
18698 - free_thread_xstate(ti->task);
18699 free_pages((unsigned long)ti, THREAD_ORDER);
18700 }
18701
18702 +static struct kmem_cache *task_struct_cachep;
18703 +
18704 void arch_task_cache_init(void)
18705 {
18706 - task_xstate_cachep =
18707 - kmem_cache_create("task_xstate", xstate_size,
18708 + /* create a slab on which task_structs can be allocated */
18709 + task_struct_cachep =
18710 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18711 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18712 +
18713 + task_xstate_cachep =
18714 + kmem_cache_create("task_xstate", xstate_size,
18715 __alignof__(union thread_xstate),
18716 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18717 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18718 +}
18719 +
18720 +struct task_struct *alloc_task_struct_node(int node)
18721 +{
18722 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18723 +}
18724 +
18725 +void free_task_struct(struct task_struct *task)
18726 +{
18727 + free_thread_xstate(task);
18728 + kmem_cache_free(task_struct_cachep, task);
18729 }
18730
18731 /*
18732 @@ -70,7 +87,7 @@ void exit_thread(void)
18733 unsigned long *bp = t->io_bitmap_ptr;
18734
18735 if (bp) {
18736 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18737 + struct tss_struct *tss = init_tss + get_cpu();
18738
18739 t->io_bitmap_ptr = NULL;
18740 clear_thread_flag(TIF_IO_BITMAP);
18741 @@ -106,7 +123,7 @@ void show_regs_common(void)
18742
18743 printk(KERN_CONT "\n");
18744 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18745 - current->pid, current->comm, print_tainted(),
18746 + task_pid_nr(current), current->comm, print_tainted(),
18747 init_utsname()->release,
18748 (int)strcspn(init_utsname()->version, " "),
18749 init_utsname()->version);
18750 @@ -120,6 +137,9 @@ void flush_thread(void)
18751 {
18752 struct task_struct *tsk = current;
18753
18754 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18755 + loadsegment(gs, 0);
18756 +#endif
18757 flush_ptrace_hw_breakpoint(tsk);
18758 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18759 /*
18760 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18761 regs.di = (unsigned long) arg;
18762
18763 #ifdef CONFIG_X86_32
18764 - regs.ds = __USER_DS;
18765 - regs.es = __USER_DS;
18766 + regs.ds = __KERNEL_DS;
18767 + regs.es = __KERNEL_DS;
18768 regs.fs = __KERNEL_PERCPU;
18769 - regs.gs = __KERNEL_STACK_CANARY;
18770 + savesegment(gs, regs.gs);
18771 #else
18772 regs.ss = __KERNEL_DS;
18773 #endif
18774 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
18775
18776 return ret;
18777 }
18778 -void stop_this_cpu(void *dummy)
18779 +__noreturn void stop_this_cpu(void *dummy)
18780 {
18781 local_irq_disable();
18782 /*
18783 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
18784 }
18785 early_param("idle", idle_setup);
18786
18787 -unsigned long arch_align_stack(unsigned long sp)
18788 +#ifdef CONFIG_PAX_RANDKSTACK
18789 +void pax_randomize_kstack(struct pt_regs *regs)
18790 {
18791 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18792 - sp -= get_random_int() % 8192;
18793 - return sp & ~0xf;
18794 -}
18795 + struct thread_struct *thread = &current->thread;
18796 + unsigned long time;
18797
18798 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18799 -{
18800 - unsigned long range_end = mm->brk + 0x02000000;
18801 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18802 -}
18803 + if (!randomize_va_space)
18804 + return;
18805 +
18806 + if (v8086_mode(regs))
18807 + return;
18808
18809 + rdtscl(time);
18810 +
18811 + /* P4 seems to return a 0 LSB, ignore it */
18812 +#ifdef CONFIG_MPENTIUM4
18813 + time &= 0x3EUL;
18814 + time <<= 2;
18815 +#elif defined(CONFIG_X86_64)
18816 + time &= 0xFUL;
18817 + time <<= 4;
18818 +#else
18819 + time &= 0x1FUL;
18820 + time <<= 3;
18821 +#endif
18822 +
18823 + thread->sp0 ^= time;
18824 + load_sp0(init_tss + smp_processor_id(), thread);
18825 +
18826 +#ifdef CONFIG_X86_64
18827 + percpu_write(kernel_stack, thread->sp0);
18828 +#endif
18829 +}
18830 +#endif
18831 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18832 index c08d1ff..6ae1c81 100644
18833 --- a/arch/x86/kernel/process_32.c
18834 +++ b/arch/x86/kernel/process_32.c
18835 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18836 unsigned long thread_saved_pc(struct task_struct *tsk)
18837 {
18838 return ((unsigned long *)tsk->thread.sp)[3];
18839 +//XXX return tsk->thread.eip;
18840 }
18841
18842 #ifndef CONFIG_SMP
18843 @@ -132,15 +133,14 @@ void __show_regs(struct pt_regs *regs, int all)
18844 unsigned long sp;
18845 unsigned short ss, gs;
18846
18847 - if (user_mode_vm(regs)) {
18848 + if (user_mode(regs)) {
18849 sp = regs->sp;
18850 ss = regs->ss & 0xffff;
18851 - gs = get_user_gs(regs);
18852 } else {
18853 sp = kernel_stack_pointer(regs);
18854 savesegment(ss, ss);
18855 - savesegment(gs, gs);
18856 }
18857 + gs = get_user_gs(regs);
18858
18859 show_regs_common();
18860
18861 @@ -202,13 +202,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18862 struct task_struct *tsk;
18863 int err;
18864
18865 - childregs = task_pt_regs(p);
18866 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18867 *childregs = *regs;
18868 childregs->ax = 0;
18869 childregs->sp = sp;
18870
18871 p->thread.sp = (unsigned long) childregs;
18872 p->thread.sp0 = (unsigned long) (childregs+1);
18873 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18874
18875 p->thread.ip = (unsigned long) ret_from_fork;
18876
18877 @@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18878 struct thread_struct *prev = &prev_p->thread,
18879 *next = &next_p->thread;
18880 int cpu = smp_processor_id();
18881 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18882 + struct tss_struct *tss = init_tss + cpu;
18883 fpu_switch_t fpu;
18884
18885 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18886 @@ -323,6 +324,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18887 */
18888 lazy_save_gs(prev->gs);
18889
18890 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18891 + __set_fs(task_thread_info(next_p)->addr_limit);
18892 +#endif
18893 +
18894 /*
18895 * Load the per-thread Thread-Local Storage descriptor.
18896 */
18897 @@ -353,6 +358,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18898 */
18899 arch_end_context_switch(next_p);
18900
18901 + percpu_write(current_task, next_p);
18902 + percpu_write(current_tinfo, &next_p->tinfo);
18903 +
18904 /*
18905 * Restore %gs if needed (which is common)
18906 */
18907 @@ -361,8 +369,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18908
18909 switch_fpu_finish(next_p, fpu);
18910
18911 - percpu_write(current_task, next_p);
18912 -
18913 return prev_p;
18914 }
18915
18916 @@ -392,4 +398,3 @@ unsigned long get_wchan(struct task_struct *p)
18917 } while (count++ < 16);
18918 return 0;
18919 }
18920 -
18921 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18922 index cfa5c90..4facd28 100644
18923 --- a/arch/x86/kernel/process_64.c
18924 +++ b/arch/x86/kernel/process_64.c
18925 @@ -89,7 +89,7 @@ static void __exit_idle(void)
18926 void exit_idle(void)
18927 {
18928 /* idle loop has pid 0 */
18929 - if (current->pid)
18930 + if (task_pid_nr(current))
18931 return;
18932 __exit_idle();
18933 }
18934 @@ -270,8 +270,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18935 struct pt_regs *childregs;
18936 struct task_struct *me = current;
18937
18938 - childregs = ((struct pt_regs *)
18939 - (THREAD_SIZE + task_stack_page(p))) - 1;
18940 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18941 *childregs = *regs;
18942
18943 childregs->ax = 0;
18944 @@ -283,6 +282,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18945 p->thread.sp = (unsigned long) childregs;
18946 p->thread.sp0 = (unsigned long) (childregs+1);
18947 p->thread.usersp = me->thread.usersp;
18948 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18949
18950 set_tsk_thread_flag(p, TIF_FORK);
18951
18952 @@ -385,7 +385,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18953 struct thread_struct *prev = &prev_p->thread;
18954 struct thread_struct *next = &next_p->thread;
18955 int cpu = smp_processor_id();
18956 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18957 + struct tss_struct *tss = init_tss + cpu;
18958 unsigned fsindex, gsindex;
18959 fpu_switch_t fpu;
18960
18961 @@ -467,10 +467,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18962 prev->usersp = percpu_read(old_rsp);
18963 percpu_write(old_rsp, next->usersp);
18964 percpu_write(current_task, next_p);
18965 + percpu_write(current_tinfo, &next_p->tinfo);
18966
18967 - percpu_write(kernel_stack,
18968 - (unsigned long)task_stack_page(next_p) +
18969 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18970 + percpu_write(kernel_stack, next->sp0);
18971
18972 /*
18973 * Now maybe reload the debug registers and handle I/O bitmaps
18974 @@ -525,12 +524,11 @@ unsigned long get_wchan(struct task_struct *p)
18975 if (!p || p == current || p->state == TASK_RUNNING)
18976 return 0;
18977 stack = (unsigned long)task_stack_page(p);
18978 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18979 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18980 return 0;
18981 fp = *(u64 *)(p->thread.sp);
18982 do {
18983 - if (fp < (unsigned long)stack ||
18984 - fp >= (unsigned long)stack+THREAD_SIZE)
18985 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18986 return 0;
18987 ip = *(u64 *)(fp+8);
18988 if (!in_sched_functions(ip))
18989 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18990 index 5026738..574f70a 100644
18991 --- a/arch/x86/kernel/ptrace.c
18992 +++ b/arch/x86/kernel/ptrace.c
18993 @@ -792,6 +792,10 @@ static int ioperm_active(struct task_struct *target,
18994 static int ioperm_get(struct task_struct *target,
18995 const struct user_regset *regset,
18996 unsigned int pos, unsigned int count,
18997 + void *kbuf, void __user *ubuf) __size_overflow(3,4);
18998 +static int ioperm_get(struct task_struct *target,
18999 + const struct user_regset *regset,
19000 + unsigned int pos, unsigned int count,
19001 void *kbuf, void __user *ubuf)
19002 {
19003 if (!target->thread.io_bitmap_ptr)
19004 @@ -823,7 +827,7 @@ long arch_ptrace(struct task_struct *child, long request,
19005 unsigned long addr, unsigned long data)
19006 {
19007 int ret;
19008 - unsigned long __user *datap = (unsigned long __user *)data;
19009 + unsigned long __user *datap = (__force unsigned long __user *)data;
19010
19011 switch (request) {
19012 /* read the word at location addr in the USER area. */
19013 @@ -908,14 +912,14 @@ long arch_ptrace(struct task_struct *child, long request,
19014 if ((int) addr < 0)
19015 return -EIO;
19016 ret = do_get_thread_area(child, addr,
19017 - (struct user_desc __user *)data);
19018 + (__force struct user_desc __user *) data);
19019 break;
19020
19021 case PTRACE_SET_THREAD_AREA:
19022 if ((int) addr < 0)
19023 return -EIO;
19024 ret = do_set_thread_area(child, addr,
19025 - (struct user_desc __user *)data, 0);
19026 + (__force struct user_desc __user *) data, 0);
19027 break;
19028 #endif
19029
19030 @@ -1332,7 +1336,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
19031 memset(info, 0, sizeof(*info));
19032 info->si_signo = SIGTRAP;
19033 info->si_code = si_code;
19034 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
19035 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
19036 }
19037
19038 void user_single_step_siginfo(struct task_struct *tsk,
19039 @@ -1361,6 +1365,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
19040 # define IS_IA32 0
19041 #endif
19042
19043 +#ifdef CONFIG_GRKERNSEC_SETXID
19044 +extern void gr_delayed_cred_worker(void);
19045 +#endif
19046 +
19047 /*
19048 * We must return the syscall number to actually look up in the table.
19049 * This can be -1L to skip running any syscall at all.
19050 @@ -1369,6 +1377,11 @@ long syscall_trace_enter(struct pt_regs *regs)
19051 {
19052 long ret = 0;
19053
19054 +#ifdef CONFIG_GRKERNSEC_SETXID
19055 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
19056 + gr_delayed_cred_worker();
19057 +#endif
19058 +
19059 /*
19060 * If we stepped into a sysenter/syscall insn, it trapped in
19061 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
19062 @@ -1412,6 +1425,11 @@ void syscall_trace_leave(struct pt_regs *regs)
19063 {
19064 bool step;
19065
19066 +#ifdef CONFIG_GRKERNSEC_SETXID
19067 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
19068 + gr_delayed_cred_worker();
19069 +#endif
19070 +
19071 audit_syscall_exit(regs);
19072
19073 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
19074 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
19075 index 42eb330..139955c 100644
19076 --- a/arch/x86/kernel/pvclock.c
19077 +++ b/arch/x86/kernel/pvclock.c
19078 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
19079 return pv_tsc_khz;
19080 }
19081
19082 -static atomic64_t last_value = ATOMIC64_INIT(0);
19083 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
19084
19085 void pvclock_resume(void)
19086 {
19087 - atomic64_set(&last_value, 0);
19088 + atomic64_set_unchecked(&last_value, 0);
19089 }
19090
19091 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
19092 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
19093 * updating at the same time, and one of them could be slightly behind,
19094 * making the assumption that last_value always go forward fail to hold.
19095 */
19096 - last = atomic64_read(&last_value);
19097 + last = atomic64_read_unchecked(&last_value);
19098 do {
19099 if (ret < last)
19100 return last;
19101 - last = atomic64_cmpxchg(&last_value, last, ret);
19102 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
19103 } while (unlikely(last != ret));
19104
19105 return ret;
19106 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
19107 index d840e69..98e9581 100644
19108 --- a/arch/x86/kernel/reboot.c
19109 +++ b/arch/x86/kernel/reboot.c
19110 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
19111 EXPORT_SYMBOL(pm_power_off);
19112
19113 static const struct desc_ptr no_idt = {};
19114 -static int reboot_mode;
19115 +static unsigned short reboot_mode;
19116 enum reboot_type reboot_type = BOOT_ACPI;
19117 int reboot_force;
19118
19119 @@ -335,13 +335,17 @@ core_initcall(reboot_init);
19120 extern const unsigned char machine_real_restart_asm[];
19121 extern const u64 machine_real_restart_gdt[3];
19122
19123 -void machine_real_restart(unsigned int type)
19124 +__noreturn void machine_real_restart(unsigned int type)
19125 {
19126 void *restart_va;
19127 unsigned long restart_pa;
19128 - void (*restart_lowmem)(unsigned int);
19129 + void (* __noreturn restart_lowmem)(unsigned int);
19130 u64 *lowmem_gdt;
19131
19132 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19133 + struct desc_struct *gdt;
19134 +#endif
19135 +
19136 local_irq_disable();
19137
19138 /* Write zero to CMOS register number 0x0f, which the BIOS POST
19139 @@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
19140 boot)". This seems like a fairly standard thing that gets set by
19141 REBOOT.COM programs, and the previous reset routine did this
19142 too. */
19143 - *((unsigned short *)0x472) = reboot_mode;
19144 + *(unsigned short *)(__va(0x472)) = reboot_mode;
19145
19146 /* Patch the GDT in the low memory trampoline */
19147 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
19148
19149 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
19150 restart_pa = virt_to_phys(restart_va);
19151 - restart_lowmem = (void (*)(unsigned int))restart_pa;
19152 + restart_lowmem = (void *)restart_pa;
19153
19154 /* GDT[0]: GDT self-pointer */
19155 lowmem_gdt[0] =
19156 @@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
19157 GDT_ENTRY(0x009b, restart_pa, 0xffff);
19158
19159 /* Jump to the identity-mapped low memory code */
19160 +
19161 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19162 + gdt = get_cpu_gdt_table(smp_processor_id());
19163 + pax_open_kernel();
19164 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19165 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
19166 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
19167 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
19168 +#endif
19169 +#ifdef CONFIG_PAX_KERNEXEC
19170 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
19171 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
19172 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
19173 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
19174 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
19175 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
19176 +#endif
19177 + pax_close_kernel();
19178 +#endif
19179 +
19180 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19181 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
19182 + unreachable();
19183 +#else
19184 restart_lowmem(type);
19185 +#endif
19186 +
19187 }
19188 #ifdef CONFIG_APM_MODULE
19189 EXPORT_SYMBOL(machine_real_restart);
19190 @@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
19191 * try to force a triple fault and then cycle between hitting the keyboard
19192 * controller and doing that
19193 */
19194 -static void native_machine_emergency_restart(void)
19195 +__noreturn static void native_machine_emergency_restart(void)
19196 {
19197 int i;
19198 int attempt = 0;
19199 @@ -680,13 +710,13 @@ void native_machine_shutdown(void)
19200 #endif
19201 }
19202
19203 -static void __machine_emergency_restart(int emergency)
19204 +static __noreturn void __machine_emergency_restart(int emergency)
19205 {
19206 reboot_emergency = emergency;
19207 machine_ops.emergency_restart();
19208 }
19209
19210 -static void native_machine_restart(char *__unused)
19211 +static __noreturn void native_machine_restart(char *__unused)
19212 {
19213 printk("machine restart\n");
19214
19215 @@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
19216 __machine_emergency_restart(0);
19217 }
19218
19219 -static void native_machine_halt(void)
19220 +static __noreturn void native_machine_halt(void)
19221 {
19222 /* stop other cpus and apics */
19223 machine_shutdown();
19224 @@ -706,7 +736,7 @@ static void native_machine_halt(void)
19225 stop_this_cpu(NULL);
19226 }
19227
19228 -static void native_machine_power_off(void)
19229 +__noreturn static void native_machine_power_off(void)
19230 {
19231 if (pm_power_off) {
19232 if (!reboot_force)
19233 @@ -715,6 +745,7 @@ static void native_machine_power_off(void)
19234 }
19235 /* a fallback in case there is no PM info available */
19236 tboot_shutdown(TB_SHUTDOWN_HALT);
19237 + unreachable();
19238 }
19239
19240 struct machine_ops machine_ops = {
19241 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19242 index 7a6f3b3..bed145d7 100644
19243 --- a/arch/x86/kernel/relocate_kernel_64.S
19244 +++ b/arch/x86/kernel/relocate_kernel_64.S
19245 @@ -11,6 +11,7 @@
19246 #include <asm/kexec.h>
19247 #include <asm/processor-flags.h>
19248 #include <asm/pgtable_types.h>
19249 +#include <asm/alternative-asm.h>
19250
19251 /*
19252 * Must be relocatable PIC code callable as a C function
19253 @@ -160,13 +161,14 @@ identity_mapped:
19254 xorq %rbp, %rbp
19255 xorq %r8, %r8
19256 xorq %r9, %r9
19257 - xorq %r10, %r9
19258 + xorq %r10, %r10
19259 xorq %r11, %r11
19260 xorq %r12, %r12
19261 xorq %r13, %r13
19262 xorq %r14, %r14
19263 xorq %r15, %r15
19264
19265 + pax_force_retaddr 0, 1
19266 ret
19267
19268 1:
19269 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19270 index d7d5099..28555d0 100644
19271 --- a/arch/x86/kernel/setup.c
19272 +++ b/arch/x86/kernel/setup.c
19273 @@ -448,7 +448,7 @@ static void __init parse_setup_data(void)
19274
19275 switch (data->type) {
19276 case SETUP_E820_EXT:
19277 - parse_e820_ext(data);
19278 + parse_e820_ext((struct setup_data __force_kernel *)data);
19279 break;
19280 case SETUP_DTB:
19281 add_dtb(pa_data);
19282 @@ -649,7 +649,7 @@ static void __init trim_bios_range(void)
19283 * area (640->1Mb) as ram even though it is not.
19284 * take them out.
19285 */
19286 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19287 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19288 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19289 }
19290
19291 @@ -767,14 +767,14 @@ void __init setup_arch(char **cmdline_p)
19292
19293 if (!boot_params.hdr.root_flags)
19294 root_mountflags &= ~MS_RDONLY;
19295 - init_mm.start_code = (unsigned long) _text;
19296 - init_mm.end_code = (unsigned long) _etext;
19297 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19298 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19299 init_mm.end_data = (unsigned long) _edata;
19300 init_mm.brk = _brk_end;
19301
19302 - code_resource.start = virt_to_phys(_text);
19303 - code_resource.end = virt_to_phys(_etext)-1;
19304 - data_resource.start = virt_to_phys(_etext);
19305 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19306 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19307 + data_resource.start = virt_to_phys(_sdata);
19308 data_resource.end = virt_to_phys(_edata)-1;
19309 bss_resource.start = virt_to_phys(&__bss_start);
19310 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19311 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19312 index 5a98aa2..848d2be 100644
19313 --- a/arch/x86/kernel/setup_percpu.c
19314 +++ b/arch/x86/kernel/setup_percpu.c
19315 @@ -21,19 +21,17 @@
19316 #include <asm/cpu.h>
19317 #include <asm/stackprotector.h>
19318
19319 -DEFINE_PER_CPU(int, cpu_number);
19320 +#ifdef CONFIG_SMP
19321 +DEFINE_PER_CPU(unsigned int, cpu_number);
19322 EXPORT_PER_CPU_SYMBOL(cpu_number);
19323 +#endif
19324
19325 -#ifdef CONFIG_X86_64
19326 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19327 -#else
19328 -#define BOOT_PERCPU_OFFSET 0
19329 -#endif
19330
19331 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19332 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19333
19334 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19335 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19336 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19337 };
19338 EXPORT_SYMBOL(__per_cpu_offset);
19339 @@ -96,6 +94,8 @@ static bool __init pcpu_need_numa(void)
19340 * Pointer to the allocated area on success, NULL on failure.
19341 */
19342 static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
19343 + unsigned long align) __size_overflow(2);
19344 +static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
19345 unsigned long align)
19346 {
19347 const unsigned long goal = __pa(MAX_DMA_ADDRESS);
19348 @@ -124,6 +124,8 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, unsigned long size,
19349 /*
19350 * Helpers for first chunk memory allocation
19351 */
19352 +static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align) __size_overflow(2);
19353 +
19354 static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
19355 {
19356 return pcpu_alloc_bootmem(cpu, size, align);
19357 @@ -155,10 +157,10 @@ static inline void setup_percpu_segment(int cpu)
19358 {
19359 #ifdef CONFIG_X86_32
19360 struct desc_struct gdt;
19361 + unsigned long base = per_cpu_offset(cpu);
19362
19363 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19364 - 0x2 | DESCTYPE_S, 0x8);
19365 - gdt.s = 1;
19366 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19367 + 0x83 | DESCTYPE_S, 0xC);
19368 write_gdt_entry(get_cpu_gdt_table(cpu),
19369 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19370 #endif
19371 @@ -219,6 +221,11 @@ void __init setup_per_cpu_areas(void)
19372 /* alrighty, percpu areas up and running */
19373 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19374 for_each_possible_cpu(cpu) {
19375 +#ifdef CONFIG_CC_STACKPROTECTOR
19376 +#ifdef CONFIG_X86_32
19377 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19378 +#endif
19379 +#endif
19380 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19381 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19382 per_cpu(cpu_number, cpu) = cpu;
19383 @@ -259,6 +266,12 @@ void __init setup_per_cpu_areas(void)
19384 */
19385 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19386 #endif
19387 +#ifdef CONFIG_CC_STACKPROTECTOR
19388 +#ifdef CONFIG_X86_32
19389 + if (!cpu)
19390 + per_cpu(stack_canary.canary, cpu) = canary;
19391 +#endif
19392 +#endif
19393 /*
19394 * Up to this point, the boot CPU has been using .init.data
19395 * area. Reload any changed state for the boot CPU.
19396 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19397 index 46a01bd..2e88e6d 100644
19398 --- a/arch/x86/kernel/signal.c
19399 +++ b/arch/x86/kernel/signal.c
19400 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
19401 * Align the stack pointer according to the i386 ABI,
19402 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19403 */
19404 - sp = ((sp + 4) & -16ul) - 4;
19405 + sp = ((sp - 12) & -16ul) - 4;
19406 #else /* !CONFIG_X86_32 */
19407 sp = round_down(sp, 16) - 8;
19408 #endif
19409 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19410 * Return an always-bogus address instead so we will die with SIGSEGV.
19411 */
19412 if (onsigstack && !likely(on_sig_stack(sp)))
19413 - return (void __user *)-1L;
19414 + return (__force void __user *)-1L;
19415
19416 /* save i387 state */
19417 if (used_math() && save_i387_xstate(*fpstate) < 0)
19418 - return (void __user *)-1L;
19419 + return (__force void __user *)-1L;
19420
19421 return (void __user *)sp;
19422 }
19423 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19424 }
19425
19426 if (current->mm->context.vdso)
19427 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19428 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19429 else
19430 - restorer = &frame->retcode;
19431 + restorer = (void __user *)&frame->retcode;
19432 if (ka->sa.sa_flags & SA_RESTORER)
19433 restorer = ka->sa.sa_restorer;
19434
19435 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19436 * reasons and because gdb uses it as a signature to notice
19437 * signal handler stack frames.
19438 */
19439 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19440 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19441
19442 if (err)
19443 return -EFAULT;
19444 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19445 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19446
19447 /* Set up to return from userspace. */
19448 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19449 + if (current->mm->context.vdso)
19450 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19451 + else
19452 + restorer = (void __user *)&frame->retcode;
19453 if (ka->sa.sa_flags & SA_RESTORER)
19454 restorer = ka->sa.sa_restorer;
19455 put_user_ex(restorer, &frame->pretcode);
19456 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19457 * reasons and because gdb uses it as a signature to notice
19458 * signal handler stack frames.
19459 */
19460 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19461 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19462 } put_user_catch(err);
19463
19464 if (err)
19465 @@ -765,7 +768,7 @@ static void do_signal(struct pt_regs *regs)
19466 * X86_32: vm86 regs switched out by assembly code before reaching
19467 * here, so testing against kernel CS suffices.
19468 */
19469 - if (!user_mode(regs))
19470 + if (!user_mode_novm(regs))
19471 return;
19472
19473 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
19474 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19475 index 66d250c..f1b10bd 100644
19476 --- a/arch/x86/kernel/smpboot.c
19477 +++ b/arch/x86/kernel/smpboot.c
19478 @@ -715,17 +715,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19479 set_idle_for_cpu(cpu, c_idle.idle);
19480 do_rest:
19481 per_cpu(current_task, cpu) = c_idle.idle;
19482 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19483 #ifdef CONFIG_X86_32
19484 /* Stack for startup_32 can be just as for start_secondary onwards */
19485 irq_ctx_init(cpu);
19486 #else
19487 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19488 initial_gs = per_cpu_offset(cpu);
19489 - per_cpu(kernel_stack, cpu) =
19490 - (unsigned long)task_stack_page(c_idle.idle) -
19491 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19492 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19493 #endif
19494 +
19495 + pax_open_kernel();
19496 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19497 + pax_close_kernel();
19498 +
19499 initial_code = (unsigned long)start_secondary;
19500 stack_start = c_idle.idle->thread.sp;
19501
19502 @@ -868,6 +871,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19503
19504 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19505
19506 +#ifdef CONFIG_PAX_PER_CPU_PGD
19507 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19508 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19509 + KERNEL_PGD_PTRS);
19510 +#endif
19511 +
19512 err = do_boot_cpu(apicid, cpu);
19513 if (err) {
19514 pr_debug("do_boot_cpu failed %d\n", err);
19515 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19516 index c346d11..d43b163 100644
19517 --- a/arch/x86/kernel/step.c
19518 +++ b/arch/x86/kernel/step.c
19519 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19520 struct desc_struct *desc;
19521 unsigned long base;
19522
19523 - seg &= ~7UL;
19524 + seg >>= 3;
19525
19526 mutex_lock(&child->mm->context.lock);
19527 - if (unlikely((seg >> 3) >= child->mm->context.size))
19528 + if (unlikely(seg >= child->mm->context.size))
19529 addr = -1L; /* bogus selector, access would fault */
19530 else {
19531 desc = child->mm->context.ldt + seg;
19532 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19533 addr += base;
19534 }
19535 mutex_unlock(&child->mm->context.lock);
19536 - }
19537 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19538 + addr = ktla_ktva(addr);
19539
19540 return addr;
19541 }
19542 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19543 unsigned char opcode[15];
19544 unsigned long addr = convert_ip_to_linear(child, regs);
19545
19546 + if (addr == -EINVAL)
19547 + return 0;
19548 +
19549 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19550 for (i = 0; i < copied; i++) {
19551 switch (opcode[i]) {
19552 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19553 index 0b0cb5f..db6b9ed 100644
19554 --- a/arch/x86/kernel/sys_i386_32.c
19555 +++ b/arch/x86/kernel/sys_i386_32.c
19556 @@ -24,17 +24,224 @@
19557
19558 #include <asm/syscalls.h>
19559
19560 -/*
19561 - * Do a system call from kernel instead of calling sys_execve so we
19562 - * end up with proper pt_regs.
19563 - */
19564 -int kernel_execve(const char *filename,
19565 - const char *const argv[],
19566 - const char *const envp[])
19567 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19568 {
19569 - long __res;
19570 - asm volatile ("int $0x80"
19571 - : "=a" (__res)
19572 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19573 - return __res;
19574 + unsigned long pax_task_size = TASK_SIZE;
19575 +
19576 +#ifdef CONFIG_PAX_SEGMEXEC
19577 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19578 + pax_task_size = SEGMEXEC_TASK_SIZE;
19579 +#endif
19580 +
19581 + if (len > pax_task_size || addr > pax_task_size - len)
19582 + return -EINVAL;
19583 +
19584 + return 0;
19585 +}
19586 +
19587 +unsigned long
19588 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19589 + unsigned long len, unsigned long pgoff, unsigned long flags)
19590 +{
19591 + struct mm_struct *mm = current->mm;
19592 + struct vm_area_struct *vma;
19593 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19594 +
19595 +#ifdef CONFIG_PAX_SEGMEXEC
19596 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19597 + pax_task_size = SEGMEXEC_TASK_SIZE;
19598 +#endif
19599 +
19600 + pax_task_size -= PAGE_SIZE;
19601 +
19602 + if (len > pax_task_size)
19603 + return -ENOMEM;
19604 +
19605 + if (flags & MAP_FIXED)
19606 + return addr;
19607 +
19608 +#ifdef CONFIG_PAX_RANDMMAP
19609 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19610 +#endif
19611 +
19612 + if (addr) {
19613 + addr = PAGE_ALIGN(addr);
19614 + if (pax_task_size - len >= addr) {
19615 + vma = find_vma(mm, addr);
19616 + if (check_heap_stack_gap(vma, addr, len))
19617 + return addr;
19618 + }
19619 + }
19620 + if (len > mm->cached_hole_size) {
19621 + start_addr = addr = mm->free_area_cache;
19622 + } else {
19623 + start_addr = addr = mm->mmap_base;
19624 + mm->cached_hole_size = 0;
19625 + }
19626 +
19627 +#ifdef CONFIG_PAX_PAGEEXEC
19628 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19629 + start_addr = 0x00110000UL;
19630 +
19631 +#ifdef CONFIG_PAX_RANDMMAP
19632 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19633 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19634 +#endif
19635 +
19636 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19637 + start_addr = addr = mm->mmap_base;
19638 + else
19639 + addr = start_addr;
19640 + }
19641 +#endif
19642 +
19643 +full_search:
19644 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19645 + /* At this point: (!vma || addr < vma->vm_end). */
19646 + if (pax_task_size - len < addr) {
19647 + /*
19648 + * Start a new search - just in case we missed
19649 + * some holes.
19650 + */
19651 + if (start_addr != mm->mmap_base) {
19652 + start_addr = addr = mm->mmap_base;
19653 + mm->cached_hole_size = 0;
19654 + goto full_search;
19655 + }
19656 + return -ENOMEM;
19657 + }
19658 + if (check_heap_stack_gap(vma, addr, len))
19659 + break;
19660 + if (addr + mm->cached_hole_size < vma->vm_start)
19661 + mm->cached_hole_size = vma->vm_start - addr;
19662 + addr = vma->vm_end;
19663 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19664 + start_addr = addr = mm->mmap_base;
19665 + mm->cached_hole_size = 0;
19666 + goto full_search;
19667 + }
19668 + }
19669 +
19670 + /*
19671 + * Remember the place where we stopped the search:
19672 + */
19673 + mm->free_area_cache = addr + len;
19674 + return addr;
19675 +}
19676 +
19677 +unsigned long
19678 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19679 + const unsigned long len, const unsigned long pgoff,
19680 + const unsigned long flags)
19681 +{
19682 + struct vm_area_struct *vma;
19683 + struct mm_struct *mm = current->mm;
19684 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19685 +
19686 +#ifdef CONFIG_PAX_SEGMEXEC
19687 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19688 + pax_task_size = SEGMEXEC_TASK_SIZE;
19689 +#endif
19690 +
19691 + pax_task_size -= PAGE_SIZE;
19692 +
19693 + /* requested length too big for entire address space */
19694 + if (len > pax_task_size)
19695 + return -ENOMEM;
19696 +
19697 + if (flags & MAP_FIXED)
19698 + return addr;
19699 +
19700 +#ifdef CONFIG_PAX_PAGEEXEC
19701 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19702 + goto bottomup;
19703 +#endif
19704 +
19705 +#ifdef CONFIG_PAX_RANDMMAP
19706 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19707 +#endif
19708 +
19709 + /* requesting a specific address */
19710 + if (addr) {
19711 + addr = PAGE_ALIGN(addr);
19712 + if (pax_task_size - len >= addr) {
19713 + vma = find_vma(mm, addr);
19714 + if (check_heap_stack_gap(vma, addr, len))
19715 + return addr;
19716 + }
19717 + }
19718 +
19719 + /* check if free_area_cache is useful for us */
19720 + if (len <= mm->cached_hole_size) {
19721 + mm->cached_hole_size = 0;
19722 + mm->free_area_cache = mm->mmap_base;
19723 + }
19724 +
19725 + /* either no address requested or can't fit in requested address hole */
19726 + addr = mm->free_area_cache;
19727 +
19728 + /* make sure it can fit in the remaining address space */
19729 + if (addr > len) {
19730 + vma = find_vma(mm, addr-len);
19731 + if (check_heap_stack_gap(vma, addr - len, len))
19732 + /* remember the address as a hint for next time */
19733 + return (mm->free_area_cache = addr-len);
19734 + }
19735 +
19736 + if (mm->mmap_base < len)
19737 + goto bottomup;
19738 +
19739 + addr = mm->mmap_base-len;
19740 +
19741 + do {
19742 + /*
19743 + * Lookup failure means no vma is above this address,
19744 + * else if new region fits below vma->vm_start,
19745 + * return with success:
19746 + */
19747 + vma = find_vma(mm, addr);
19748 + if (check_heap_stack_gap(vma, addr, len))
19749 + /* remember the address as a hint for next time */
19750 + return (mm->free_area_cache = addr);
19751 +
19752 + /* remember the largest hole we saw so far */
19753 + if (addr + mm->cached_hole_size < vma->vm_start)
19754 + mm->cached_hole_size = vma->vm_start - addr;
19755 +
19756 + /* try just below the current vma->vm_start */
19757 + addr = skip_heap_stack_gap(vma, len);
19758 + } while (!IS_ERR_VALUE(addr));
19759 +
19760 +bottomup:
19761 + /*
19762 + * A failed mmap() very likely causes application failure,
19763 + * so fall back to the bottom-up function here. This scenario
19764 + * can happen with large stack limits and large mmap()
19765 + * allocations.
19766 + */
19767 +
19768 +#ifdef CONFIG_PAX_SEGMEXEC
19769 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19770 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19771 + else
19772 +#endif
19773 +
19774 + mm->mmap_base = TASK_UNMAPPED_BASE;
19775 +
19776 +#ifdef CONFIG_PAX_RANDMMAP
19777 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19778 + mm->mmap_base += mm->delta_mmap;
19779 +#endif
19780 +
19781 + mm->free_area_cache = mm->mmap_base;
19782 + mm->cached_hole_size = ~0UL;
19783 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19784 + /*
19785 + * Restore the topdown base:
19786 + */
19787 + mm->mmap_base = base;
19788 + mm->free_area_cache = base;
19789 + mm->cached_hole_size = ~0UL;
19790 +
19791 + return addr;
19792 }
19793 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19794 index 0514890..3dbebce 100644
19795 --- a/arch/x86/kernel/sys_x86_64.c
19796 +++ b/arch/x86/kernel/sys_x86_64.c
19797 @@ -95,8 +95,8 @@ out:
19798 return error;
19799 }
19800
19801 -static void find_start_end(unsigned long flags, unsigned long *begin,
19802 - unsigned long *end)
19803 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19804 + unsigned long *begin, unsigned long *end)
19805 {
19806 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19807 unsigned long new_begin;
19808 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19809 *begin = new_begin;
19810 }
19811 } else {
19812 - *begin = TASK_UNMAPPED_BASE;
19813 + *begin = mm->mmap_base;
19814 *end = TASK_SIZE;
19815 }
19816 }
19817 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19818 if (flags & MAP_FIXED)
19819 return addr;
19820
19821 - find_start_end(flags, &begin, &end);
19822 + find_start_end(mm, flags, &begin, &end);
19823
19824 if (len > end)
19825 return -ENOMEM;
19826
19827 +#ifdef CONFIG_PAX_RANDMMAP
19828 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19829 +#endif
19830 +
19831 if (addr) {
19832 addr = PAGE_ALIGN(addr);
19833 vma = find_vma(mm, addr);
19834 - if (end - len >= addr &&
19835 - (!vma || addr + len <= vma->vm_start))
19836 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19837 return addr;
19838 }
19839 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19840 @@ -172,7 +175,7 @@ full_search:
19841 }
19842 return -ENOMEM;
19843 }
19844 - if (!vma || addr + len <= vma->vm_start) {
19845 + if (check_heap_stack_gap(vma, addr, len)) {
19846 /*
19847 * Remember the place where we stopped the search:
19848 */
19849 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19850 {
19851 struct vm_area_struct *vma;
19852 struct mm_struct *mm = current->mm;
19853 - unsigned long addr = addr0;
19854 + unsigned long base = mm->mmap_base, addr = addr0;
19855
19856 /* requested length too big for entire address space */
19857 if (len > TASK_SIZE)
19858 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19859 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19860 goto bottomup;
19861
19862 +#ifdef CONFIG_PAX_RANDMMAP
19863 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19864 +#endif
19865 +
19866 /* requesting a specific address */
19867 if (addr) {
19868 addr = PAGE_ALIGN(addr);
19869 - vma = find_vma(mm, addr);
19870 - if (TASK_SIZE - len >= addr &&
19871 - (!vma || addr + len <= vma->vm_start))
19872 - return addr;
19873 + if (TASK_SIZE - len >= addr) {
19874 + vma = find_vma(mm, addr);
19875 + if (check_heap_stack_gap(vma, addr, len))
19876 + return addr;
19877 + }
19878 }
19879
19880 /* check if free_area_cache is useful for us */
19881 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19882 ALIGN_TOPDOWN);
19883
19884 vma = find_vma(mm, tmp_addr);
19885 - if (!vma || tmp_addr + len <= vma->vm_start)
19886 + if (check_heap_stack_gap(vma, tmp_addr, len))
19887 /* remember the address as a hint for next time */
19888 return mm->free_area_cache = tmp_addr;
19889 }
19890 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19891 * return with success:
19892 */
19893 vma = find_vma(mm, addr);
19894 - if (!vma || addr+len <= vma->vm_start)
19895 + if (check_heap_stack_gap(vma, addr, len))
19896 /* remember the address as a hint for next time */
19897 return mm->free_area_cache = addr;
19898
19899 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19900 mm->cached_hole_size = vma->vm_start - addr;
19901
19902 /* try just below the current vma->vm_start */
19903 - addr = vma->vm_start-len;
19904 - } while (len < vma->vm_start);
19905 + addr = skip_heap_stack_gap(vma, len);
19906 + } while (!IS_ERR_VALUE(addr));
19907
19908 bottomup:
19909 /*
19910 @@ -270,13 +278,21 @@ bottomup:
19911 * can happen with large stack limits and large mmap()
19912 * allocations.
19913 */
19914 + mm->mmap_base = TASK_UNMAPPED_BASE;
19915 +
19916 +#ifdef CONFIG_PAX_RANDMMAP
19917 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19918 + mm->mmap_base += mm->delta_mmap;
19919 +#endif
19920 +
19921 + mm->free_area_cache = mm->mmap_base;
19922 mm->cached_hole_size = ~0UL;
19923 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19924 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19925 /*
19926 * Restore the topdown base:
19927 */
19928 - mm->free_area_cache = mm->mmap_base;
19929 + mm->mmap_base = base;
19930 + mm->free_area_cache = base;
19931 mm->cached_hole_size = ~0UL;
19932
19933 return addr;
19934 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19935 index e2410e2..4fe3fbc 100644
19936 --- a/arch/x86/kernel/tboot.c
19937 +++ b/arch/x86/kernel/tboot.c
19938 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19939
19940 void tboot_shutdown(u32 shutdown_type)
19941 {
19942 - void (*shutdown)(void);
19943 + void (* __noreturn shutdown)(void);
19944
19945 if (!tboot_enabled())
19946 return;
19947 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19948
19949 switch_to_tboot_pt();
19950
19951 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19952 + shutdown = (void *)tboot->shutdown_entry;
19953 shutdown();
19954
19955 /* should not reach here */
19956 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19957 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19958 }
19959
19960 -static atomic_t ap_wfs_count;
19961 +static atomic_unchecked_t ap_wfs_count;
19962
19963 static int tboot_wait_for_aps(int num_aps)
19964 {
19965 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19966 {
19967 switch (action) {
19968 case CPU_DYING:
19969 - atomic_inc(&ap_wfs_count);
19970 + atomic_inc_unchecked(&ap_wfs_count);
19971 if (num_online_cpus() == 1)
19972 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19973 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19974 return NOTIFY_BAD;
19975 break;
19976 }
19977 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
19978
19979 tboot_create_trampoline();
19980
19981 - atomic_set(&ap_wfs_count, 0);
19982 + atomic_set_unchecked(&ap_wfs_count, 0);
19983 register_hotcpu_notifier(&tboot_cpu_notifier);
19984 return 0;
19985 }
19986 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19987 index dd5fbf4..b7f2232 100644
19988 --- a/arch/x86/kernel/time.c
19989 +++ b/arch/x86/kernel/time.c
19990 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19991 {
19992 unsigned long pc = instruction_pointer(regs);
19993
19994 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19995 + if (!user_mode(regs) && in_lock_functions(pc)) {
19996 #ifdef CONFIG_FRAME_POINTER
19997 - return *(unsigned long *)(regs->bp + sizeof(long));
19998 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19999 #else
20000 unsigned long *sp =
20001 (unsigned long *)kernel_stack_pointer(regs);
20002 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
20003 * or above a saved flags. Eflags has bits 22-31 zero,
20004 * kernel addresses don't.
20005 */
20006 +
20007 +#ifdef CONFIG_PAX_KERNEXEC
20008 + return ktla_ktva(sp[0]);
20009 +#else
20010 if (sp[0] >> 22)
20011 return sp[0];
20012 if (sp[1] >> 22)
20013 return sp[1];
20014 #endif
20015 +
20016 +#endif
20017 }
20018 return pc;
20019 }
20020 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
20021 index bcfec2d..8f88b4a 100644
20022 --- a/arch/x86/kernel/tls.c
20023 +++ b/arch/x86/kernel/tls.c
20024 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
20025 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
20026 return -EINVAL;
20027
20028 +#ifdef CONFIG_PAX_SEGMEXEC
20029 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
20030 + return -EINVAL;
20031 +#endif
20032 +
20033 set_tls_desc(p, idx, &info, 1);
20034
20035 return 0;
20036 diff --git a/arch/x86/kernel/tls.h b/arch/x86/kernel/tls.h
20037 index 2f083a2..7d3fecc 100644
20038 --- a/arch/x86/kernel/tls.h
20039 +++ b/arch/x86/kernel/tls.h
20040 @@ -16,6 +16,6 @@
20041
20042 extern user_regset_active_fn regset_tls_active;
20043 extern user_regset_get_fn regset_tls_get;
20044 -extern user_regset_set_fn regset_tls_set;
20045 +extern user_regset_set_fn regset_tls_set __size_overflow(4);
20046
20047 #endif /* _ARCH_X86_KERNEL_TLS_H */
20048 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
20049 index 451c0a7..e57f551 100644
20050 --- a/arch/x86/kernel/trampoline_32.S
20051 +++ b/arch/x86/kernel/trampoline_32.S
20052 @@ -32,6 +32,12 @@
20053 #include <asm/segment.h>
20054 #include <asm/page_types.h>
20055
20056 +#ifdef CONFIG_PAX_KERNEXEC
20057 +#define ta(X) (X)
20058 +#else
20059 +#define ta(X) ((X) - __PAGE_OFFSET)
20060 +#endif
20061 +
20062 #ifdef CONFIG_SMP
20063
20064 .section ".x86_trampoline","a"
20065 @@ -62,7 +68,7 @@ r_base = .
20066 inc %ax # protected mode (PE) bit
20067 lmsw %ax # into protected mode
20068 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
20069 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
20070 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
20071
20072 # These need to be in the same 64K segment as the above;
20073 # hence we don't use the boot_gdt_descr defined in head.S
20074 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
20075 index 09ff517..df19fbff 100644
20076 --- a/arch/x86/kernel/trampoline_64.S
20077 +++ b/arch/x86/kernel/trampoline_64.S
20078 @@ -90,7 +90,7 @@ startup_32:
20079 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
20080 movl %eax, %ds
20081
20082 - movl $X86_CR4_PAE, %eax
20083 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20084 movl %eax, %cr4 # Enable PAE mode
20085
20086 # Setup trampoline 4 level pagetables
20087 @@ -138,7 +138,7 @@ tidt:
20088 # so the kernel can live anywhere
20089 .balign 4
20090 tgdt:
20091 - .short tgdt_end - tgdt # gdt limit
20092 + .short tgdt_end - tgdt - 1 # gdt limit
20093 .long tgdt - r_base
20094 .short 0
20095 .quad 0x00cf9b000000ffff # __KERNEL32_CS
20096 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
20097 index 4bbe04d..41d0943 100644
20098 --- a/arch/x86/kernel/traps.c
20099 +++ b/arch/x86/kernel/traps.c
20100 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
20101
20102 /* Do we ignore FPU interrupts ? */
20103 char ignore_fpu_irq;
20104 -
20105 -/*
20106 - * The IDT has to be page-aligned to simplify the Pentium
20107 - * F0 0F bug workaround.
20108 - */
20109 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
20110 #endif
20111
20112 DECLARE_BITMAP(used_vectors, NR_VECTORS);
20113 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
20114 }
20115
20116 static void __kprobes
20117 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20118 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
20119 long error_code, siginfo_t *info)
20120 {
20121 struct task_struct *tsk = current;
20122
20123 #ifdef CONFIG_X86_32
20124 - if (regs->flags & X86_VM_MASK) {
20125 + if (v8086_mode(regs)) {
20126 /*
20127 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
20128 * On nmi (interrupt 2), do_trap should not be called.
20129 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20130 }
20131 #endif
20132
20133 - if (!user_mode(regs))
20134 + if (!user_mode_novm(regs))
20135 goto kernel_trap;
20136
20137 #ifdef CONFIG_X86_32
20138 @@ -148,7 +142,7 @@ trap_signal:
20139 printk_ratelimit()) {
20140 printk(KERN_INFO
20141 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
20142 - tsk->comm, tsk->pid, str,
20143 + tsk->comm, task_pid_nr(tsk), str,
20144 regs->ip, regs->sp, error_code);
20145 print_vma_addr(" in ", regs->ip);
20146 printk("\n");
20147 @@ -165,8 +159,20 @@ kernel_trap:
20148 if (!fixup_exception(regs)) {
20149 tsk->thread.error_code = error_code;
20150 tsk->thread.trap_no = trapnr;
20151 +
20152 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20153 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
20154 + str = "PAX: suspicious stack segment fault";
20155 +#endif
20156 +
20157 die(str, regs, error_code);
20158 }
20159 +
20160 +#ifdef CONFIG_PAX_REFCOUNT
20161 + if (trapnr == 4)
20162 + pax_report_refcount_overflow(regs);
20163 +#endif
20164 +
20165 return;
20166
20167 #ifdef CONFIG_X86_32
20168 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
20169 conditional_sti(regs);
20170
20171 #ifdef CONFIG_X86_32
20172 - if (regs->flags & X86_VM_MASK)
20173 + if (v8086_mode(regs))
20174 goto gp_in_vm86;
20175 #endif
20176
20177 tsk = current;
20178 - if (!user_mode(regs))
20179 + if (!user_mode_novm(regs))
20180 goto gp_in_kernel;
20181
20182 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20183 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
20184 + struct mm_struct *mm = tsk->mm;
20185 + unsigned long limit;
20186 +
20187 + down_write(&mm->mmap_sem);
20188 + limit = mm->context.user_cs_limit;
20189 + if (limit < TASK_SIZE) {
20190 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
20191 + up_write(&mm->mmap_sem);
20192 + return;
20193 + }
20194 + up_write(&mm->mmap_sem);
20195 + }
20196 +#endif
20197 +
20198 tsk->thread.error_code = error_code;
20199 tsk->thread.trap_no = 13;
20200
20201 @@ -295,6 +317,13 @@ gp_in_kernel:
20202 if (notify_die(DIE_GPF, "general protection fault", regs,
20203 error_code, 13, SIGSEGV) == NOTIFY_STOP)
20204 return;
20205 +
20206 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20207 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
20208 + die("PAX: suspicious general protection fault", regs, error_code);
20209 + else
20210 +#endif
20211 +
20212 die("general protection fault", regs, error_code);
20213 }
20214
20215 @@ -421,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20216 /* It's safe to allow irq's after DR6 has been saved */
20217 preempt_conditional_sti(regs);
20218
20219 - if (regs->flags & X86_VM_MASK) {
20220 + if (v8086_mode(regs)) {
20221 handle_vm86_trap((struct kernel_vm86_regs *) regs,
20222 error_code, 1);
20223 preempt_conditional_cli(regs);
20224 @@ -436,7 +465,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20225 * We already checked v86 mode above, so we can check for kernel mode
20226 * by just checking the CPL of CS.
20227 */
20228 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
20229 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
20230 tsk->thread.debugreg6 &= ~DR_STEP;
20231 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
20232 regs->flags &= ~X86_EFLAGS_TF;
20233 @@ -466,7 +495,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
20234 return;
20235 conditional_sti(regs);
20236
20237 - if (!user_mode_vm(regs))
20238 + if (!user_mode(regs))
20239 {
20240 if (!fixup_exception(regs)) {
20241 task->thread.error_code = error_code;
20242 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
20243 index b9242ba..50c5edd 100644
20244 --- a/arch/x86/kernel/verify_cpu.S
20245 +++ b/arch/x86/kernel/verify_cpu.S
20246 @@ -20,6 +20,7 @@
20247 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
20248 * arch/x86/kernel/trampoline_64.S: secondary processor verification
20249 * arch/x86/kernel/head_32.S: processor startup
20250 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
20251 *
20252 * verify_cpu, returns the status of longmode and SSE in register %eax.
20253 * 0: Success 1: Failure
20254 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
20255 index 328cb37..f37fee1 100644
20256 --- a/arch/x86/kernel/vm86_32.c
20257 +++ b/arch/x86/kernel/vm86_32.c
20258 @@ -41,6 +41,7 @@
20259 #include <linux/ptrace.h>
20260 #include <linux/audit.h>
20261 #include <linux/stddef.h>
20262 +#include <linux/grsecurity.h>
20263
20264 #include <asm/uaccess.h>
20265 #include <asm/io.h>
20266 @@ -109,6 +110,9 @@ static int copy_vm86_regs_to_user(struct vm86_regs __user *user,
20267 /* convert vm86_regs to kernel_vm86_regs */
20268 static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
20269 const struct vm86_regs __user *user,
20270 + unsigned extra) __size_overflow(3);
20271 +static int copy_vm86_regs_from_user(struct kernel_vm86_regs *regs,
20272 + const struct vm86_regs __user *user,
20273 unsigned extra)
20274 {
20275 int ret = 0;
20276 @@ -148,7 +152,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20277 do_exit(SIGSEGV);
20278 }
20279
20280 - tss = &per_cpu(init_tss, get_cpu());
20281 + tss = init_tss + get_cpu();
20282 current->thread.sp0 = current->thread.saved_sp0;
20283 current->thread.sysenter_cs = __KERNEL_CS;
20284 load_sp0(tss, &current->thread);
20285 @@ -210,6 +214,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20286 struct task_struct *tsk;
20287 int tmp, ret = -EPERM;
20288
20289 +#ifdef CONFIG_GRKERNSEC_VM86
20290 + if (!capable(CAP_SYS_RAWIO)) {
20291 + gr_handle_vm86();
20292 + goto out;
20293 + }
20294 +#endif
20295 +
20296 tsk = current;
20297 if (tsk->thread.saved_sp0)
20298 goto out;
20299 @@ -240,6 +251,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20300 int tmp, ret;
20301 struct vm86plus_struct __user *v86;
20302
20303 +#ifdef CONFIG_GRKERNSEC_VM86
20304 + if (!capable(CAP_SYS_RAWIO)) {
20305 + gr_handle_vm86();
20306 + ret = -EPERM;
20307 + goto out;
20308 + }
20309 +#endif
20310 +
20311 tsk = current;
20312 switch (cmd) {
20313 case VM86_REQUEST_IRQ:
20314 @@ -326,7 +345,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20315 tsk->thread.saved_fs = info->regs32->fs;
20316 tsk->thread.saved_gs = get_user_gs(info->regs32);
20317
20318 - tss = &per_cpu(init_tss, get_cpu());
20319 + tss = init_tss + get_cpu();
20320 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20321 if (cpu_has_sep)
20322 tsk->thread.sysenter_cs = 0;
20323 @@ -533,7 +552,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20324 goto cannot_handle;
20325 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20326 goto cannot_handle;
20327 - intr_ptr = (unsigned long __user *) (i << 2);
20328 + intr_ptr = (__force unsigned long __user *) (i << 2);
20329 if (get_user(segoffs, intr_ptr))
20330 goto cannot_handle;
20331 if ((segoffs >> 16) == BIOSSEG)
20332 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20333 index 0f703f1..9e15f64 100644
20334 --- a/arch/x86/kernel/vmlinux.lds.S
20335 +++ b/arch/x86/kernel/vmlinux.lds.S
20336 @@ -26,6 +26,13 @@
20337 #include <asm/page_types.h>
20338 #include <asm/cache.h>
20339 #include <asm/boot.h>
20340 +#include <asm/segment.h>
20341 +
20342 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20343 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20344 +#else
20345 +#define __KERNEL_TEXT_OFFSET 0
20346 +#endif
20347
20348 #undef i386 /* in case the preprocessor is a 32bit one */
20349
20350 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20351
20352 PHDRS {
20353 text PT_LOAD FLAGS(5); /* R_E */
20354 +#ifdef CONFIG_X86_32
20355 + module PT_LOAD FLAGS(5); /* R_E */
20356 +#endif
20357 +#ifdef CONFIG_XEN
20358 + rodata PT_LOAD FLAGS(5); /* R_E */
20359 +#else
20360 + rodata PT_LOAD FLAGS(4); /* R__ */
20361 +#endif
20362 data PT_LOAD FLAGS(6); /* RW_ */
20363 -#ifdef CONFIG_X86_64
20364 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20365 #ifdef CONFIG_SMP
20366 percpu PT_LOAD FLAGS(6); /* RW_ */
20367 #endif
20368 + text.init PT_LOAD FLAGS(5); /* R_E */
20369 + text.exit PT_LOAD FLAGS(5); /* R_E */
20370 init PT_LOAD FLAGS(7); /* RWE */
20371 -#endif
20372 note PT_NOTE FLAGS(0); /* ___ */
20373 }
20374
20375 SECTIONS
20376 {
20377 #ifdef CONFIG_X86_32
20378 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20379 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20380 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20381 #else
20382 - . = __START_KERNEL;
20383 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20384 + . = __START_KERNEL;
20385 #endif
20386
20387 /* Text and read-only data */
20388 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20389 - _text = .;
20390 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20391 /* bootstrapping code */
20392 +#ifdef CONFIG_X86_32
20393 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20394 +#else
20395 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20396 +#endif
20397 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20398 + _text = .;
20399 HEAD_TEXT
20400 #ifdef CONFIG_X86_32
20401 . = ALIGN(PAGE_SIZE);
20402 @@ -108,13 +128,47 @@ SECTIONS
20403 IRQENTRY_TEXT
20404 *(.fixup)
20405 *(.gnu.warning)
20406 - /* End of text section */
20407 - _etext = .;
20408 } :text = 0x9090
20409
20410 - NOTES :text :note
20411 + . += __KERNEL_TEXT_OFFSET;
20412
20413 - EXCEPTION_TABLE(16) :text = 0x9090
20414 +#ifdef CONFIG_X86_32
20415 + . = ALIGN(PAGE_SIZE);
20416 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20417 +
20418 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20419 + MODULES_EXEC_VADDR = .;
20420 + BYTE(0)
20421 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20422 + . = ALIGN(HPAGE_SIZE);
20423 + MODULES_EXEC_END = . - 1;
20424 +#endif
20425 +
20426 + } :module
20427 +#endif
20428 +
20429 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20430 + /* End of text section */
20431 + _etext = . - __KERNEL_TEXT_OFFSET;
20432 + }
20433 +
20434 +#ifdef CONFIG_X86_32
20435 + . = ALIGN(PAGE_SIZE);
20436 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20437 + *(.idt)
20438 + . = ALIGN(PAGE_SIZE);
20439 + *(.empty_zero_page)
20440 + *(.initial_pg_fixmap)
20441 + *(.initial_pg_pmd)
20442 + *(.initial_page_table)
20443 + *(.swapper_pg_dir)
20444 + } :rodata
20445 +#endif
20446 +
20447 + . = ALIGN(PAGE_SIZE);
20448 + NOTES :rodata :note
20449 +
20450 + EXCEPTION_TABLE(16) :rodata
20451
20452 #if defined(CONFIG_DEBUG_RODATA)
20453 /* .text should occupy whole number of pages */
20454 @@ -126,16 +180,20 @@ SECTIONS
20455
20456 /* Data */
20457 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20458 +
20459 +#ifdef CONFIG_PAX_KERNEXEC
20460 + . = ALIGN(HPAGE_SIZE);
20461 +#else
20462 + . = ALIGN(PAGE_SIZE);
20463 +#endif
20464 +
20465 /* Start of data section */
20466 _sdata = .;
20467
20468 /* init_task */
20469 INIT_TASK_DATA(THREAD_SIZE)
20470
20471 -#ifdef CONFIG_X86_32
20472 - /* 32 bit has nosave before _edata */
20473 NOSAVE_DATA
20474 -#endif
20475
20476 PAGE_ALIGNED_DATA(PAGE_SIZE)
20477
20478 @@ -176,12 +234,19 @@ SECTIONS
20479 #endif /* CONFIG_X86_64 */
20480
20481 /* Init code and data - will be freed after init */
20482 - . = ALIGN(PAGE_SIZE);
20483 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20484 + BYTE(0)
20485 +
20486 +#ifdef CONFIG_PAX_KERNEXEC
20487 + . = ALIGN(HPAGE_SIZE);
20488 +#else
20489 + . = ALIGN(PAGE_SIZE);
20490 +#endif
20491 +
20492 __init_begin = .; /* paired with __init_end */
20493 - }
20494 + } :init.begin
20495
20496 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20497 +#ifdef CONFIG_SMP
20498 /*
20499 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20500 * output PHDR, so the next output section - .init.text - should
20501 @@ -190,12 +255,27 @@ SECTIONS
20502 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20503 #endif
20504
20505 - INIT_TEXT_SECTION(PAGE_SIZE)
20506 -#ifdef CONFIG_X86_64
20507 - :init
20508 -#endif
20509 + . = ALIGN(PAGE_SIZE);
20510 + init_begin = .;
20511 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20512 + VMLINUX_SYMBOL(_sinittext) = .;
20513 + INIT_TEXT
20514 + VMLINUX_SYMBOL(_einittext) = .;
20515 + . = ALIGN(PAGE_SIZE);
20516 + } :text.init
20517
20518 - INIT_DATA_SECTION(16)
20519 + /*
20520 + * .exit.text is discard at runtime, not link time, to deal with
20521 + * references from .altinstructions and .eh_frame
20522 + */
20523 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20524 + EXIT_TEXT
20525 + . = ALIGN(16);
20526 + } :text.exit
20527 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20528 +
20529 + . = ALIGN(PAGE_SIZE);
20530 + INIT_DATA_SECTION(16) :init
20531
20532 /*
20533 * Code and data for a variety of lowlevel trampolines, to be
20534 @@ -269,19 +349,12 @@ SECTIONS
20535 }
20536
20537 . = ALIGN(8);
20538 - /*
20539 - * .exit.text is discard at runtime, not link time, to deal with
20540 - * references from .altinstructions and .eh_frame
20541 - */
20542 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20543 - EXIT_TEXT
20544 - }
20545
20546 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20547 EXIT_DATA
20548 }
20549
20550 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20551 +#ifndef CONFIG_SMP
20552 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20553 #endif
20554
20555 @@ -300,16 +373,10 @@ SECTIONS
20556 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20557 __smp_locks = .;
20558 *(.smp_locks)
20559 - . = ALIGN(PAGE_SIZE);
20560 __smp_locks_end = .;
20561 + . = ALIGN(PAGE_SIZE);
20562 }
20563
20564 -#ifdef CONFIG_X86_64
20565 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20566 - NOSAVE_DATA
20567 - }
20568 -#endif
20569 -
20570 /* BSS */
20571 . = ALIGN(PAGE_SIZE);
20572 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20573 @@ -325,6 +392,7 @@ SECTIONS
20574 __brk_base = .;
20575 . += 64 * 1024; /* 64k alignment slop space */
20576 *(.brk_reservation) /* areas brk users have reserved */
20577 + . = ALIGN(HPAGE_SIZE);
20578 __brk_limit = .;
20579 }
20580
20581 @@ -351,13 +419,12 @@ SECTIONS
20582 * for the boot processor.
20583 */
20584 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20585 -INIT_PER_CPU(gdt_page);
20586 INIT_PER_CPU(irq_stack_union);
20587
20588 /*
20589 * Build-time check on the image size:
20590 */
20591 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20592 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20593 "kernel image bigger than KERNEL_IMAGE_SIZE");
20594
20595 #ifdef CONFIG_SMP
20596 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20597 index b07ba93..a212969 100644
20598 --- a/arch/x86/kernel/vsyscall_64.c
20599 +++ b/arch/x86/kernel/vsyscall_64.c
20600 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
20601 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
20602 };
20603
20604 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20605 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20606
20607 static int __init vsyscall_setup(char *str)
20608 {
20609 if (str) {
20610 if (!strcmp("emulate", str))
20611 vsyscall_mode = EMULATE;
20612 - else if (!strcmp("native", str))
20613 - vsyscall_mode = NATIVE;
20614 else if (!strcmp("none", str))
20615 vsyscall_mode = NONE;
20616 else
20617 @@ -207,7 +205,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20618
20619 tsk = current;
20620 if (seccomp_mode(&tsk->seccomp))
20621 - do_exit(SIGKILL);
20622 + do_group_exit(SIGKILL);
20623
20624 /*
20625 * With a real vsyscall, page faults cause SIGSEGV. We want to
20626 @@ -279,8 +277,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20627 return true;
20628
20629 sigsegv:
20630 - force_sig(SIGSEGV, current);
20631 - return true;
20632 + do_group_exit(SIGKILL);
20633 }
20634
20635 /*
20636 @@ -333,10 +330,7 @@ void __init map_vsyscall(void)
20637 extern char __vvar_page;
20638 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20639
20640 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20641 - vsyscall_mode == NATIVE
20642 - ? PAGE_KERNEL_VSYSCALL
20643 - : PAGE_KERNEL_VVAR);
20644 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20645 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20646 (unsigned long)VSYSCALL_START);
20647
20648 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20649 index 9796c2f..f686fbf 100644
20650 --- a/arch/x86/kernel/x8664_ksyms_64.c
20651 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20652 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20653 EXPORT_SYMBOL(copy_user_generic_string);
20654 EXPORT_SYMBOL(copy_user_generic_unrolled);
20655 EXPORT_SYMBOL(__copy_user_nocache);
20656 -EXPORT_SYMBOL(_copy_from_user);
20657 -EXPORT_SYMBOL(_copy_to_user);
20658
20659 EXPORT_SYMBOL(copy_page);
20660 EXPORT_SYMBOL(clear_page);
20661 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20662 index 7110911..e8cdee5 100644
20663 --- a/arch/x86/kernel/xsave.c
20664 +++ b/arch/x86/kernel/xsave.c
20665 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20666 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20667 return -EINVAL;
20668
20669 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20670 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20671 fx_sw_user->extended_size -
20672 FP_XSTATE_MAGIC2_SIZE));
20673 if (err)
20674 @@ -266,7 +266,7 @@ fx_only:
20675 * the other extended state.
20676 */
20677 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20678 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20679 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20680 }
20681
20682 /*
20683 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
20684 if (use_xsave())
20685 err = restore_user_xstate(buf);
20686 else
20687 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20688 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20689 buf);
20690 if (unlikely(err)) {
20691 /*
20692 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20693 index 89b02bf..0f6511d 100644
20694 --- a/arch/x86/kvm/cpuid.c
20695 +++ b/arch/x86/kvm/cpuid.c
20696 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20697 struct kvm_cpuid2 *cpuid,
20698 struct kvm_cpuid_entry2 __user *entries)
20699 {
20700 - int r;
20701 + int r, i;
20702
20703 r = -E2BIG;
20704 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20705 goto out;
20706 r = -EFAULT;
20707 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20708 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20709 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20710 goto out;
20711 + for (i = 0; i < cpuid->nent; ++i) {
20712 + struct kvm_cpuid_entry2 cpuid_entry;
20713 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20714 + goto out;
20715 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20716 + }
20717 vcpu->arch.cpuid_nent = cpuid->nent;
20718 kvm_apic_set_version(vcpu);
20719 kvm_x86_ops->cpuid_update(vcpu);
20720 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20721 struct kvm_cpuid2 *cpuid,
20722 struct kvm_cpuid_entry2 __user *entries)
20723 {
20724 - int r;
20725 + int r, i;
20726
20727 r = -E2BIG;
20728 if (cpuid->nent < vcpu->arch.cpuid_nent)
20729 goto out;
20730 r = -EFAULT;
20731 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20732 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20733 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20734 goto out;
20735 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20736 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20737 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20738 + goto out;
20739 + }
20740 return 0;
20741
20742 out:
20743 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20744 index 0982507..7f6d72f 100644
20745 --- a/arch/x86/kvm/emulate.c
20746 +++ b/arch/x86/kvm/emulate.c
20747 @@ -250,6 +250,7 @@ struct gprefix {
20748
20749 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20750 do { \
20751 + unsigned long _tmp; \
20752 __asm__ __volatile__ ( \
20753 _PRE_EFLAGS("0", "4", "2") \
20754 _op _suffix " %"_x"3,%1; " \
20755 @@ -264,8 +265,6 @@ struct gprefix {
20756 /* Raw emulation: instruction has two explicit operands. */
20757 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20758 do { \
20759 - unsigned long _tmp; \
20760 - \
20761 switch ((ctxt)->dst.bytes) { \
20762 case 2: \
20763 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20764 @@ -281,7 +280,6 @@ struct gprefix {
20765
20766 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20767 do { \
20768 - unsigned long _tmp; \
20769 switch ((ctxt)->dst.bytes) { \
20770 case 1: \
20771 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20772 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20773 index cfdc6e0..ab92e84 100644
20774 --- a/arch/x86/kvm/lapic.c
20775 +++ b/arch/x86/kvm/lapic.c
20776 @@ -54,7 +54,7 @@
20777 #define APIC_BUS_CYCLE_NS 1
20778
20779 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20780 -#define apic_debug(fmt, arg...)
20781 +#define apic_debug(fmt, arg...) do {} while (0)
20782
20783 #define APIC_LVT_NUM 6
20784 /* 14 is the version for Xeon and Pentium 8.4.8*/
20785 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20786 index 1561028..0ed7f14 100644
20787 --- a/arch/x86/kvm/paging_tmpl.h
20788 +++ b/arch/x86/kvm/paging_tmpl.h
20789 @@ -197,7 +197,7 @@ retry_walk:
20790 if (unlikely(kvm_is_error_hva(host_addr)))
20791 goto error;
20792
20793 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20794 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20795 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20796 goto error;
20797
20798 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20799 index e385214..f8df033 100644
20800 --- a/arch/x86/kvm/svm.c
20801 +++ b/arch/x86/kvm/svm.c
20802 @@ -3420,7 +3420,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20803 int cpu = raw_smp_processor_id();
20804
20805 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20806 +
20807 + pax_open_kernel();
20808 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20809 + pax_close_kernel();
20810 +
20811 load_TR_desc();
20812 }
20813
20814 @@ -3798,6 +3802,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20815 #endif
20816 #endif
20817
20818 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20819 + __set_fs(current_thread_info()->addr_limit);
20820 +#endif
20821 +
20822 reload_tss(vcpu);
20823
20824 local_irq_disable();
20825 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20826 index a7a6f60..04b745a 100644
20827 --- a/arch/x86/kvm/vmx.c
20828 +++ b/arch/x86/kvm/vmx.c
20829 @@ -1306,7 +1306,11 @@ static void reload_tss(void)
20830 struct desc_struct *descs;
20831
20832 descs = (void *)gdt->address;
20833 +
20834 + pax_open_kernel();
20835 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20836 + pax_close_kernel();
20837 +
20838 load_TR_desc();
20839 }
20840
20841 @@ -2637,8 +2641,11 @@ static __init int hardware_setup(void)
20842 if (!cpu_has_vmx_flexpriority())
20843 flexpriority_enabled = 0;
20844
20845 - if (!cpu_has_vmx_tpr_shadow())
20846 - kvm_x86_ops->update_cr8_intercept = NULL;
20847 + if (!cpu_has_vmx_tpr_shadow()) {
20848 + pax_open_kernel();
20849 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20850 + pax_close_kernel();
20851 + }
20852
20853 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20854 kvm_disable_largepages();
20855 @@ -3654,7 +3661,7 @@ static void vmx_set_constant_host_state(void)
20856 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20857
20858 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20859 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20860 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20861
20862 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20863 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20864 @@ -6192,6 +6199,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20865 "jmp .Lkvm_vmx_return \n\t"
20866 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20867 ".Lkvm_vmx_return: "
20868 +
20869 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20870 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20871 + ".Lkvm_vmx_return2: "
20872 +#endif
20873 +
20874 /* Save guest registers, load host registers, keep flags */
20875 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20876 "pop %0 \n\t"
20877 @@ -6240,6 +6253,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20878 #endif
20879 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20880 [wordsize]"i"(sizeof(ulong))
20881 +
20882 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20883 + ,[cs]"i"(__KERNEL_CS)
20884 +#endif
20885 +
20886 : "cc", "memory"
20887 , R"ax", R"bx", R"di", R"si"
20888 #ifdef CONFIG_X86_64
20889 @@ -6268,7 +6286,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20890 }
20891 }
20892
20893 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20894 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20895 +
20896 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20897 + loadsegment(fs, __KERNEL_PERCPU);
20898 +#endif
20899 +
20900 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20901 + __set_fs(current_thread_info()->addr_limit);
20902 +#endif
20903 +
20904 vmx->loaded_vmcs->launched = 1;
20905
20906 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20907 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20908 index 8d1c6c6..6e6d611 100644
20909 --- a/arch/x86/kvm/x86.c
20910 +++ b/arch/x86/kvm/x86.c
20911 @@ -873,6 +873,7 @@ static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
20912 return kvm_set_msr(vcpu, index, *data);
20913 }
20914
20915 +static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) __size_overflow(2);
20916 static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
20917 {
20918 int version;
20919 @@ -1307,12 +1308,13 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 data)
20920 return 0;
20921 }
20922
20923 +static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data) __size_overflow(2);
20924 static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20925 {
20926 struct kvm *kvm = vcpu->kvm;
20927 int lm = is_long_mode(vcpu);
20928 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20929 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20930 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20931 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20932 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20933 : kvm->arch.xen_hvm_config.blob_size_32;
20934 u32 page_num = data & ~PAGE_MASK;
20935 @@ -2145,6 +2147,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20936 if (n < msr_list.nmsrs)
20937 goto out;
20938 r = -EFAULT;
20939 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20940 + goto out;
20941 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20942 num_msrs_to_save * sizeof(u32)))
20943 goto out;
20944 @@ -2266,7 +2270,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20945 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20946 struct kvm_interrupt *irq)
20947 {
20948 - if (irq->irq < 0 || irq->irq >= 256)
20949 + if (irq->irq >= 256)
20950 return -EINVAL;
20951 if (irqchip_in_kernel(vcpu->kvm))
20952 return -ENXIO;
20953 @@ -3499,6 +3503,9 @@ gpa_t kvm_mmu_gva_to_gpa_system(struct kvm_vcpu *vcpu, gva_t gva,
20954
20955 static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20956 struct kvm_vcpu *vcpu, u32 access,
20957 + struct x86_exception *exception) __size_overflow(1,3);
20958 +static int kvm_read_guest_virt_helper(gva_t addr, void *val, unsigned int bytes,
20959 + struct kvm_vcpu *vcpu, u32 access,
20960 struct x86_exception *exception)
20961 {
20962 void *data = val;
20963 @@ -3530,6 +3537,9 @@ out:
20964 /* used for instruction fetching */
20965 static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20966 gva_t addr, void *val, unsigned int bytes,
20967 + struct x86_exception *exception) __size_overflow(2,4);
20968 +static int kvm_fetch_guest_virt(struct x86_emulate_ctxt *ctxt,
20969 + gva_t addr, void *val, unsigned int bytes,
20970 struct x86_exception *exception)
20971 {
20972 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20973 @@ -3554,6 +3564,9 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_virt);
20974
20975 static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20976 gva_t addr, void *val, unsigned int bytes,
20977 + struct x86_exception *exception) __size_overflow(2,4);
20978 +static int kvm_read_guest_virt_system(struct x86_emulate_ctxt *ctxt,
20979 + gva_t addr, void *val, unsigned int bytes,
20980 struct x86_exception *exception)
20981 {
20982 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
20983 @@ -3667,12 +3680,16 @@ static int read_prepare(struct kvm_vcpu *vcpu, void *val, int bytes)
20984 }
20985
20986 static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20987 + void *val, int bytes) __size_overflow(2);
20988 +static int read_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20989 void *val, int bytes)
20990 {
20991 return !kvm_read_guest(vcpu->kvm, gpa, val, bytes);
20992 }
20993
20994 static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20995 + void *val, int bytes) __size_overflow(2);
20996 +static int write_emulate(struct kvm_vcpu *vcpu, gpa_t gpa,
20997 void *val, int bytes)
20998 {
20999 return emulator_write_phys(vcpu, gpa, val, bytes);
21000 @@ -3823,6 +3840,12 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
21001 const void *old,
21002 const void *new,
21003 unsigned int bytes,
21004 + struct x86_exception *exception) __size_overflow(5);
21005 +static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt,
21006 + unsigned long addr,
21007 + const void *old,
21008 + const void *new,
21009 + unsigned int bytes,
21010 struct x86_exception *exception)
21011 {
21012 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
21013 @@ -4782,7 +4805,7 @@ static void kvm_set_mmio_spte_mask(void)
21014 kvm_mmu_set_mmio_spte_mask(mask);
21015 }
21016
21017 -int kvm_arch_init(void *opaque)
21018 +int kvm_arch_init(const void *opaque)
21019 {
21020 int r;
21021 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
21022 diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
21023 index cb80c29..aeee86c 100644
21024 --- a/arch/x86/kvm/x86.h
21025 +++ b/arch/x86/kvm/x86.h
21026 @@ -116,11 +116,11 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data);
21027
21028 int kvm_read_guest_virt(struct x86_emulate_ctxt *ctxt,
21029 gva_t addr, void *val, unsigned int bytes,
21030 - struct x86_exception *exception);
21031 + struct x86_exception *exception) __size_overflow(2,4);
21032
21033 int kvm_write_guest_virt_system(struct x86_emulate_ctxt *ctxt,
21034 gva_t addr, void *val, unsigned int bytes,
21035 - struct x86_exception *exception);
21036 + struct x86_exception *exception) __size_overflow(2,4);
21037
21038 extern u64 host_xcr0;
21039
21040 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
21041 index 642d880..44e0f3f 100644
21042 --- a/arch/x86/lguest/boot.c
21043 +++ b/arch/x86/lguest/boot.c
21044 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
21045 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
21046 * Launcher to reboot us.
21047 */
21048 -static void lguest_restart(char *reason)
21049 +static __noreturn void lguest_restart(char *reason)
21050 {
21051 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
21052 + BUG();
21053 }
21054
21055 /*G:050
21056 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
21057 index 042f682..c92afb6 100644
21058 --- a/arch/x86/lib/atomic64_32.c
21059 +++ b/arch/x86/lib/atomic64_32.c
21060 @@ -8,18 +8,30 @@
21061
21062 long long atomic64_read_cx8(long long, const atomic64_t *v);
21063 EXPORT_SYMBOL(atomic64_read_cx8);
21064 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
21065 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
21066 long long atomic64_set_cx8(long long, const atomic64_t *v);
21067 EXPORT_SYMBOL(atomic64_set_cx8);
21068 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
21069 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
21070 long long atomic64_xchg_cx8(long long, unsigned high);
21071 EXPORT_SYMBOL(atomic64_xchg_cx8);
21072 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
21073 EXPORT_SYMBOL(atomic64_add_return_cx8);
21074 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
21075 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
21076 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
21077 EXPORT_SYMBOL(atomic64_sub_return_cx8);
21078 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
21079 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
21080 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
21081 EXPORT_SYMBOL(atomic64_inc_return_cx8);
21082 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
21083 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
21084 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
21085 EXPORT_SYMBOL(atomic64_dec_return_cx8);
21086 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
21087 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
21088 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
21089 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
21090 int atomic64_inc_not_zero_cx8(atomic64_t *v);
21091 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
21092 #ifndef CONFIG_X86_CMPXCHG64
21093 long long atomic64_read_386(long long, const atomic64_t *v);
21094 EXPORT_SYMBOL(atomic64_read_386);
21095 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
21096 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
21097 long long atomic64_set_386(long long, const atomic64_t *v);
21098 EXPORT_SYMBOL(atomic64_set_386);
21099 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
21100 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
21101 long long atomic64_xchg_386(long long, unsigned high);
21102 EXPORT_SYMBOL(atomic64_xchg_386);
21103 long long atomic64_add_return_386(long long a, atomic64_t *v);
21104 EXPORT_SYMBOL(atomic64_add_return_386);
21105 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
21106 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
21107 long long atomic64_sub_return_386(long long a, atomic64_t *v);
21108 EXPORT_SYMBOL(atomic64_sub_return_386);
21109 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
21110 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
21111 long long atomic64_inc_return_386(long long a, atomic64_t *v);
21112 EXPORT_SYMBOL(atomic64_inc_return_386);
21113 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
21114 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
21115 long long atomic64_dec_return_386(long long a, atomic64_t *v);
21116 EXPORT_SYMBOL(atomic64_dec_return_386);
21117 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
21118 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
21119 long long atomic64_add_386(long long a, atomic64_t *v);
21120 EXPORT_SYMBOL(atomic64_add_386);
21121 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
21122 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
21123 long long atomic64_sub_386(long long a, atomic64_t *v);
21124 EXPORT_SYMBOL(atomic64_sub_386);
21125 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
21126 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
21127 long long atomic64_inc_386(long long a, atomic64_t *v);
21128 EXPORT_SYMBOL(atomic64_inc_386);
21129 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
21130 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
21131 long long atomic64_dec_386(long long a, atomic64_t *v);
21132 EXPORT_SYMBOL(atomic64_dec_386);
21133 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
21134 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
21135 long long atomic64_dec_if_positive_386(atomic64_t *v);
21136 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
21137 int atomic64_inc_not_zero_386(atomic64_t *v);
21138 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
21139 index e8e7e0d..56fd1b0 100644
21140 --- a/arch/x86/lib/atomic64_386_32.S
21141 +++ b/arch/x86/lib/atomic64_386_32.S
21142 @@ -48,6 +48,10 @@ BEGIN(read)
21143 movl (v), %eax
21144 movl 4(v), %edx
21145 RET_ENDP
21146 +BEGIN(read_unchecked)
21147 + movl (v), %eax
21148 + movl 4(v), %edx
21149 +RET_ENDP
21150 #undef v
21151
21152 #define v %esi
21153 @@ -55,6 +59,10 @@ BEGIN(set)
21154 movl %ebx, (v)
21155 movl %ecx, 4(v)
21156 RET_ENDP
21157 +BEGIN(set_unchecked)
21158 + movl %ebx, (v)
21159 + movl %ecx, 4(v)
21160 +RET_ENDP
21161 #undef v
21162
21163 #define v %esi
21164 @@ -70,6 +78,20 @@ RET_ENDP
21165 BEGIN(add)
21166 addl %eax, (v)
21167 adcl %edx, 4(v)
21168 +
21169 +#ifdef CONFIG_PAX_REFCOUNT
21170 + jno 0f
21171 + subl %eax, (v)
21172 + sbbl %edx, 4(v)
21173 + int $4
21174 +0:
21175 + _ASM_EXTABLE(0b, 0b)
21176 +#endif
21177 +
21178 +RET_ENDP
21179 +BEGIN(add_unchecked)
21180 + addl %eax, (v)
21181 + adcl %edx, 4(v)
21182 RET_ENDP
21183 #undef v
21184
21185 @@ -77,6 +99,24 @@ RET_ENDP
21186 BEGIN(add_return)
21187 addl (v), %eax
21188 adcl 4(v), %edx
21189 +
21190 +#ifdef CONFIG_PAX_REFCOUNT
21191 + into
21192 +1234:
21193 + _ASM_EXTABLE(1234b, 2f)
21194 +#endif
21195 +
21196 + movl %eax, (v)
21197 + movl %edx, 4(v)
21198 +
21199 +#ifdef CONFIG_PAX_REFCOUNT
21200 +2:
21201 +#endif
21202 +
21203 +RET_ENDP
21204 +BEGIN(add_return_unchecked)
21205 + addl (v), %eax
21206 + adcl 4(v), %edx
21207 movl %eax, (v)
21208 movl %edx, 4(v)
21209 RET_ENDP
21210 @@ -86,6 +126,20 @@ RET_ENDP
21211 BEGIN(sub)
21212 subl %eax, (v)
21213 sbbl %edx, 4(v)
21214 +
21215 +#ifdef CONFIG_PAX_REFCOUNT
21216 + jno 0f
21217 + addl %eax, (v)
21218 + adcl %edx, 4(v)
21219 + int $4
21220 +0:
21221 + _ASM_EXTABLE(0b, 0b)
21222 +#endif
21223 +
21224 +RET_ENDP
21225 +BEGIN(sub_unchecked)
21226 + subl %eax, (v)
21227 + sbbl %edx, 4(v)
21228 RET_ENDP
21229 #undef v
21230
21231 @@ -96,6 +150,27 @@ BEGIN(sub_return)
21232 sbbl $0, %edx
21233 addl (v), %eax
21234 adcl 4(v), %edx
21235 +
21236 +#ifdef CONFIG_PAX_REFCOUNT
21237 + into
21238 +1234:
21239 + _ASM_EXTABLE(1234b, 2f)
21240 +#endif
21241 +
21242 + movl %eax, (v)
21243 + movl %edx, 4(v)
21244 +
21245 +#ifdef CONFIG_PAX_REFCOUNT
21246 +2:
21247 +#endif
21248 +
21249 +RET_ENDP
21250 +BEGIN(sub_return_unchecked)
21251 + negl %edx
21252 + negl %eax
21253 + sbbl $0, %edx
21254 + addl (v), %eax
21255 + adcl 4(v), %edx
21256 movl %eax, (v)
21257 movl %edx, 4(v)
21258 RET_ENDP
21259 @@ -105,6 +180,20 @@ RET_ENDP
21260 BEGIN(inc)
21261 addl $1, (v)
21262 adcl $0, 4(v)
21263 +
21264 +#ifdef CONFIG_PAX_REFCOUNT
21265 + jno 0f
21266 + subl $1, (v)
21267 + sbbl $0, 4(v)
21268 + int $4
21269 +0:
21270 + _ASM_EXTABLE(0b, 0b)
21271 +#endif
21272 +
21273 +RET_ENDP
21274 +BEGIN(inc_unchecked)
21275 + addl $1, (v)
21276 + adcl $0, 4(v)
21277 RET_ENDP
21278 #undef v
21279
21280 @@ -114,6 +203,26 @@ BEGIN(inc_return)
21281 movl 4(v), %edx
21282 addl $1, %eax
21283 adcl $0, %edx
21284 +
21285 +#ifdef CONFIG_PAX_REFCOUNT
21286 + into
21287 +1234:
21288 + _ASM_EXTABLE(1234b, 2f)
21289 +#endif
21290 +
21291 + movl %eax, (v)
21292 + movl %edx, 4(v)
21293 +
21294 +#ifdef CONFIG_PAX_REFCOUNT
21295 +2:
21296 +#endif
21297 +
21298 +RET_ENDP
21299 +BEGIN(inc_return_unchecked)
21300 + movl (v), %eax
21301 + movl 4(v), %edx
21302 + addl $1, %eax
21303 + adcl $0, %edx
21304 movl %eax, (v)
21305 movl %edx, 4(v)
21306 RET_ENDP
21307 @@ -123,6 +232,20 @@ RET_ENDP
21308 BEGIN(dec)
21309 subl $1, (v)
21310 sbbl $0, 4(v)
21311 +
21312 +#ifdef CONFIG_PAX_REFCOUNT
21313 + jno 0f
21314 + addl $1, (v)
21315 + adcl $0, 4(v)
21316 + int $4
21317 +0:
21318 + _ASM_EXTABLE(0b, 0b)
21319 +#endif
21320 +
21321 +RET_ENDP
21322 +BEGIN(dec_unchecked)
21323 + subl $1, (v)
21324 + sbbl $0, 4(v)
21325 RET_ENDP
21326 #undef v
21327
21328 @@ -132,6 +255,26 @@ BEGIN(dec_return)
21329 movl 4(v), %edx
21330 subl $1, %eax
21331 sbbl $0, %edx
21332 +
21333 +#ifdef CONFIG_PAX_REFCOUNT
21334 + into
21335 +1234:
21336 + _ASM_EXTABLE(1234b, 2f)
21337 +#endif
21338 +
21339 + movl %eax, (v)
21340 + movl %edx, 4(v)
21341 +
21342 +#ifdef CONFIG_PAX_REFCOUNT
21343 +2:
21344 +#endif
21345 +
21346 +RET_ENDP
21347 +BEGIN(dec_return_unchecked)
21348 + movl (v), %eax
21349 + movl 4(v), %edx
21350 + subl $1, %eax
21351 + sbbl $0, %edx
21352 movl %eax, (v)
21353 movl %edx, 4(v)
21354 RET_ENDP
21355 @@ -143,6 +286,13 @@ BEGIN(add_unless)
21356 adcl %edx, %edi
21357 addl (v), %eax
21358 adcl 4(v), %edx
21359 +
21360 +#ifdef CONFIG_PAX_REFCOUNT
21361 + into
21362 +1234:
21363 + _ASM_EXTABLE(1234b, 2f)
21364 +#endif
21365 +
21366 cmpl %eax, %esi
21367 je 3f
21368 1:
21369 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
21370 1:
21371 addl $1, %eax
21372 adcl $0, %edx
21373 +
21374 +#ifdef CONFIG_PAX_REFCOUNT
21375 + into
21376 +1234:
21377 + _ASM_EXTABLE(1234b, 2f)
21378 +#endif
21379 +
21380 movl %eax, (v)
21381 movl %edx, 4(v)
21382 movl $1, %eax
21383 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
21384 movl 4(v), %edx
21385 subl $1, %eax
21386 sbbl $0, %edx
21387 +
21388 +#ifdef CONFIG_PAX_REFCOUNT
21389 + into
21390 +1234:
21391 + _ASM_EXTABLE(1234b, 1f)
21392 +#endif
21393 +
21394 js 1f
21395 movl %eax, (v)
21396 movl %edx, 4(v)
21397 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
21398 index 391a083..3a2cf39 100644
21399 --- a/arch/x86/lib/atomic64_cx8_32.S
21400 +++ b/arch/x86/lib/atomic64_cx8_32.S
21401 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
21402 CFI_STARTPROC
21403
21404 read64 %ecx
21405 + pax_force_retaddr
21406 ret
21407 CFI_ENDPROC
21408 ENDPROC(atomic64_read_cx8)
21409
21410 +ENTRY(atomic64_read_unchecked_cx8)
21411 + CFI_STARTPROC
21412 +
21413 + read64 %ecx
21414 + pax_force_retaddr
21415 + ret
21416 + CFI_ENDPROC
21417 +ENDPROC(atomic64_read_unchecked_cx8)
21418 +
21419 ENTRY(atomic64_set_cx8)
21420 CFI_STARTPROC
21421
21422 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
21423 cmpxchg8b (%esi)
21424 jne 1b
21425
21426 + pax_force_retaddr
21427 ret
21428 CFI_ENDPROC
21429 ENDPROC(atomic64_set_cx8)
21430
21431 +ENTRY(atomic64_set_unchecked_cx8)
21432 + CFI_STARTPROC
21433 +
21434 +1:
21435 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
21436 + * are atomic on 586 and newer */
21437 + cmpxchg8b (%esi)
21438 + jne 1b
21439 +
21440 + pax_force_retaddr
21441 + ret
21442 + CFI_ENDPROC
21443 +ENDPROC(atomic64_set_unchecked_cx8)
21444 +
21445 ENTRY(atomic64_xchg_cx8)
21446 CFI_STARTPROC
21447
21448 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
21449 cmpxchg8b (%esi)
21450 jne 1b
21451
21452 + pax_force_retaddr
21453 ret
21454 CFI_ENDPROC
21455 ENDPROC(atomic64_xchg_cx8)
21456
21457 -.macro addsub_return func ins insc
21458 -ENTRY(atomic64_\func\()_return_cx8)
21459 +.macro addsub_return func ins insc unchecked=""
21460 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21461 CFI_STARTPROC
21462 SAVE ebp
21463 SAVE ebx
21464 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21465 movl %edx, %ecx
21466 \ins\()l %esi, %ebx
21467 \insc\()l %edi, %ecx
21468 +
21469 +.ifb \unchecked
21470 +#ifdef CONFIG_PAX_REFCOUNT
21471 + into
21472 +2:
21473 + _ASM_EXTABLE(2b, 3f)
21474 +#endif
21475 +.endif
21476 +
21477 LOCK_PREFIX
21478 cmpxchg8b (%ebp)
21479 jne 1b
21480 -
21481 -10:
21482 movl %ebx, %eax
21483 movl %ecx, %edx
21484 +
21485 +.ifb \unchecked
21486 +#ifdef CONFIG_PAX_REFCOUNT
21487 +3:
21488 +#endif
21489 +.endif
21490 +
21491 RESTORE edi
21492 RESTORE esi
21493 RESTORE ebx
21494 RESTORE ebp
21495 + pax_force_retaddr
21496 ret
21497 CFI_ENDPROC
21498 -ENDPROC(atomic64_\func\()_return_cx8)
21499 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21500 .endm
21501
21502 addsub_return add add adc
21503 addsub_return sub sub sbb
21504 +addsub_return add add adc _unchecked
21505 +addsub_return sub sub sbb _unchecked
21506
21507 -.macro incdec_return func ins insc
21508 -ENTRY(atomic64_\func\()_return_cx8)
21509 +.macro incdec_return func ins insc unchecked=""
21510 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21511 CFI_STARTPROC
21512 SAVE ebx
21513
21514 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21515 movl %edx, %ecx
21516 \ins\()l $1, %ebx
21517 \insc\()l $0, %ecx
21518 +
21519 +.ifb \unchecked
21520 +#ifdef CONFIG_PAX_REFCOUNT
21521 + into
21522 +2:
21523 + _ASM_EXTABLE(2b, 3f)
21524 +#endif
21525 +.endif
21526 +
21527 LOCK_PREFIX
21528 cmpxchg8b (%esi)
21529 jne 1b
21530
21531 -10:
21532 movl %ebx, %eax
21533 movl %ecx, %edx
21534 +
21535 +.ifb \unchecked
21536 +#ifdef CONFIG_PAX_REFCOUNT
21537 +3:
21538 +#endif
21539 +.endif
21540 +
21541 RESTORE ebx
21542 + pax_force_retaddr
21543 ret
21544 CFI_ENDPROC
21545 -ENDPROC(atomic64_\func\()_return_cx8)
21546 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21547 .endm
21548
21549 incdec_return inc add adc
21550 incdec_return dec sub sbb
21551 +incdec_return inc add adc _unchecked
21552 +incdec_return dec sub sbb _unchecked
21553
21554 ENTRY(atomic64_dec_if_positive_cx8)
21555 CFI_STARTPROC
21556 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21557 movl %edx, %ecx
21558 subl $1, %ebx
21559 sbb $0, %ecx
21560 +
21561 +#ifdef CONFIG_PAX_REFCOUNT
21562 + into
21563 +1234:
21564 + _ASM_EXTABLE(1234b, 2f)
21565 +#endif
21566 +
21567 js 2f
21568 LOCK_PREFIX
21569 cmpxchg8b (%esi)
21570 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21571 movl %ebx, %eax
21572 movl %ecx, %edx
21573 RESTORE ebx
21574 + pax_force_retaddr
21575 ret
21576 CFI_ENDPROC
21577 ENDPROC(atomic64_dec_if_positive_cx8)
21578 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
21579 movl %edx, %ecx
21580 addl %esi, %ebx
21581 adcl %edi, %ecx
21582 +
21583 +#ifdef CONFIG_PAX_REFCOUNT
21584 + into
21585 +1234:
21586 + _ASM_EXTABLE(1234b, 3f)
21587 +#endif
21588 +
21589 LOCK_PREFIX
21590 cmpxchg8b (%ebp)
21591 jne 1b
21592 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
21593 CFI_ADJUST_CFA_OFFSET -8
21594 RESTORE ebx
21595 RESTORE ebp
21596 + pax_force_retaddr
21597 ret
21598 4:
21599 cmpl %edx, 4(%esp)
21600 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21601 movl %edx, %ecx
21602 addl $1, %ebx
21603 adcl $0, %ecx
21604 +
21605 +#ifdef CONFIG_PAX_REFCOUNT
21606 + into
21607 +1234:
21608 + _ASM_EXTABLE(1234b, 3f)
21609 +#endif
21610 +
21611 LOCK_PREFIX
21612 cmpxchg8b (%esi)
21613 jne 1b
21614 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21615 movl $1, %eax
21616 3:
21617 RESTORE ebx
21618 + pax_force_retaddr
21619 ret
21620 4:
21621 testl %edx, %edx
21622 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21623 index 78d16a5..fbcf666 100644
21624 --- a/arch/x86/lib/checksum_32.S
21625 +++ b/arch/x86/lib/checksum_32.S
21626 @@ -28,7 +28,8 @@
21627 #include <linux/linkage.h>
21628 #include <asm/dwarf2.h>
21629 #include <asm/errno.h>
21630 -
21631 +#include <asm/segment.h>
21632 +
21633 /*
21634 * computes a partial checksum, e.g. for TCP/UDP fragments
21635 */
21636 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21637
21638 #define ARGBASE 16
21639 #define FP 12
21640 -
21641 -ENTRY(csum_partial_copy_generic)
21642 +
21643 +ENTRY(csum_partial_copy_generic_to_user)
21644 CFI_STARTPROC
21645 +
21646 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21647 + pushl_cfi %gs
21648 + popl_cfi %es
21649 + jmp csum_partial_copy_generic
21650 +#endif
21651 +
21652 +ENTRY(csum_partial_copy_generic_from_user)
21653 +
21654 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21655 + pushl_cfi %gs
21656 + popl_cfi %ds
21657 +#endif
21658 +
21659 +ENTRY(csum_partial_copy_generic)
21660 subl $4,%esp
21661 CFI_ADJUST_CFA_OFFSET 4
21662 pushl_cfi %edi
21663 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21664 jmp 4f
21665 SRC(1: movw (%esi), %bx )
21666 addl $2, %esi
21667 -DST( movw %bx, (%edi) )
21668 +DST( movw %bx, %es:(%edi) )
21669 addl $2, %edi
21670 addw %bx, %ax
21671 adcl $0, %eax
21672 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21673 SRC(1: movl (%esi), %ebx )
21674 SRC( movl 4(%esi), %edx )
21675 adcl %ebx, %eax
21676 -DST( movl %ebx, (%edi) )
21677 +DST( movl %ebx, %es:(%edi) )
21678 adcl %edx, %eax
21679 -DST( movl %edx, 4(%edi) )
21680 +DST( movl %edx, %es:4(%edi) )
21681
21682 SRC( movl 8(%esi), %ebx )
21683 SRC( movl 12(%esi), %edx )
21684 adcl %ebx, %eax
21685 -DST( movl %ebx, 8(%edi) )
21686 +DST( movl %ebx, %es:8(%edi) )
21687 adcl %edx, %eax
21688 -DST( movl %edx, 12(%edi) )
21689 +DST( movl %edx, %es:12(%edi) )
21690
21691 SRC( movl 16(%esi), %ebx )
21692 SRC( movl 20(%esi), %edx )
21693 adcl %ebx, %eax
21694 -DST( movl %ebx, 16(%edi) )
21695 +DST( movl %ebx, %es:16(%edi) )
21696 adcl %edx, %eax
21697 -DST( movl %edx, 20(%edi) )
21698 +DST( movl %edx, %es:20(%edi) )
21699
21700 SRC( movl 24(%esi), %ebx )
21701 SRC( movl 28(%esi), %edx )
21702 adcl %ebx, %eax
21703 -DST( movl %ebx, 24(%edi) )
21704 +DST( movl %ebx, %es:24(%edi) )
21705 adcl %edx, %eax
21706 -DST( movl %edx, 28(%edi) )
21707 +DST( movl %edx, %es:28(%edi) )
21708
21709 lea 32(%esi), %esi
21710 lea 32(%edi), %edi
21711 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21712 shrl $2, %edx # This clears CF
21713 SRC(3: movl (%esi), %ebx )
21714 adcl %ebx, %eax
21715 -DST( movl %ebx, (%edi) )
21716 +DST( movl %ebx, %es:(%edi) )
21717 lea 4(%esi), %esi
21718 lea 4(%edi), %edi
21719 dec %edx
21720 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21721 jb 5f
21722 SRC( movw (%esi), %cx )
21723 leal 2(%esi), %esi
21724 -DST( movw %cx, (%edi) )
21725 +DST( movw %cx, %es:(%edi) )
21726 leal 2(%edi), %edi
21727 je 6f
21728 shll $16,%ecx
21729 SRC(5: movb (%esi), %cl )
21730 -DST( movb %cl, (%edi) )
21731 +DST( movb %cl, %es:(%edi) )
21732 6: addl %ecx, %eax
21733 adcl $0, %eax
21734 7:
21735 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21736
21737 6001:
21738 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21739 - movl $-EFAULT, (%ebx)
21740 + movl $-EFAULT, %ss:(%ebx)
21741
21742 # zero the complete destination - computing the rest
21743 # is too much work
21744 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21745
21746 6002:
21747 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21748 - movl $-EFAULT,(%ebx)
21749 + movl $-EFAULT,%ss:(%ebx)
21750 jmp 5000b
21751
21752 .previous
21753
21754 + pushl_cfi %ss
21755 + popl_cfi %ds
21756 + pushl_cfi %ss
21757 + popl_cfi %es
21758 popl_cfi %ebx
21759 CFI_RESTORE ebx
21760 popl_cfi %esi
21761 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21762 popl_cfi %ecx # equivalent to addl $4,%esp
21763 ret
21764 CFI_ENDPROC
21765 -ENDPROC(csum_partial_copy_generic)
21766 +ENDPROC(csum_partial_copy_generic_to_user)
21767
21768 #else
21769
21770 /* Version for PentiumII/PPro */
21771
21772 #define ROUND1(x) \
21773 + nop; nop; nop; \
21774 SRC(movl x(%esi), %ebx ) ; \
21775 addl %ebx, %eax ; \
21776 - DST(movl %ebx, x(%edi) ) ;
21777 + DST(movl %ebx, %es:x(%edi)) ;
21778
21779 #define ROUND(x) \
21780 + nop; nop; nop; \
21781 SRC(movl x(%esi), %ebx ) ; \
21782 adcl %ebx, %eax ; \
21783 - DST(movl %ebx, x(%edi) ) ;
21784 + DST(movl %ebx, %es:x(%edi)) ;
21785
21786 #define ARGBASE 12
21787 -
21788 -ENTRY(csum_partial_copy_generic)
21789 +
21790 +ENTRY(csum_partial_copy_generic_to_user)
21791 CFI_STARTPROC
21792 +
21793 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21794 + pushl_cfi %gs
21795 + popl_cfi %es
21796 + jmp csum_partial_copy_generic
21797 +#endif
21798 +
21799 +ENTRY(csum_partial_copy_generic_from_user)
21800 +
21801 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21802 + pushl_cfi %gs
21803 + popl_cfi %ds
21804 +#endif
21805 +
21806 +ENTRY(csum_partial_copy_generic)
21807 pushl_cfi %ebx
21808 CFI_REL_OFFSET ebx, 0
21809 pushl_cfi %edi
21810 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21811 subl %ebx, %edi
21812 lea -1(%esi),%edx
21813 andl $-32,%edx
21814 - lea 3f(%ebx,%ebx), %ebx
21815 + lea 3f(%ebx,%ebx,2), %ebx
21816 testl %esi, %esi
21817 jmp *%ebx
21818 1: addl $64,%esi
21819 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21820 jb 5f
21821 SRC( movw (%esi), %dx )
21822 leal 2(%esi), %esi
21823 -DST( movw %dx, (%edi) )
21824 +DST( movw %dx, %es:(%edi) )
21825 leal 2(%edi), %edi
21826 je 6f
21827 shll $16,%edx
21828 5:
21829 SRC( movb (%esi), %dl )
21830 -DST( movb %dl, (%edi) )
21831 +DST( movb %dl, %es:(%edi) )
21832 6: addl %edx, %eax
21833 adcl $0, %eax
21834 7:
21835 .section .fixup, "ax"
21836 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21837 - movl $-EFAULT, (%ebx)
21838 + movl $-EFAULT, %ss:(%ebx)
21839 # zero the complete destination (computing the rest is too much work)
21840 movl ARGBASE+8(%esp),%edi # dst
21841 movl ARGBASE+12(%esp),%ecx # len
21842 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21843 rep; stosb
21844 jmp 7b
21845 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21846 - movl $-EFAULT, (%ebx)
21847 + movl $-EFAULT, %ss:(%ebx)
21848 jmp 7b
21849 .previous
21850
21851 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21852 + pushl_cfi %ss
21853 + popl_cfi %ds
21854 + pushl_cfi %ss
21855 + popl_cfi %es
21856 +#endif
21857 +
21858 popl_cfi %esi
21859 CFI_RESTORE esi
21860 popl_cfi %edi
21861 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21862 CFI_RESTORE ebx
21863 ret
21864 CFI_ENDPROC
21865 -ENDPROC(csum_partial_copy_generic)
21866 +ENDPROC(csum_partial_copy_generic_to_user)
21867
21868 #undef ROUND
21869 #undef ROUND1
21870 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21871 index f2145cf..cea889d 100644
21872 --- a/arch/x86/lib/clear_page_64.S
21873 +++ b/arch/x86/lib/clear_page_64.S
21874 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21875 movl $4096/8,%ecx
21876 xorl %eax,%eax
21877 rep stosq
21878 + pax_force_retaddr
21879 ret
21880 CFI_ENDPROC
21881 ENDPROC(clear_page_c)
21882 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21883 movl $4096,%ecx
21884 xorl %eax,%eax
21885 rep stosb
21886 + pax_force_retaddr
21887 ret
21888 CFI_ENDPROC
21889 ENDPROC(clear_page_c_e)
21890 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21891 leaq 64(%rdi),%rdi
21892 jnz .Lloop
21893 nop
21894 + pax_force_retaddr
21895 ret
21896 CFI_ENDPROC
21897 .Lclear_page_end:
21898 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21899
21900 #include <asm/cpufeature.h>
21901
21902 - .section .altinstr_replacement,"ax"
21903 + .section .altinstr_replacement,"a"
21904 1: .byte 0xeb /* jmp <disp8> */
21905 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21906 2: .byte 0xeb /* jmp <disp8> */
21907 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21908 index 1e572c5..2a162cd 100644
21909 --- a/arch/x86/lib/cmpxchg16b_emu.S
21910 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21911 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21912
21913 popf
21914 mov $1, %al
21915 + pax_force_retaddr
21916 ret
21917
21918 not_same:
21919 popf
21920 xor %al,%al
21921 + pax_force_retaddr
21922 ret
21923
21924 CFI_ENDPROC
21925 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21926 index 01c805b..dccb07f 100644
21927 --- a/arch/x86/lib/copy_page_64.S
21928 +++ b/arch/x86/lib/copy_page_64.S
21929 @@ -9,6 +9,7 @@ copy_page_c:
21930 CFI_STARTPROC
21931 movl $4096/8,%ecx
21932 rep movsq
21933 + pax_force_retaddr
21934 ret
21935 CFI_ENDPROC
21936 ENDPROC(copy_page_c)
21937 @@ -39,7 +40,7 @@ ENTRY(copy_page)
21938 movq 16 (%rsi), %rdx
21939 movq 24 (%rsi), %r8
21940 movq 32 (%rsi), %r9
21941 - movq 40 (%rsi), %r10
21942 + movq 40 (%rsi), %r13
21943 movq 48 (%rsi), %r11
21944 movq 56 (%rsi), %r12
21945
21946 @@ -50,7 +51,7 @@ ENTRY(copy_page)
21947 movq %rdx, 16 (%rdi)
21948 movq %r8, 24 (%rdi)
21949 movq %r9, 32 (%rdi)
21950 - movq %r10, 40 (%rdi)
21951 + movq %r13, 40 (%rdi)
21952 movq %r11, 48 (%rdi)
21953 movq %r12, 56 (%rdi)
21954
21955 @@ -69,7 +70,7 @@ ENTRY(copy_page)
21956 movq 16 (%rsi), %rdx
21957 movq 24 (%rsi), %r8
21958 movq 32 (%rsi), %r9
21959 - movq 40 (%rsi), %r10
21960 + movq 40 (%rsi), %r13
21961 movq 48 (%rsi), %r11
21962 movq 56 (%rsi), %r12
21963
21964 @@ -78,7 +79,7 @@ ENTRY(copy_page)
21965 movq %rdx, 16 (%rdi)
21966 movq %r8, 24 (%rdi)
21967 movq %r9, 32 (%rdi)
21968 - movq %r10, 40 (%rdi)
21969 + movq %r13, 40 (%rdi)
21970 movq %r11, 48 (%rdi)
21971 movq %r12, 56 (%rdi)
21972
21973 @@ -95,6 +96,7 @@ ENTRY(copy_page)
21974 CFI_RESTORE r13
21975 addq $3*8,%rsp
21976 CFI_ADJUST_CFA_OFFSET -3*8
21977 + pax_force_retaddr
21978 ret
21979 .Lcopy_page_end:
21980 CFI_ENDPROC
21981 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
21982
21983 #include <asm/cpufeature.h>
21984
21985 - .section .altinstr_replacement,"ax"
21986 + .section .altinstr_replacement,"a"
21987 1: .byte 0xeb /* jmp <disp8> */
21988 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21989 2:
21990 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21991 index 0248402..821c786 100644
21992 --- a/arch/x86/lib/copy_user_64.S
21993 +++ b/arch/x86/lib/copy_user_64.S
21994 @@ -16,6 +16,7 @@
21995 #include <asm/thread_info.h>
21996 #include <asm/cpufeature.h>
21997 #include <asm/alternative-asm.h>
21998 +#include <asm/pgtable.h>
21999
22000 /*
22001 * By placing feature2 after feature1 in altinstructions section, we logically
22002 @@ -29,7 +30,7 @@
22003 .byte 0xe9 /* 32bit jump */
22004 .long \orig-1f /* by default jump to orig */
22005 1:
22006 - .section .altinstr_replacement,"ax"
22007 + .section .altinstr_replacement,"a"
22008 2: .byte 0xe9 /* near jump with 32bit immediate */
22009 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
22010 3: .byte 0xe9 /* near jump with 32bit immediate */
22011 @@ -71,47 +72,20 @@
22012 #endif
22013 .endm
22014
22015 -/* Standard copy_to_user with segment limit checking */
22016 -ENTRY(_copy_to_user)
22017 - CFI_STARTPROC
22018 - GET_THREAD_INFO(%rax)
22019 - movq %rdi,%rcx
22020 - addq %rdx,%rcx
22021 - jc bad_to_user
22022 - cmpq TI_addr_limit(%rax),%rcx
22023 - ja bad_to_user
22024 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
22025 - copy_user_generic_unrolled,copy_user_generic_string, \
22026 - copy_user_enhanced_fast_string
22027 - CFI_ENDPROC
22028 -ENDPROC(_copy_to_user)
22029 -
22030 -/* Standard copy_from_user with segment limit checking */
22031 -ENTRY(_copy_from_user)
22032 - CFI_STARTPROC
22033 - GET_THREAD_INFO(%rax)
22034 - movq %rsi,%rcx
22035 - addq %rdx,%rcx
22036 - jc bad_from_user
22037 - cmpq TI_addr_limit(%rax),%rcx
22038 - ja bad_from_user
22039 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
22040 - copy_user_generic_unrolled,copy_user_generic_string, \
22041 - copy_user_enhanced_fast_string
22042 - CFI_ENDPROC
22043 -ENDPROC(_copy_from_user)
22044 -
22045 .section .fixup,"ax"
22046 /* must zero dest */
22047 ENTRY(bad_from_user)
22048 bad_from_user:
22049 CFI_STARTPROC
22050 + testl %edx,%edx
22051 + js bad_to_user
22052 movl %edx,%ecx
22053 xorl %eax,%eax
22054 rep
22055 stosb
22056 bad_to_user:
22057 movl %edx,%eax
22058 + pax_force_retaddr
22059 ret
22060 CFI_ENDPROC
22061 ENDPROC(bad_from_user)
22062 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
22063 jz 17f
22064 1: movq (%rsi),%r8
22065 2: movq 1*8(%rsi),%r9
22066 -3: movq 2*8(%rsi),%r10
22067 +3: movq 2*8(%rsi),%rax
22068 4: movq 3*8(%rsi),%r11
22069 5: movq %r8,(%rdi)
22070 6: movq %r9,1*8(%rdi)
22071 -7: movq %r10,2*8(%rdi)
22072 +7: movq %rax,2*8(%rdi)
22073 8: movq %r11,3*8(%rdi)
22074 9: movq 4*8(%rsi),%r8
22075 10: movq 5*8(%rsi),%r9
22076 -11: movq 6*8(%rsi),%r10
22077 +11: movq 6*8(%rsi),%rax
22078 12: movq 7*8(%rsi),%r11
22079 13: movq %r8,4*8(%rdi)
22080 14: movq %r9,5*8(%rdi)
22081 -15: movq %r10,6*8(%rdi)
22082 +15: movq %rax,6*8(%rdi)
22083 16: movq %r11,7*8(%rdi)
22084 leaq 64(%rsi),%rsi
22085 leaq 64(%rdi),%rdi
22086 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
22087 decl %ecx
22088 jnz 21b
22089 23: xor %eax,%eax
22090 + pax_force_retaddr
22091 ret
22092
22093 .section .fixup,"ax"
22094 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
22095 3: rep
22096 movsb
22097 4: xorl %eax,%eax
22098 + pax_force_retaddr
22099 ret
22100
22101 .section .fixup,"ax"
22102 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
22103 1: rep
22104 movsb
22105 2: xorl %eax,%eax
22106 + pax_force_retaddr
22107 ret
22108
22109 .section .fixup,"ax"
22110 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
22111 index cb0c112..e3a6895 100644
22112 --- a/arch/x86/lib/copy_user_nocache_64.S
22113 +++ b/arch/x86/lib/copy_user_nocache_64.S
22114 @@ -8,12 +8,14 @@
22115
22116 #include <linux/linkage.h>
22117 #include <asm/dwarf2.h>
22118 +#include <asm/alternative-asm.h>
22119
22120 #define FIX_ALIGNMENT 1
22121
22122 #include <asm/current.h>
22123 #include <asm/asm-offsets.h>
22124 #include <asm/thread_info.h>
22125 +#include <asm/pgtable.h>
22126
22127 .macro ALIGN_DESTINATION
22128 #ifdef FIX_ALIGNMENT
22129 @@ -50,6 +52,15 @@
22130 */
22131 ENTRY(__copy_user_nocache)
22132 CFI_STARTPROC
22133 +
22134 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22135 + mov $PAX_USER_SHADOW_BASE,%rcx
22136 + cmp %rcx,%rsi
22137 + jae 1f
22138 + add %rcx,%rsi
22139 +1:
22140 +#endif
22141 +
22142 cmpl $8,%edx
22143 jb 20f /* less then 8 bytes, go to byte copy loop */
22144 ALIGN_DESTINATION
22145 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
22146 jz 17f
22147 1: movq (%rsi),%r8
22148 2: movq 1*8(%rsi),%r9
22149 -3: movq 2*8(%rsi),%r10
22150 +3: movq 2*8(%rsi),%rax
22151 4: movq 3*8(%rsi),%r11
22152 5: movnti %r8,(%rdi)
22153 6: movnti %r9,1*8(%rdi)
22154 -7: movnti %r10,2*8(%rdi)
22155 +7: movnti %rax,2*8(%rdi)
22156 8: movnti %r11,3*8(%rdi)
22157 9: movq 4*8(%rsi),%r8
22158 10: movq 5*8(%rsi),%r9
22159 -11: movq 6*8(%rsi),%r10
22160 +11: movq 6*8(%rsi),%rax
22161 12: movq 7*8(%rsi),%r11
22162 13: movnti %r8,4*8(%rdi)
22163 14: movnti %r9,5*8(%rdi)
22164 -15: movnti %r10,6*8(%rdi)
22165 +15: movnti %rax,6*8(%rdi)
22166 16: movnti %r11,7*8(%rdi)
22167 leaq 64(%rsi),%rsi
22168 leaq 64(%rdi),%rdi
22169 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
22170 jnz 21b
22171 23: xorl %eax,%eax
22172 sfence
22173 + pax_force_retaddr
22174 ret
22175
22176 .section .fixup,"ax"
22177 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
22178 index fb903b7..c92b7f7 100644
22179 --- a/arch/x86/lib/csum-copy_64.S
22180 +++ b/arch/x86/lib/csum-copy_64.S
22181 @@ -8,6 +8,7 @@
22182 #include <linux/linkage.h>
22183 #include <asm/dwarf2.h>
22184 #include <asm/errno.h>
22185 +#include <asm/alternative-asm.h>
22186
22187 /*
22188 * Checksum copy with exception handling.
22189 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
22190 CFI_RESTORE rbp
22191 addq $7*8, %rsp
22192 CFI_ADJUST_CFA_OFFSET -7*8
22193 + pax_force_retaddr 0, 1
22194 ret
22195 CFI_RESTORE_STATE
22196
22197 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
22198 index 459b58a..9570bc7 100644
22199 --- a/arch/x86/lib/csum-wrappers_64.c
22200 +++ b/arch/x86/lib/csum-wrappers_64.c
22201 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
22202 len -= 2;
22203 }
22204 }
22205 - isum = csum_partial_copy_generic((__force const void *)src,
22206 +
22207 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22208 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
22209 + src += PAX_USER_SHADOW_BASE;
22210 +#endif
22211 +
22212 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
22213 dst, len, isum, errp, NULL);
22214 if (unlikely(*errp))
22215 goto out_err;
22216 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
22217 }
22218
22219 *errp = 0;
22220 - return csum_partial_copy_generic(src, (void __force *)dst,
22221 +
22222 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22223 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
22224 + dst += PAX_USER_SHADOW_BASE;
22225 +#endif
22226 +
22227 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
22228 len, isum, NULL, errp);
22229 }
22230 EXPORT_SYMBOL(csum_partial_copy_to_user);
22231 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
22232 index 51f1504..ddac4c1 100644
22233 --- a/arch/x86/lib/getuser.S
22234 +++ b/arch/x86/lib/getuser.S
22235 @@ -33,15 +33,38 @@
22236 #include <asm/asm-offsets.h>
22237 #include <asm/thread_info.h>
22238 #include <asm/asm.h>
22239 +#include <asm/segment.h>
22240 +#include <asm/pgtable.h>
22241 +#include <asm/alternative-asm.h>
22242 +
22243 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22244 +#define __copyuser_seg gs;
22245 +#else
22246 +#define __copyuser_seg
22247 +#endif
22248
22249 .text
22250 ENTRY(__get_user_1)
22251 CFI_STARTPROC
22252 +
22253 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22254 GET_THREAD_INFO(%_ASM_DX)
22255 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22256 jae bad_get_user
22257 -1: movzb (%_ASM_AX),%edx
22258 +
22259 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22260 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22261 + cmp %_ASM_DX,%_ASM_AX
22262 + jae 1234f
22263 + add %_ASM_DX,%_ASM_AX
22264 +1234:
22265 +#endif
22266 +
22267 +#endif
22268 +
22269 +1: __copyuser_seg movzb (%_ASM_AX),%edx
22270 xor %eax,%eax
22271 + pax_force_retaddr
22272 ret
22273 CFI_ENDPROC
22274 ENDPROC(__get_user_1)
22275 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
22276 ENTRY(__get_user_2)
22277 CFI_STARTPROC
22278 add $1,%_ASM_AX
22279 +
22280 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22281 jc bad_get_user
22282 GET_THREAD_INFO(%_ASM_DX)
22283 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22284 jae bad_get_user
22285 -2: movzwl -1(%_ASM_AX),%edx
22286 +
22287 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22288 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22289 + cmp %_ASM_DX,%_ASM_AX
22290 + jae 1234f
22291 + add %_ASM_DX,%_ASM_AX
22292 +1234:
22293 +#endif
22294 +
22295 +#endif
22296 +
22297 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
22298 xor %eax,%eax
22299 + pax_force_retaddr
22300 ret
22301 CFI_ENDPROC
22302 ENDPROC(__get_user_2)
22303 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
22304 ENTRY(__get_user_4)
22305 CFI_STARTPROC
22306 add $3,%_ASM_AX
22307 +
22308 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22309 jc bad_get_user
22310 GET_THREAD_INFO(%_ASM_DX)
22311 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22312 jae bad_get_user
22313 -3: mov -3(%_ASM_AX),%edx
22314 +
22315 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22316 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22317 + cmp %_ASM_DX,%_ASM_AX
22318 + jae 1234f
22319 + add %_ASM_DX,%_ASM_AX
22320 +1234:
22321 +#endif
22322 +
22323 +#endif
22324 +
22325 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
22326 xor %eax,%eax
22327 + pax_force_retaddr
22328 ret
22329 CFI_ENDPROC
22330 ENDPROC(__get_user_4)
22331 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
22332 GET_THREAD_INFO(%_ASM_DX)
22333 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22334 jae bad_get_user
22335 +
22336 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22337 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22338 + cmp %_ASM_DX,%_ASM_AX
22339 + jae 1234f
22340 + add %_ASM_DX,%_ASM_AX
22341 +1234:
22342 +#endif
22343 +
22344 4: movq -7(%_ASM_AX),%_ASM_DX
22345 xor %eax,%eax
22346 + pax_force_retaddr
22347 ret
22348 CFI_ENDPROC
22349 ENDPROC(__get_user_8)
22350 @@ -91,6 +152,7 @@ bad_get_user:
22351 CFI_STARTPROC
22352 xor %edx,%edx
22353 mov $(-EFAULT),%_ASM_AX
22354 + pax_force_retaddr
22355 ret
22356 CFI_ENDPROC
22357 END(bad_get_user)
22358 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
22359 index 5a1f9f3..ba9f577 100644
22360 --- a/arch/x86/lib/insn.c
22361 +++ b/arch/x86/lib/insn.c
22362 @@ -21,6 +21,11 @@
22363 #include <linux/string.h>
22364 #include <asm/inat.h>
22365 #include <asm/insn.h>
22366 +#ifdef __KERNEL__
22367 +#include <asm/pgtable_types.h>
22368 +#else
22369 +#define ktla_ktva(addr) addr
22370 +#endif
22371
22372 /* Verify next sizeof(t) bytes can be on the same instruction */
22373 #define validate_next(t, insn, n) \
22374 @@ -49,8 +54,8 @@
22375 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
22376 {
22377 memset(insn, 0, sizeof(*insn));
22378 - insn->kaddr = kaddr;
22379 - insn->next_byte = kaddr;
22380 + insn->kaddr = ktla_ktva(kaddr);
22381 + insn->next_byte = ktla_ktva(kaddr);
22382 insn->x86_64 = x86_64 ? 1 : 0;
22383 insn->opnd_bytes = 4;
22384 if (x86_64)
22385 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22386 index 05a95e7..326f2fa 100644
22387 --- a/arch/x86/lib/iomap_copy_64.S
22388 +++ b/arch/x86/lib/iomap_copy_64.S
22389 @@ -17,6 +17,7 @@
22390
22391 #include <linux/linkage.h>
22392 #include <asm/dwarf2.h>
22393 +#include <asm/alternative-asm.h>
22394
22395 /*
22396 * override generic version in lib/iomap_copy.c
22397 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22398 CFI_STARTPROC
22399 movl %edx,%ecx
22400 rep movsd
22401 + pax_force_retaddr
22402 ret
22403 CFI_ENDPROC
22404 ENDPROC(__iowrite32_copy)
22405 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22406 index efbf2a0..8893637 100644
22407 --- a/arch/x86/lib/memcpy_64.S
22408 +++ b/arch/x86/lib/memcpy_64.S
22409 @@ -34,6 +34,7 @@
22410 rep movsq
22411 movl %edx, %ecx
22412 rep movsb
22413 + pax_force_retaddr
22414 ret
22415 .Lmemcpy_e:
22416 .previous
22417 @@ -51,6 +52,7 @@
22418
22419 movl %edx, %ecx
22420 rep movsb
22421 + pax_force_retaddr
22422 ret
22423 .Lmemcpy_e_e:
22424 .previous
22425 @@ -81,13 +83,13 @@ ENTRY(memcpy)
22426 */
22427 movq 0*8(%rsi), %r8
22428 movq 1*8(%rsi), %r9
22429 - movq 2*8(%rsi), %r10
22430 + movq 2*8(%rsi), %rcx
22431 movq 3*8(%rsi), %r11
22432 leaq 4*8(%rsi), %rsi
22433
22434 movq %r8, 0*8(%rdi)
22435 movq %r9, 1*8(%rdi)
22436 - movq %r10, 2*8(%rdi)
22437 + movq %rcx, 2*8(%rdi)
22438 movq %r11, 3*8(%rdi)
22439 leaq 4*8(%rdi), %rdi
22440 jae .Lcopy_forward_loop
22441 @@ -110,12 +112,12 @@ ENTRY(memcpy)
22442 subq $0x20, %rdx
22443 movq -1*8(%rsi), %r8
22444 movq -2*8(%rsi), %r9
22445 - movq -3*8(%rsi), %r10
22446 + movq -3*8(%rsi), %rcx
22447 movq -4*8(%rsi), %r11
22448 leaq -4*8(%rsi), %rsi
22449 movq %r8, -1*8(%rdi)
22450 movq %r9, -2*8(%rdi)
22451 - movq %r10, -3*8(%rdi)
22452 + movq %rcx, -3*8(%rdi)
22453 movq %r11, -4*8(%rdi)
22454 leaq -4*8(%rdi), %rdi
22455 jae .Lcopy_backward_loop
22456 @@ -135,12 +137,13 @@ ENTRY(memcpy)
22457 */
22458 movq 0*8(%rsi), %r8
22459 movq 1*8(%rsi), %r9
22460 - movq -2*8(%rsi, %rdx), %r10
22461 + movq -2*8(%rsi, %rdx), %rcx
22462 movq -1*8(%rsi, %rdx), %r11
22463 movq %r8, 0*8(%rdi)
22464 movq %r9, 1*8(%rdi)
22465 - movq %r10, -2*8(%rdi, %rdx)
22466 + movq %rcx, -2*8(%rdi, %rdx)
22467 movq %r11, -1*8(%rdi, %rdx)
22468 + pax_force_retaddr
22469 retq
22470 .p2align 4
22471 .Lless_16bytes:
22472 @@ -153,6 +156,7 @@ ENTRY(memcpy)
22473 movq -1*8(%rsi, %rdx), %r9
22474 movq %r8, 0*8(%rdi)
22475 movq %r9, -1*8(%rdi, %rdx)
22476 + pax_force_retaddr
22477 retq
22478 .p2align 4
22479 .Lless_8bytes:
22480 @@ -166,6 +170,7 @@ ENTRY(memcpy)
22481 movl -4(%rsi, %rdx), %r8d
22482 movl %ecx, (%rdi)
22483 movl %r8d, -4(%rdi, %rdx)
22484 + pax_force_retaddr
22485 retq
22486 .p2align 4
22487 .Lless_3bytes:
22488 @@ -183,6 +188,7 @@ ENTRY(memcpy)
22489 jnz .Lloop_1
22490
22491 .Lend:
22492 + pax_force_retaddr
22493 retq
22494 CFI_ENDPROC
22495 ENDPROC(memcpy)
22496 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22497 index ee16461..c39c199 100644
22498 --- a/arch/x86/lib/memmove_64.S
22499 +++ b/arch/x86/lib/memmove_64.S
22500 @@ -61,13 +61,13 @@ ENTRY(memmove)
22501 5:
22502 sub $0x20, %rdx
22503 movq 0*8(%rsi), %r11
22504 - movq 1*8(%rsi), %r10
22505 + movq 1*8(%rsi), %rcx
22506 movq 2*8(%rsi), %r9
22507 movq 3*8(%rsi), %r8
22508 leaq 4*8(%rsi), %rsi
22509
22510 movq %r11, 0*8(%rdi)
22511 - movq %r10, 1*8(%rdi)
22512 + movq %rcx, 1*8(%rdi)
22513 movq %r9, 2*8(%rdi)
22514 movq %r8, 3*8(%rdi)
22515 leaq 4*8(%rdi), %rdi
22516 @@ -81,10 +81,10 @@ ENTRY(memmove)
22517 4:
22518 movq %rdx, %rcx
22519 movq -8(%rsi, %rdx), %r11
22520 - lea -8(%rdi, %rdx), %r10
22521 + lea -8(%rdi, %rdx), %r9
22522 shrq $3, %rcx
22523 rep movsq
22524 - movq %r11, (%r10)
22525 + movq %r11, (%r9)
22526 jmp 13f
22527 .Lmemmove_end_forward:
22528
22529 @@ -95,14 +95,14 @@ ENTRY(memmove)
22530 7:
22531 movq %rdx, %rcx
22532 movq (%rsi), %r11
22533 - movq %rdi, %r10
22534 + movq %rdi, %r9
22535 leaq -8(%rsi, %rdx), %rsi
22536 leaq -8(%rdi, %rdx), %rdi
22537 shrq $3, %rcx
22538 std
22539 rep movsq
22540 cld
22541 - movq %r11, (%r10)
22542 + movq %r11, (%r9)
22543 jmp 13f
22544
22545 /*
22546 @@ -127,13 +127,13 @@ ENTRY(memmove)
22547 8:
22548 subq $0x20, %rdx
22549 movq -1*8(%rsi), %r11
22550 - movq -2*8(%rsi), %r10
22551 + movq -2*8(%rsi), %rcx
22552 movq -3*8(%rsi), %r9
22553 movq -4*8(%rsi), %r8
22554 leaq -4*8(%rsi), %rsi
22555
22556 movq %r11, -1*8(%rdi)
22557 - movq %r10, -2*8(%rdi)
22558 + movq %rcx, -2*8(%rdi)
22559 movq %r9, -3*8(%rdi)
22560 movq %r8, -4*8(%rdi)
22561 leaq -4*8(%rdi), %rdi
22562 @@ -151,11 +151,11 @@ ENTRY(memmove)
22563 * Move data from 16 bytes to 31 bytes.
22564 */
22565 movq 0*8(%rsi), %r11
22566 - movq 1*8(%rsi), %r10
22567 + movq 1*8(%rsi), %rcx
22568 movq -2*8(%rsi, %rdx), %r9
22569 movq -1*8(%rsi, %rdx), %r8
22570 movq %r11, 0*8(%rdi)
22571 - movq %r10, 1*8(%rdi)
22572 + movq %rcx, 1*8(%rdi)
22573 movq %r9, -2*8(%rdi, %rdx)
22574 movq %r8, -1*8(%rdi, %rdx)
22575 jmp 13f
22576 @@ -167,9 +167,9 @@ ENTRY(memmove)
22577 * Move data from 8 bytes to 15 bytes.
22578 */
22579 movq 0*8(%rsi), %r11
22580 - movq -1*8(%rsi, %rdx), %r10
22581 + movq -1*8(%rsi, %rdx), %r9
22582 movq %r11, 0*8(%rdi)
22583 - movq %r10, -1*8(%rdi, %rdx)
22584 + movq %r9, -1*8(%rdi, %rdx)
22585 jmp 13f
22586 10:
22587 cmpq $4, %rdx
22588 @@ -178,9 +178,9 @@ ENTRY(memmove)
22589 * Move data from 4 bytes to 7 bytes.
22590 */
22591 movl (%rsi), %r11d
22592 - movl -4(%rsi, %rdx), %r10d
22593 + movl -4(%rsi, %rdx), %r9d
22594 movl %r11d, (%rdi)
22595 - movl %r10d, -4(%rdi, %rdx)
22596 + movl %r9d, -4(%rdi, %rdx)
22597 jmp 13f
22598 11:
22599 cmp $2, %rdx
22600 @@ -189,9 +189,9 @@ ENTRY(memmove)
22601 * Move data from 2 bytes to 3 bytes.
22602 */
22603 movw (%rsi), %r11w
22604 - movw -2(%rsi, %rdx), %r10w
22605 + movw -2(%rsi, %rdx), %r9w
22606 movw %r11w, (%rdi)
22607 - movw %r10w, -2(%rdi, %rdx)
22608 + movw %r9w, -2(%rdi, %rdx)
22609 jmp 13f
22610 12:
22611 cmp $1, %rdx
22612 @@ -202,6 +202,7 @@ ENTRY(memmove)
22613 movb (%rsi), %r11b
22614 movb %r11b, (%rdi)
22615 13:
22616 + pax_force_retaddr
22617 retq
22618 CFI_ENDPROC
22619
22620 @@ -210,6 +211,7 @@ ENTRY(memmove)
22621 /* Forward moving data. */
22622 movq %rdx, %rcx
22623 rep movsb
22624 + pax_force_retaddr
22625 retq
22626 .Lmemmove_end_forward_efs:
22627 .previous
22628 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22629 index 79bd454..dff325a 100644
22630 --- a/arch/x86/lib/memset_64.S
22631 +++ b/arch/x86/lib/memset_64.S
22632 @@ -31,6 +31,7 @@
22633 movl %r8d,%ecx
22634 rep stosb
22635 movq %r9,%rax
22636 + pax_force_retaddr
22637 ret
22638 .Lmemset_e:
22639 .previous
22640 @@ -53,6 +54,7 @@
22641 movl %edx,%ecx
22642 rep stosb
22643 movq %r9,%rax
22644 + pax_force_retaddr
22645 ret
22646 .Lmemset_e_e:
22647 .previous
22648 @@ -60,13 +62,13 @@
22649 ENTRY(memset)
22650 ENTRY(__memset)
22651 CFI_STARTPROC
22652 - movq %rdi,%r10
22653 movq %rdx,%r11
22654
22655 /* expand byte value */
22656 movzbl %sil,%ecx
22657 movabs $0x0101010101010101,%rax
22658 mul %rcx /* with rax, clobbers rdx */
22659 + movq %rdi,%rdx
22660
22661 /* align dst */
22662 movl %edi,%r9d
22663 @@ -120,7 +122,8 @@ ENTRY(__memset)
22664 jnz .Lloop_1
22665
22666 .Lende:
22667 - movq %r10,%rax
22668 + movq %rdx,%rax
22669 + pax_force_retaddr
22670 ret
22671
22672 CFI_RESTORE_STATE
22673 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22674 index c9f2d9b..e7fd2c0 100644
22675 --- a/arch/x86/lib/mmx_32.c
22676 +++ b/arch/x86/lib/mmx_32.c
22677 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22678 {
22679 void *p;
22680 int i;
22681 + unsigned long cr0;
22682
22683 if (unlikely(in_interrupt()))
22684 return __memcpy(to, from, len);
22685 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22686 kernel_fpu_begin();
22687
22688 __asm__ __volatile__ (
22689 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22690 - " prefetch 64(%0)\n"
22691 - " prefetch 128(%0)\n"
22692 - " prefetch 192(%0)\n"
22693 - " prefetch 256(%0)\n"
22694 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22695 + " prefetch 64(%1)\n"
22696 + " prefetch 128(%1)\n"
22697 + " prefetch 192(%1)\n"
22698 + " prefetch 256(%1)\n"
22699 "2: \n"
22700 ".section .fixup, \"ax\"\n"
22701 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22702 + "3: \n"
22703 +
22704 +#ifdef CONFIG_PAX_KERNEXEC
22705 + " movl %%cr0, %0\n"
22706 + " movl %0, %%eax\n"
22707 + " andl $0xFFFEFFFF, %%eax\n"
22708 + " movl %%eax, %%cr0\n"
22709 +#endif
22710 +
22711 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22712 +
22713 +#ifdef CONFIG_PAX_KERNEXEC
22714 + " movl %0, %%cr0\n"
22715 +#endif
22716 +
22717 " jmp 2b\n"
22718 ".previous\n"
22719 _ASM_EXTABLE(1b, 3b)
22720 - : : "r" (from));
22721 + : "=&r" (cr0) : "r" (from) : "ax");
22722
22723 for ( ; i > 5; i--) {
22724 __asm__ __volatile__ (
22725 - "1: prefetch 320(%0)\n"
22726 - "2: movq (%0), %%mm0\n"
22727 - " movq 8(%0), %%mm1\n"
22728 - " movq 16(%0), %%mm2\n"
22729 - " movq 24(%0), %%mm3\n"
22730 - " movq %%mm0, (%1)\n"
22731 - " movq %%mm1, 8(%1)\n"
22732 - " movq %%mm2, 16(%1)\n"
22733 - " movq %%mm3, 24(%1)\n"
22734 - " movq 32(%0), %%mm0\n"
22735 - " movq 40(%0), %%mm1\n"
22736 - " movq 48(%0), %%mm2\n"
22737 - " movq 56(%0), %%mm3\n"
22738 - " movq %%mm0, 32(%1)\n"
22739 - " movq %%mm1, 40(%1)\n"
22740 - " movq %%mm2, 48(%1)\n"
22741 - " movq %%mm3, 56(%1)\n"
22742 + "1: prefetch 320(%1)\n"
22743 + "2: movq (%1), %%mm0\n"
22744 + " movq 8(%1), %%mm1\n"
22745 + " movq 16(%1), %%mm2\n"
22746 + " movq 24(%1), %%mm3\n"
22747 + " movq %%mm0, (%2)\n"
22748 + " movq %%mm1, 8(%2)\n"
22749 + " movq %%mm2, 16(%2)\n"
22750 + " movq %%mm3, 24(%2)\n"
22751 + " movq 32(%1), %%mm0\n"
22752 + " movq 40(%1), %%mm1\n"
22753 + " movq 48(%1), %%mm2\n"
22754 + " movq 56(%1), %%mm3\n"
22755 + " movq %%mm0, 32(%2)\n"
22756 + " movq %%mm1, 40(%2)\n"
22757 + " movq %%mm2, 48(%2)\n"
22758 + " movq %%mm3, 56(%2)\n"
22759 ".section .fixup, \"ax\"\n"
22760 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22761 + "3:\n"
22762 +
22763 +#ifdef CONFIG_PAX_KERNEXEC
22764 + " movl %%cr0, %0\n"
22765 + " movl %0, %%eax\n"
22766 + " andl $0xFFFEFFFF, %%eax\n"
22767 + " movl %%eax, %%cr0\n"
22768 +#endif
22769 +
22770 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22771 +
22772 +#ifdef CONFIG_PAX_KERNEXEC
22773 + " movl %0, %%cr0\n"
22774 +#endif
22775 +
22776 " jmp 2b\n"
22777 ".previous\n"
22778 _ASM_EXTABLE(1b, 3b)
22779 - : : "r" (from), "r" (to) : "memory");
22780 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22781
22782 from += 64;
22783 to += 64;
22784 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22785 static void fast_copy_page(void *to, void *from)
22786 {
22787 int i;
22788 + unsigned long cr0;
22789
22790 kernel_fpu_begin();
22791
22792 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22793 * but that is for later. -AV
22794 */
22795 __asm__ __volatile__(
22796 - "1: prefetch (%0)\n"
22797 - " prefetch 64(%0)\n"
22798 - " prefetch 128(%0)\n"
22799 - " prefetch 192(%0)\n"
22800 - " prefetch 256(%0)\n"
22801 + "1: prefetch (%1)\n"
22802 + " prefetch 64(%1)\n"
22803 + " prefetch 128(%1)\n"
22804 + " prefetch 192(%1)\n"
22805 + " prefetch 256(%1)\n"
22806 "2: \n"
22807 ".section .fixup, \"ax\"\n"
22808 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22809 + "3: \n"
22810 +
22811 +#ifdef CONFIG_PAX_KERNEXEC
22812 + " movl %%cr0, %0\n"
22813 + " movl %0, %%eax\n"
22814 + " andl $0xFFFEFFFF, %%eax\n"
22815 + " movl %%eax, %%cr0\n"
22816 +#endif
22817 +
22818 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22819 +
22820 +#ifdef CONFIG_PAX_KERNEXEC
22821 + " movl %0, %%cr0\n"
22822 +#endif
22823 +
22824 " jmp 2b\n"
22825 ".previous\n"
22826 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22827 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22828
22829 for (i = 0; i < (4096-320)/64; i++) {
22830 __asm__ __volatile__ (
22831 - "1: prefetch 320(%0)\n"
22832 - "2: movq (%0), %%mm0\n"
22833 - " movntq %%mm0, (%1)\n"
22834 - " movq 8(%0), %%mm1\n"
22835 - " movntq %%mm1, 8(%1)\n"
22836 - " movq 16(%0), %%mm2\n"
22837 - " movntq %%mm2, 16(%1)\n"
22838 - " movq 24(%0), %%mm3\n"
22839 - " movntq %%mm3, 24(%1)\n"
22840 - " movq 32(%0), %%mm4\n"
22841 - " movntq %%mm4, 32(%1)\n"
22842 - " movq 40(%0), %%mm5\n"
22843 - " movntq %%mm5, 40(%1)\n"
22844 - " movq 48(%0), %%mm6\n"
22845 - " movntq %%mm6, 48(%1)\n"
22846 - " movq 56(%0), %%mm7\n"
22847 - " movntq %%mm7, 56(%1)\n"
22848 + "1: prefetch 320(%1)\n"
22849 + "2: movq (%1), %%mm0\n"
22850 + " movntq %%mm0, (%2)\n"
22851 + " movq 8(%1), %%mm1\n"
22852 + " movntq %%mm1, 8(%2)\n"
22853 + " movq 16(%1), %%mm2\n"
22854 + " movntq %%mm2, 16(%2)\n"
22855 + " movq 24(%1), %%mm3\n"
22856 + " movntq %%mm3, 24(%2)\n"
22857 + " movq 32(%1), %%mm4\n"
22858 + " movntq %%mm4, 32(%2)\n"
22859 + " movq 40(%1), %%mm5\n"
22860 + " movntq %%mm5, 40(%2)\n"
22861 + " movq 48(%1), %%mm6\n"
22862 + " movntq %%mm6, 48(%2)\n"
22863 + " movq 56(%1), %%mm7\n"
22864 + " movntq %%mm7, 56(%2)\n"
22865 ".section .fixup, \"ax\"\n"
22866 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22867 + "3:\n"
22868 +
22869 +#ifdef CONFIG_PAX_KERNEXEC
22870 + " movl %%cr0, %0\n"
22871 + " movl %0, %%eax\n"
22872 + " andl $0xFFFEFFFF, %%eax\n"
22873 + " movl %%eax, %%cr0\n"
22874 +#endif
22875 +
22876 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22877 +
22878 +#ifdef CONFIG_PAX_KERNEXEC
22879 + " movl %0, %%cr0\n"
22880 +#endif
22881 +
22882 " jmp 2b\n"
22883 ".previous\n"
22884 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22885 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22886
22887 from += 64;
22888 to += 64;
22889 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22890 static void fast_copy_page(void *to, void *from)
22891 {
22892 int i;
22893 + unsigned long cr0;
22894
22895 kernel_fpu_begin();
22896
22897 __asm__ __volatile__ (
22898 - "1: prefetch (%0)\n"
22899 - " prefetch 64(%0)\n"
22900 - " prefetch 128(%0)\n"
22901 - " prefetch 192(%0)\n"
22902 - " prefetch 256(%0)\n"
22903 + "1: prefetch (%1)\n"
22904 + " prefetch 64(%1)\n"
22905 + " prefetch 128(%1)\n"
22906 + " prefetch 192(%1)\n"
22907 + " prefetch 256(%1)\n"
22908 "2: \n"
22909 ".section .fixup, \"ax\"\n"
22910 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22911 + "3: \n"
22912 +
22913 +#ifdef CONFIG_PAX_KERNEXEC
22914 + " movl %%cr0, %0\n"
22915 + " movl %0, %%eax\n"
22916 + " andl $0xFFFEFFFF, %%eax\n"
22917 + " movl %%eax, %%cr0\n"
22918 +#endif
22919 +
22920 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22921 +
22922 +#ifdef CONFIG_PAX_KERNEXEC
22923 + " movl %0, %%cr0\n"
22924 +#endif
22925 +
22926 " jmp 2b\n"
22927 ".previous\n"
22928 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22929 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22930
22931 for (i = 0; i < 4096/64; i++) {
22932 __asm__ __volatile__ (
22933 - "1: prefetch 320(%0)\n"
22934 - "2: movq (%0), %%mm0\n"
22935 - " movq 8(%0), %%mm1\n"
22936 - " movq 16(%0), %%mm2\n"
22937 - " movq 24(%0), %%mm3\n"
22938 - " movq %%mm0, (%1)\n"
22939 - " movq %%mm1, 8(%1)\n"
22940 - " movq %%mm2, 16(%1)\n"
22941 - " movq %%mm3, 24(%1)\n"
22942 - " movq 32(%0), %%mm0\n"
22943 - " movq 40(%0), %%mm1\n"
22944 - " movq 48(%0), %%mm2\n"
22945 - " movq 56(%0), %%mm3\n"
22946 - " movq %%mm0, 32(%1)\n"
22947 - " movq %%mm1, 40(%1)\n"
22948 - " movq %%mm2, 48(%1)\n"
22949 - " movq %%mm3, 56(%1)\n"
22950 + "1: prefetch 320(%1)\n"
22951 + "2: movq (%1), %%mm0\n"
22952 + " movq 8(%1), %%mm1\n"
22953 + " movq 16(%1), %%mm2\n"
22954 + " movq 24(%1), %%mm3\n"
22955 + " movq %%mm0, (%2)\n"
22956 + " movq %%mm1, 8(%2)\n"
22957 + " movq %%mm2, 16(%2)\n"
22958 + " movq %%mm3, 24(%2)\n"
22959 + " movq 32(%1), %%mm0\n"
22960 + " movq 40(%1), %%mm1\n"
22961 + " movq 48(%1), %%mm2\n"
22962 + " movq 56(%1), %%mm3\n"
22963 + " movq %%mm0, 32(%2)\n"
22964 + " movq %%mm1, 40(%2)\n"
22965 + " movq %%mm2, 48(%2)\n"
22966 + " movq %%mm3, 56(%2)\n"
22967 ".section .fixup, \"ax\"\n"
22968 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22969 + "3:\n"
22970 +
22971 +#ifdef CONFIG_PAX_KERNEXEC
22972 + " movl %%cr0, %0\n"
22973 + " movl %0, %%eax\n"
22974 + " andl $0xFFFEFFFF, %%eax\n"
22975 + " movl %%eax, %%cr0\n"
22976 +#endif
22977 +
22978 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22979 +
22980 +#ifdef CONFIG_PAX_KERNEXEC
22981 + " movl %0, %%cr0\n"
22982 +#endif
22983 +
22984 " jmp 2b\n"
22985 ".previous\n"
22986 _ASM_EXTABLE(1b, 3b)
22987 - : : "r" (from), "r" (to) : "memory");
22988 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22989
22990 from += 64;
22991 to += 64;
22992 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22993 index 69fa106..adda88b 100644
22994 --- a/arch/x86/lib/msr-reg.S
22995 +++ b/arch/x86/lib/msr-reg.S
22996 @@ -3,6 +3,7 @@
22997 #include <asm/dwarf2.h>
22998 #include <asm/asm.h>
22999 #include <asm/msr.h>
23000 +#include <asm/alternative-asm.h>
23001
23002 #ifdef CONFIG_X86_64
23003 /*
23004 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
23005 CFI_STARTPROC
23006 pushq_cfi %rbx
23007 pushq_cfi %rbp
23008 - movq %rdi, %r10 /* Save pointer */
23009 + movq %rdi, %r9 /* Save pointer */
23010 xorl %r11d, %r11d /* Return value */
23011 movl (%rdi), %eax
23012 movl 4(%rdi), %ecx
23013 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
23014 movl 28(%rdi), %edi
23015 CFI_REMEMBER_STATE
23016 1: \op
23017 -2: movl %eax, (%r10)
23018 +2: movl %eax, (%r9)
23019 movl %r11d, %eax /* Return value */
23020 - movl %ecx, 4(%r10)
23021 - movl %edx, 8(%r10)
23022 - movl %ebx, 12(%r10)
23023 - movl %ebp, 20(%r10)
23024 - movl %esi, 24(%r10)
23025 - movl %edi, 28(%r10)
23026 + movl %ecx, 4(%r9)
23027 + movl %edx, 8(%r9)
23028 + movl %ebx, 12(%r9)
23029 + movl %ebp, 20(%r9)
23030 + movl %esi, 24(%r9)
23031 + movl %edi, 28(%r9)
23032 popq_cfi %rbp
23033 popq_cfi %rbx
23034 + pax_force_retaddr
23035 ret
23036 3:
23037 CFI_RESTORE_STATE
23038 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
23039 index 36b0d15..d381858 100644
23040 --- a/arch/x86/lib/putuser.S
23041 +++ b/arch/x86/lib/putuser.S
23042 @@ -15,7 +15,9 @@
23043 #include <asm/thread_info.h>
23044 #include <asm/errno.h>
23045 #include <asm/asm.h>
23046 -
23047 +#include <asm/segment.h>
23048 +#include <asm/pgtable.h>
23049 +#include <asm/alternative-asm.h>
23050
23051 /*
23052 * __put_user_X
23053 @@ -29,52 +31,119 @@
23054 * as they get called from within inline assembly.
23055 */
23056
23057 -#define ENTER CFI_STARTPROC ; \
23058 - GET_THREAD_INFO(%_ASM_BX)
23059 -#define EXIT ret ; \
23060 +#define ENTER CFI_STARTPROC
23061 +#define EXIT pax_force_retaddr; ret ; \
23062 CFI_ENDPROC
23063
23064 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23065 +#define _DEST %_ASM_CX,%_ASM_BX
23066 +#else
23067 +#define _DEST %_ASM_CX
23068 +#endif
23069 +
23070 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23071 +#define __copyuser_seg gs;
23072 +#else
23073 +#define __copyuser_seg
23074 +#endif
23075 +
23076 .text
23077 ENTRY(__put_user_1)
23078 ENTER
23079 +
23080 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23081 + GET_THREAD_INFO(%_ASM_BX)
23082 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
23083 jae bad_put_user
23084 -1: movb %al,(%_ASM_CX)
23085 +
23086 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23087 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23088 + cmp %_ASM_BX,%_ASM_CX
23089 + jb 1234f
23090 + xor %ebx,%ebx
23091 +1234:
23092 +#endif
23093 +
23094 +#endif
23095 +
23096 +1: __copyuser_seg movb %al,(_DEST)
23097 xor %eax,%eax
23098 EXIT
23099 ENDPROC(__put_user_1)
23100
23101 ENTRY(__put_user_2)
23102 ENTER
23103 +
23104 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23105 + GET_THREAD_INFO(%_ASM_BX)
23106 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
23107 sub $1,%_ASM_BX
23108 cmp %_ASM_BX,%_ASM_CX
23109 jae bad_put_user
23110 -2: movw %ax,(%_ASM_CX)
23111 +
23112 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23113 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23114 + cmp %_ASM_BX,%_ASM_CX
23115 + jb 1234f
23116 + xor %ebx,%ebx
23117 +1234:
23118 +#endif
23119 +
23120 +#endif
23121 +
23122 +2: __copyuser_seg movw %ax,(_DEST)
23123 xor %eax,%eax
23124 EXIT
23125 ENDPROC(__put_user_2)
23126
23127 ENTRY(__put_user_4)
23128 ENTER
23129 +
23130 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23131 + GET_THREAD_INFO(%_ASM_BX)
23132 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
23133 sub $3,%_ASM_BX
23134 cmp %_ASM_BX,%_ASM_CX
23135 jae bad_put_user
23136 -3: movl %eax,(%_ASM_CX)
23137 +
23138 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23139 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23140 + cmp %_ASM_BX,%_ASM_CX
23141 + jb 1234f
23142 + xor %ebx,%ebx
23143 +1234:
23144 +#endif
23145 +
23146 +#endif
23147 +
23148 +3: __copyuser_seg movl %eax,(_DEST)
23149 xor %eax,%eax
23150 EXIT
23151 ENDPROC(__put_user_4)
23152
23153 ENTRY(__put_user_8)
23154 ENTER
23155 +
23156 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23157 + GET_THREAD_INFO(%_ASM_BX)
23158 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
23159 sub $7,%_ASM_BX
23160 cmp %_ASM_BX,%_ASM_CX
23161 jae bad_put_user
23162 -4: mov %_ASM_AX,(%_ASM_CX)
23163 +
23164 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23165 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
23166 + cmp %_ASM_BX,%_ASM_CX
23167 + jb 1234f
23168 + xor %ebx,%ebx
23169 +1234:
23170 +#endif
23171 +
23172 +#endif
23173 +
23174 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
23175 #ifdef CONFIG_X86_32
23176 -5: movl %edx,4(%_ASM_CX)
23177 +5: __copyuser_seg movl %edx,4(_DEST)
23178 #endif
23179 xor %eax,%eax
23180 EXIT
23181 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
23182 index 1cad221..de671ee 100644
23183 --- a/arch/x86/lib/rwlock.S
23184 +++ b/arch/x86/lib/rwlock.S
23185 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
23186 FRAME
23187 0: LOCK_PREFIX
23188 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
23189 +
23190 +#ifdef CONFIG_PAX_REFCOUNT
23191 + jno 1234f
23192 + LOCK_PREFIX
23193 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
23194 + int $4
23195 +1234:
23196 + _ASM_EXTABLE(1234b, 1234b)
23197 +#endif
23198 +
23199 1: rep; nop
23200 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
23201 jne 1b
23202 LOCK_PREFIX
23203 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
23204 +
23205 +#ifdef CONFIG_PAX_REFCOUNT
23206 + jno 1234f
23207 + LOCK_PREFIX
23208 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
23209 + int $4
23210 +1234:
23211 + _ASM_EXTABLE(1234b, 1234b)
23212 +#endif
23213 +
23214 jnz 0b
23215 ENDFRAME
23216 + pax_force_retaddr
23217 ret
23218 CFI_ENDPROC
23219 END(__write_lock_failed)
23220 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
23221 FRAME
23222 0: LOCK_PREFIX
23223 READ_LOCK_SIZE(inc) (%__lock_ptr)
23224 +
23225 +#ifdef CONFIG_PAX_REFCOUNT
23226 + jno 1234f
23227 + LOCK_PREFIX
23228 + READ_LOCK_SIZE(dec) (%__lock_ptr)
23229 + int $4
23230 +1234:
23231 + _ASM_EXTABLE(1234b, 1234b)
23232 +#endif
23233 +
23234 1: rep; nop
23235 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
23236 js 1b
23237 LOCK_PREFIX
23238 READ_LOCK_SIZE(dec) (%__lock_ptr)
23239 +
23240 +#ifdef CONFIG_PAX_REFCOUNT
23241 + jno 1234f
23242 + LOCK_PREFIX
23243 + READ_LOCK_SIZE(inc) (%__lock_ptr)
23244 + int $4
23245 +1234:
23246 + _ASM_EXTABLE(1234b, 1234b)
23247 +#endif
23248 +
23249 js 0b
23250 ENDFRAME
23251 + pax_force_retaddr
23252 ret
23253 CFI_ENDPROC
23254 END(__read_lock_failed)
23255 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
23256 index 5dff5f0..cadebf4 100644
23257 --- a/arch/x86/lib/rwsem.S
23258 +++ b/arch/x86/lib/rwsem.S
23259 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
23260 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
23261 CFI_RESTORE __ASM_REG(dx)
23262 restore_common_regs
23263 + pax_force_retaddr
23264 ret
23265 CFI_ENDPROC
23266 ENDPROC(call_rwsem_down_read_failed)
23267 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
23268 movq %rax,%rdi
23269 call rwsem_down_write_failed
23270 restore_common_regs
23271 + pax_force_retaddr
23272 ret
23273 CFI_ENDPROC
23274 ENDPROC(call_rwsem_down_write_failed)
23275 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
23276 movq %rax,%rdi
23277 call rwsem_wake
23278 restore_common_regs
23279 -1: ret
23280 +1: pax_force_retaddr
23281 + ret
23282 CFI_ENDPROC
23283 ENDPROC(call_rwsem_wake)
23284
23285 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
23286 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
23287 CFI_RESTORE __ASM_REG(dx)
23288 restore_common_regs
23289 + pax_force_retaddr
23290 ret
23291 CFI_ENDPROC
23292 ENDPROC(call_rwsem_downgrade_wake)
23293 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
23294 index a63efd6..ccecad8 100644
23295 --- a/arch/x86/lib/thunk_64.S
23296 +++ b/arch/x86/lib/thunk_64.S
23297 @@ -8,6 +8,7 @@
23298 #include <linux/linkage.h>
23299 #include <asm/dwarf2.h>
23300 #include <asm/calling.h>
23301 +#include <asm/alternative-asm.h>
23302
23303 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
23304 .macro THUNK name, func, put_ret_addr_in_rdi=0
23305 @@ -41,5 +42,6 @@
23306 SAVE_ARGS
23307 restore:
23308 RESTORE_ARGS
23309 + pax_force_retaddr
23310 ret
23311 CFI_ENDPROC
23312 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
23313 index e218d5d..a99a1eb 100644
23314 --- a/arch/x86/lib/usercopy_32.c
23315 +++ b/arch/x86/lib/usercopy_32.c
23316 @@ -43,7 +43,7 @@ do { \
23317 __asm__ __volatile__( \
23318 " testl %1,%1\n" \
23319 " jz 2f\n" \
23320 - "0: lodsb\n" \
23321 + "0: "__copyuser_seg"lodsb\n" \
23322 " stosb\n" \
23323 " testb %%al,%%al\n" \
23324 " jz 1f\n" \
23325 @@ -128,10 +128,12 @@ do { \
23326 int __d0; \
23327 might_fault(); \
23328 __asm__ __volatile__( \
23329 + __COPYUSER_SET_ES \
23330 "0: rep; stosl\n" \
23331 " movl %2,%0\n" \
23332 "1: rep; stosb\n" \
23333 "2:\n" \
23334 + __COPYUSER_RESTORE_ES \
23335 ".section .fixup,\"ax\"\n" \
23336 "3: lea 0(%2,%0,4),%0\n" \
23337 " jmp 2b\n" \
23338 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
23339 might_fault();
23340
23341 __asm__ __volatile__(
23342 + __COPYUSER_SET_ES
23343 " testl %0, %0\n"
23344 " jz 3f\n"
23345 " andl %0,%%ecx\n"
23346 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
23347 " subl %%ecx,%0\n"
23348 " addl %0,%%eax\n"
23349 "1:\n"
23350 + __COPYUSER_RESTORE_ES
23351 ".section .fixup,\"ax\"\n"
23352 "2: xorl %%eax,%%eax\n"
23353 " jmp 1b\n"
23354 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
23355
23356 #ifdef CONFIG_X86_INTEL_USERCOPY
23357 static unsigned long
23358 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
23359 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
23360 {
23361 int d0, d1;
23362 __asm__ __volatile__(
23363 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23364 " .align 2,0x90\n"
23365 "3: movl 0(%4), %%eax\n"
23366 "4: movl 4(%4), %%edx\n"
23367 - "5: movl %%eax, 0(%3)\n"
23368 - "6: movl %%edx, 4(%3)\n"
23369 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
23370 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
23371 "7: movl 8(%4), %%eax\n"
23372 "8: movl 12(%4),%%edx\n"
23373 - "9: movl %%eax, 8(%3)\n"
23374 - "10: movl %%edx, 12(%3)\n"
23375 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
23376 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
23377 "11: movl 16(%4), %%eax\n"
23378 "12: movl 20(%4), %%edx\n"
23379 - "13: movl %%eax, 16(%3)\n"
23380 - "14: movl %%edx, 20(%3)\n"
23381 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
23382 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
23383 "15: movl 24(%4), %%eax\n"
23384 "16: movl 28(%4), %%edx\n"
23385 - "17: movl %%eax, 24(%3)\n"
23386 - "18: movl %%edx, 28(%3)\n"
23387 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23388 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23389 "19: movl 32(%4), %%eax\n"
23390 "20: movl 36(%4), %%edx\n"
23391 - "21: movl %%eax, 32(%3)\n"
23392 - "22: movl %%edx, 36(%3)\n"
23393 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23394 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23395 "23: movl 40(%4), %%eax\n"
23396 "24: movl 44(%4), %%edx\n"
23397 - "25: movl %%eax, 40(%3)\n"
23398 - "26: movl %%edx, 44(%3)\n"
23399 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23400 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23401 "27: movl 48(%4), %%eax\n"
23402 "28: movl 52(%4), %%edx\n"
23403 - "29: movl %%eax, 48(%3)\n"
23404 - "30: movl %%edx, 52(%3)\n"
23405 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23406 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23407 "31: movl 56(%4), %%eax\n"
23408 "32: movl 60(%4), %%edx\n"
23409 - "33: movl %%eax, 56(%3)\n"
23410 - "34: movl %%edx, 60(%3)\n"
23411 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23412 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23413 " addl $-64, %0\n"
23414 " addl $64, %4\n"
23415 " addl $64, %3\n"
23416 @@ -278,10 +282,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23417 " shrl $2, %0\n"
23418 " andl $3, %%eax\n"
23419 " cld\n"
23420 + __COPYUSER_SET_ES
23421 "99: rep; movsl\n"
23422 "36: movl %%eax, %0\n"
23423 "37: rep; movsb\n"
23424 "100:\n"
23425 + __COPYUSER_RESTORE_ES
23426 ".section .fixup,\"ax\"\n"
23427 "101: lea 0(%%eax,%0,4),%0\n"
23428 " jmp 100b\n"
23429 @@ -334,46 +340,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23430 }
23431
23432 static unsigned long
23433 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23434 +{
23435 + int d0, d1;
23436 + __asm__ __volatile__(
23437 + " .align 2,0x90\n"
23438 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23439 + " cmpl $67, %0\n"
23440 + " jbe 3f\n"
23441 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23442 + " .align 2,0x90\n"
23443 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23444 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23445 + "5: movl %%eax, 0(%3)\n"
23446 + "6: movl %%edx, 4(%3)\n"
23447 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23448 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23449 + "9: movl %%eax, 8(%3)\n"
23450 + "10: movl %%edx, 12(%3)\n"
23451 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23452 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23453 + "13: movl %%eax, 16(%3)\n"
23454 + "14: movl %%edx, 20(%3)\n"
23455 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23456 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23457 + "17: movl %%eax, 24(%3)\n"
23458 + "18: movl %%edx, 28(%3)\n"
23459 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23460 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23461 + "21: movl %%eax, 32(%3)\n"
23462 + "22: movl %%edx, 36(%3)\n"
23463 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23464 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23465 + "25: movl %%eax, 40(%3)\n"
23466 + "26: movl %%edx, 44(%3)\n"
23467 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23468 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23469 + "29: movl %%eax, 48(%3)\n"
23470 + "30: movl %%edx, 52(%3)\n"
23471 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23472 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23473 + "33: movl %%eax, 56(%3)\n"
23474 + "34: movl %%edx, 60(%3)\n"
23475 + " addl $-64, %0\n"
23476 + " addl $64, %4\n"
23477 + " addl $64, %3\n"
23478 + " cmpl $63, %0\n"
23479 + " ja 1b\n"
23480 + "35: movl %0, %%eax\n"
23481 + " shrl $2, %0\n"
23482 + " andl $3, %%eax\n"
23483 + " cld\n"
23484 + "99: rep; "__copyuser_seg" movsl\n"
23485 + "36: movl %%eax, %0\n"
23486 + "37: rep; "__copyuser_seg" movsb\n"
23487 + "100:\n"
23488 + ".section .fixup,\"ax\"\n"
23489 + "101: lea 0(%%eax,%0,4),%0\n"
23490 + " jmp 100b\n"
23491 + ".previous\n"
23492 + ".section __ex_table,\"a\"\n"
23493 + " .align 4\n"
23494 + " .long 1b,100b\n"
23495 + " .long 2b,100b\n"
23496 + " .long 3b,100b\n"
23497 + " .long 4b,100b\n"
23498 + " .long 5b,100b\n"
23499 + " .long 6b,100b\n"
23500 + " .long 7b,100b\n"
23501 + " .long 8b,100b\n"
23502 + " .long 9b,100b\n"
23503 + " .long 10b,100b\n"
23504 + " .long 11b,100b\n"
23505 + " .long 12b,100b\n"
23506 + " .long 13b,100b\n"
23507 + " .long 14b,100b\n"
23508 + " .long 15b,100b\n"
23509 + " .long 16b,100b\n"
23510 + " .long 17b,100b\n"
23511 + " .long 18b,100b\n"
23512 + " .long 19b,100b\n"
23513 + " .long 20b,100b\n"
23514 + " .long 21b,100b\n"
23515 + " .long 22b,100b\n"
23516 + " .long 23b,100b\n"
23517 + " .long 24b,100b\n"
23518 + " .long 25b,100b\n"
23519 + " .long 26b,100b\n"
23520 + " .long 27b,100b\n"
23521 + " .long 28b,100b\n"
23522 + " .long 29b,100b\n"
23523 + " .long 30b,100b\n"
23524 + " .long 31b,100b\n"
23525 + " .long 32b,100b\n"
23526 + " .long 33b,100b\n"
23527 + " .long 34b,100b\n"
23528 + " .long 35b,100b\n"
23529 + " .long 36b,100b\n"
23530 + " .long 37b,100b\n"
23531 + " .long 99b,101b\n"
23532 + ".previous"
23533 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23534 + : "1"(to), "2"(from), "0"(size)
23535 + : "eax", "edx", "memory");
23536 + return size;
23537 +}
23538 +
23539 +static unsigned long
23540 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
23541 +static unsigned long
23542 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23543 {
23544 int d0, d1;
23545 __asm__ __volatile__(
23546 " .align 2,0x90\n"
23547 - "0: movl 32(%4), %%eax\n"
23548 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23549 " cmpl $67, %0\n"
23550 " jbe 2f\n"
23551 - "1: movl 64(%4), %%eax\n"
23552 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23553 " .align 2,0x90\n"
23554 - "2: movl 0(%4), %%eax\n"
23555 - "21: movl 4(%4), %%edx\n"
23556 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23557 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23558 " movl %%eax, 0(%3)\n"
23559 " movl %%edx, 4(%3)\n"
23560 - "3: movl 8(%4), %%eax\n"
23561 - "31: movl 12(%4),%%edx\n"
23562 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23563 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23564 " movl %%eax, 8(%3)\n"
23565 " movl %%edx, 12(%3)\n"
23566 - "4: movl 16(%4), %%eax\n"
23567 - "41: movl 20(%4), %%edx\n"
23568 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23569 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23570 " movl %%eax, 16(%3)\n"
23571 " movl %%edx, 20(%3)\n"
23572 - "10: movl 24(%4), %%eax\n"
23573 - "51: movl 28(%4), %%edx\n"
23574 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23575 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23576 " movl %%eax, 24(%3)\n"
23577 " movl %%edx, 28(%3)\n"
23578 - "11: movl 32(%4), %%eax\n"
23579 - "61: movl 36(%4), %%edx\n"
23580 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23581 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23582 " movl %%eax, 32(%3)\n"
23583 " movl %%edx, 36(%3)\n"
23584 - "12: movl 40(%4), %%eax\n"
23585 - "71: movl 44(%4), %%edx\n"
23586 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23587 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23588 " movl %%eax, 40(%3)\n"
23589 " movl %%edx, 44(%3)\n"
23590 - "13: movl 48(%4), %%eax\n"
23591 - "81: movl 52(%4), %%edx\n"
23592 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23593 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23594 " movl %%eax, 48(%3)\n"
23595 " movl %%edx, 52(%3)\n"
23596 - "14: movl 56(%4), %%eax\n"
23597 - "91: movl 60(%4), %%edx\n"
23598 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23599 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23600 " movl %%eax, 56(%3)\n"
23601 " movl %%edx, 60(%3)\n"
23602 " addl $-64, %0\n"
23603 @@ -385,9 +500,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23604 " shrl $2, %0\n"
23605 " andl $3, %%eax\n"
23606 " cld\n"
23607 - "6: rep; movsl\n"
23608 + "6: rep; "__copyuser_seg" movsl\n"
23609 " movl %%eax,%0\n"
23610 - "7: rep; movsb\n"
23611 + "7: rep; "__copyuser_seg" movsb\n"
23612 "8:\n"
23613 ".section .fixup,\"ax\"\n"
23614 "9: lea 0(%%eax,%0,4),%0\n"
23615 @@ -434,47 +549,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23616 */
23617
23618 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23619 + const void __user *from, unsigned long size) __size_overflow(3);
23620 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23621 const void __user *from, unsigned long size)
23622 {
23623 int d0, d1;
23624
23625 __asm__ __volatile__(
23626 " .align 2,0x90\n"
23627 - "0: movl 32(%4), %%eax\n"
23628 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23629 " cmpl $67, %0\n"
23630 " jbe 2f\n"
23631 - "1: movl 64(%4), %%eax\n"
23632 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23633 " .align 2,0x90\n"
23634 - "2: movl 0(%4), %%eax\n"
23635 - "21: movl 4(%4), %%edx\n"
23636 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23637 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23638 " movnti %%eax, 0(%3)\n"
23639 " movnti %%edx, 4(%3)\n"
23640 - "3: movl 8(%4), %%eax\n"
23641 - "31: movl 12(%4),%%edx\n"
23642 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23643 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23644 " movnti %%eax, 8(%3)\n"
23645 " movnti %%edx, 12(%3)\n"
23646 - "4: movl 16(%4), %%eax\n"
23647 - "41: movl 20(%4), %%edx\n"
23648 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23649 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23650 " movnti %%eax, 16(%3)\n"
23651 " movnti %%edx, 20(%3)\n"
23652 - "10: movl 24(%4), %%eax\n"
23653 - "51: movl 28(%4), %%edx\n"
23654 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23655 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23656 " movnti %%eax, 24(%3)\n"
23657 " movnti %%edx, 28(%3)\n"
23658 - "11: movl 32(%4), %%eax\n"
23659 - "61: movl 36(%4), %%edx\n"
23660 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23661 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23662 " movnti %%eax, 32(%3)\n"
23663 " movnti %%edx, 36(%3)\n"
23664 - "12: movl 40(%4), %%eax\n"
23665 - "71: movl 44(%4), %%edx\n"
23666 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23667 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23668 " movnti %%eax, 40(%3)\n"
23669 " movnti %%edx, 44(%3)\n"
23670 - "13: movl 48(%4), %%eax\n"
23671 - "81: movl 52(%4), %%edx\n"
23672 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23673 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23674 " movnti %%eax, 48(%3)\n"
23675 " movnti %%edx, 52(%3)\n"
23676 - "14: movl 56(%4), %%eax\n"
23677 - "91: movl 60(%4), %%edx\n"
23678 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23679 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23680 " movnti %%eax, 56(%3)\n"
23681 " movnti %%edx, 60(%3)\n"
23682 " addl $-64, %0\n"
23683 @@ -487,9 +604,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23684 " shrl $2, %0\n"
23685 " andl $3, %%eax\n"
23686 " cld\n"
23687 - "6: rep; movsl\n"
23688 + "6: rep; "__copyuser_seg" movsl\n"
23689 " movl %%eax,%0\n"
23690 - "7: rep; movsb\n"
23691 + "7: rep; "__copyuser_seg" movsb\n"
23692 "8:\n"
23693 ".section .fixup,\"ax\"\n"
23694 "9: lea 0(%%eax,%0,4),%0\n"
23695 @@ -531,47 +648,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23696 }
23697
23698 static unsigned long __copy_user_intel_nocache(void *to,
23699 + const void __user *from, unsigned long size) __size_overflow(3);
23700 +static unsigned long __copy_user_intel_nocache(void *to,
23701 const void __user *from, unsigned long size)
23702 {
23703 int d0, d1;
23704
23705 __asm__ __volatile__(
23706 " .align 2,0x90\n"
23707 - "0: movl 32(%4), %%eax\n"
23708 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23709 " cmpl $67, %0\n"
23710 " jbe 2f\n"
23711 - "1: movl 64(%4), %%eax\n"
23712 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23713 " .align 2,0x90\n"
23714 - "2: movl 0(%4), %%eax\n"
23715 - "21: movl 4(%4), %%edx\n"
23716 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23717 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23718 " movnti %%eax, 0(%3)\n"
23719 " movnti %%edx, 4(%3)\n"
23720 - "3: movl 8(%4), %%eax\n"
23721 - "31: movl 12(%4),%%edx\n"
23722 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23723 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23724 " movnti %%eax, 8(%3)\n"
23725 " movnti %%edx, 12(%3)\n"
23726 - "4: movl 16(%4), %%eax\n"
23727 - "41: movl 20(%4), %%edx\n"
23728 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23729 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23730 " movnti %%eax, 16(%3)\n"
23731 " movnti %%edx, 20(%3)\n"
23732 - "10: movl 24(%4), %%eax\n"
23733 - "51: movl 28(%4), %%edx\n"
23734 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23735 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23736 " movnti %%eax, 24(%3)\n"
23737 " movnti %%edx, 28(%3)\n"
23738 - "11: movl 32(%4), %%eax\n"
23739 - "61: movl 36(%4), %%edx\n"
23740 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23741 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23742 " movnti %%eax, 32(%3)\n"
23743 " movnti %%edx, 36(%3)\n"
23744 - "12: movl 40(%4), %%eax\n"
23745 - "71: movl 44(%4), %%edx\n"
23746 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23747 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23748 " movnti %%eax, 40(%3)\n"
23749 " movnti %%edx, 44(%3)\n"
23750 - "13: movl 48(%4), %%eax\n"
23751 - "81: movl 52(%4), %%edx\n"
23752 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23753 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23754 " movnti %%eax, 48(%3)\n"
23755 " movnti %%edx, 52(%3)\n"
23756 - "14: movl 56(%4), %%eax\n"
23757 - "91: movl 60(%4), %%edx\n"
23758 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23759 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23760 " movnti %%eax, 56(%3)\n"
23761 " movnti %%edx, 60(%3)\n"
23762 " addl $-64, %0\n"
23763 @@ -584,9 +703,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23764 " shrl $2, %0\n"
23765 " andl $3, %%eax\n"
23766 " cld\n"
23767 - "6: rep; movsl\n"
23768 + "6: rep; "__copyuser_seg" movsl\n"
23769 " movl %%eax,%0\n"
23770 - "7: rep; movsb\n"
23771 + "7: rep; "__copyuser_seg" movsb\n"
23772 "8:\n"
23773 ".section .fixup,\"ax\"\n"
23774 "9: lea 0(%%eax,%0,4),%0\n"
23775 @@ -629,32 +748,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23776 */
23777 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23778 unsigned long size);
23779 -unsigned long __copy_user_intel(void __user *to, const void *from,
23780 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23781 + unsigned long size);
23782 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23783 unsigned long size);
23784 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23785 const void __user *from, unsigned long size);
23786 #endif /* CONFIG_X86_INTEL_USERCOPY */
23787
23788 /* Generic arbitrary sized copy. */
23789 -#define __copy_user(to, from, size) \
23790 +#define __copy_user(to, from, size, prefix, set, restore) \
23791 do { \
23792 int __d0, __d1, __d2; \
23793 __asm__ __volatile__( \
23794 + set \
23795 " cmp $7,%0\n" \
23796 " jbe 1f\n" \
23797 " movl %1,%0\n" \
23798 " negl %0\n" \
23799 " andl $7,%0\n" \
23800 " subl %0,%3\n" \
23801 - "4: rep; movsb\n" \
23802 + "4: rep; "prefix"movsb\n" \
23803 " movl %3,%0\n" \
23804 " shrl $2,%0\n" \
23805 " andl $3,%3\n" \
23806 " .align 2,0x90\n" \
23807 - "0: rep; movsl\n" \
23808 + "0: rep; "prefix"movsl\n" \
23809 " movl %3,%0\n" \
23810 - "1: rep; movsb\n" \
23811 + "1: rep; "prefix"movsb\n" \
23812 "2:\n" \
23813 + restore \
23814 ".section .fixup,\"ax\"\n" \
23815 "5: addl %3,%0\n" \
23816 " jmp 2b\n" \
23817 @@ -682,14 +805,14 @@ do { \
23818 " negl %0\n" \
23819 " andl $7,%0\n" \
23820 " subl %0,%3\n" \
23821 - "4: rep; movsb\n" \
23822 + "4: rep; "__copyuser_seg"movsb\n" \
23823 " movl %3,%0\n" \
23824 " shrl $2,%0\n" \
23825 " andl $3,%3\n" \
23826 " .align 2,0x90\n" \
23827 - "0: rep; movsl\n" \
23828 + "0: rep; "__copyuser_seg"movsl\n" \
23829 " movl %3,%0\n" \
23830 - "1: rep; movsb\n" \
23831 + "1: rep; "__copyuser_seg"movsb\n" \
23832 "2:\n" \
23833 ".section .fixup,\"ax\"\n" \
23834 "5: addl %3,%0\n" \
23835 @@ -775,9 +898,9 @@ survive:
23836 }
23837 #endif
23838 if (movsl_is_ok(to, from, n))
23839 - __copy_user(to, from, n);
23840 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23841 else
23842 - n = __copy_user_intel(to, from, n);
23843 + n = __generic_copy_to_user_intel(to, from, n);
23844 return n;
23845 }
23846 EXPORT_SYMBOL(__copy_to_user_ll);
23847 @@ -797,10 +920,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23848 unsigned long n)
23849 {
23850 if (movsl_is_ok(to, from, n))
23851 - __copy_user(to, from, n);
23852 + __copy_user(to, from, n, __copyuser_seg, "", "");
23853 else
23854 - n = __copy_user_intel((void __user *)to,
23855 - (const void *)from, n);
23856 + n = __generic_copy_from_user_intel(to, from, n);
23857 return n;
23858 }
23859 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23860 @@ -827,65 +949,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23861 if (n > 64 && cpu_has_xmm2)
23862 n = __copy_user_intel_nocache(to, from, n);
23863 else
23864 - __copy_user(to, from, n);
23865 + __copy_user(to, from, n, __copyuser_seg, "", "");
23866 #else
23867 - __copy_user(to, from, n);
23868 + __copy_user(to, from, n, __copyuser_seg, "", "");
23869 #endif
23870 return n;
23871 }
23872 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23873
23874 -/**
23875 - * copy_to_user: - Copy a block of data into user space.
23876 - * @to: Destination address, in user space.
23877 - * @from: Source address, in kernel space.
23878 - * @n: Number of bytes to copy.
23879 - *
23880 - * Context: User context only. This function may sleep.
23881 - *
23882 - * Copy data from kernel space to user space.
23883 - *
23884 - * Returns number of bytes that could not be copied.
23885 - * On success, this will be zero.
23886 - */
23887 -unsigned long
23888 -copy_to_user(void __user *to, const void *from, unsigned long n)
23889 -{
23890 - if (access_ok(VERIFY_WRITE, to, n))
23891 - n = __copy_to_user(to, from, n);
23892 - return n;
23893 -}
23894 -EXPORT_SYMBOL(copy_to_user);
23895 -
23896 -/**
23897 - * copy_from_user: - Copy a block of data from user space.
23898 - * @to: Destination address, in kernel space.
23899 - * @from: Source address, in user space.
23900 - * @n: Number of bytes to copy.
23901 - *
23902 - * Context: User context only. This function may sleep.
23903 - *
23904 - * Copy data from user space to kernel space.
23905 - *
23906 - * Returns number of bytes that could not be copied.
23907 - * On success, this will be zero.
23908 - *
23909 - * If some data could not be copied, this function will pad the copied
23910 - * data to the requested size using zero bytes.
23911 - */
23912 -unsigned long
23913 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23914 -{
23915 - if (access_ok(VERIFY_READ, from, n))
23916 - n = __copy_from_user(to, from, n);
23917 - else
23918 - memset(to, 0, n);
23919 - return n;
23920 -}
23921 -EXPORT_SYMBOL(_copy_from_user);
23922 -
23923 void copy_from_user_overflow(void)
23924 {
23925 WARN(1, "Buffer overflow detected!\n");
23926 }
23927 EXPORT_SYMBOL(copy_from_user_overflow);
23928 +
23929 +void copy_to_user_overflow(void)
23930 +{
23931 + WARN(1, "Buffer overflow detected!\n");
23932 +}
23933 +EXPORT_SYMBOL(copy_to_user_overflow);
23934 +
23935 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23936 +void __set_fs(mm_segment_t x)
23937 +{
23938 + switch (x.seg) {
23939 + case 0:
23940 + loadsegment(gs, 0);
23941 + break;
23942 + case TASK_SIZE_MAX:
23943 + loadsegment(gs, __USER_DS);
23944 + break;
23945 + case -1UL:
23946 + loadsegment(gs, __KERNEL_DS);
23947 + break;
23948 + default:
23949 + BUG();
23950 + }
23951 + return;
23952 +}
23953 +EXPORT_SYMBOL(__set_fs);
23954 +
23955 +void set_fs(mm_segment_t x)
23956 +{
23957 + current_thread_info()->addr_limit = x;
23958 + __set_fs(x);
23959 +}
23960 +EXPORT_SYMBOL(set_fs);
23961 +#endif
23962 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23963 index b7c2849..8633ad8 100644
23964 --- a/arch/x86/lib/usercopy_64.c
23965 +++ b/arch/x86/lib/usercopy_64.c
23966 @@ -42,6 +42,12 @@ long
23967 __strncpy_from_user(char *dst, const char __user *src, long count)
23968 {
23969 long res;
23970 +
23971 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23972 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23973 + src += PAX_USER_SHADOW_BASE;
23974 +#endif
23975 +
23976 __do_strncpy_from_user(dst, src, count, res);
23977 return res;
23978 }
23979 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23980 {
23981 long __d0;
23982 might_fault();
23983 +
23984 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23985 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23986 + addr += PAX_USER_SHADOW_BASE;
23987 +#endif
23988 +
23989 /* no memory constraint because it doesn't change any memory gcc knows
23990 about */
23991 asm volatile(
23992 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23993 }
23994 EXPORT_SYMBOL(strlen_user);
23995
23996 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23997 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23998 {
23999 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
24000 - return copy_user_generic((__force void *)to, (__force void *)from, len);
24001 - }
24002 - return len;
24003 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
24004 +
24005 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24006 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
24007 + to += PAX_USER_SHADOW_BASE;
24008 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
24009 + from += PAX_USER_SHADOW_BASE;
24010 +#endif
24011 +
24012 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
24013 + }
24014 + return len;
24015 }
24016 EXPORT_SYMBOL(copy_in_user);
24017
24018 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
24019 * it is not necessary to optimize tail handling.
24020 */
24021 unsigned long
24022 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
24023 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
24024 {
24025 char c;
24026 unsigned zero_len;
24027 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
24028 index 1fb85db..8b3540b 100644
24029 --- a/arch/x86/mm/extable.c
24030 +++ b/arch/x86/mm/extable.c
24031 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
24032 const struct exception_table_entry *fixup;
24033
24034 #ifdef CONFIG_PNPBIOS
24035 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
24036 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
24037 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
24038 extern u32 pnp_bios_is_utter_crap;
24039 pnp_bios_is_utter_crap = 1;
24040 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
24041 index f0b4caf..d92fd42 100644
24042 --- a/arch/x86/mm/fault.c
24043 +++ b/arch/x86/mm/fault.c
24044 @@ -13,11 +13,18 @@
24045 #include <linux/perf_event.h> /* perf_sw_event */
24046 #include <linux/hugetlb.h> /* hstate_index_to_shift */
24047 #include <linux/prefetch.h> /* prefetchw */
24048 +#include <linux/unistd.h>
24049 +#include <linux/compiler.h>
24050
24051 #include <asm/traps.h> /* dotraplinkage, ... */
24052 #include <asm/pgalloc.h> /* pgd_*(), ... */
24053 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
24054 #include <asm/fixmap.h> /* VSYSCALL_START */
24055 +#include <asm/tlbflush.h>
24056 +
24057 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24058 +#include <asm/stacktrace.h>
24059 +#endif
24060
24061 /*
24062 * Page fault error code bits:
24063 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
24064 int ret = 0;
24065
24066 /* kprobe_running() needs smp_processor_id() */
24067 - if (kprobes_built_in() && !user_mode_vm(regs)) {
24068 + if (kprobes_built_in() && !user_mode(regs)) {
24069 preempt_disable();
24070 if (kprobe_running() && kprobe_fault_handler(regs, 14))
24071 ret = 1;
24072 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
24073 return !instr_lo || (instr_lo>>1) == 1;
24074 case 0x00:
24075 /* Prefetch instruction is 0x0F0D or 0x0F18 */
24076 - if (probe_kernel_address(instr, opcode))
24077 + if (user_mode(regs)) {
24078 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
24079 + return 0;
24080 + } else if (probe_kernel_address(instr, opcode))
24081 return 0;
24082
24083 *prefetch = (instr_lo == 0xF) &&
24084 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
24085 while (instr < max_instr) {
24086 unsigned char opcode;
24087
24088 - if (probe_kernel_address(instr, opcode))
24089 + if (user_mode(regs)) {
24090 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
24091 + break;
24092 + } else if (probe_kernel_address(instr, opcode))
24093 break;
24094
24095 instr++;
24096 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
24097 force_sig_info(si_signo, &info, tsk);
24098 }
24099
24100 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24101 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
24102 +#endif
24103 +
24104 +#ifdef CONFIG_PAX_EMUTRAMP
24105 +static int pax_handle_fetch_fault(struct pt_regs *regs);
24106 +#endif
24107 +
24108 +#ifdef CONFIG_PAX_PAGEEXEC
24109 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
24110 +{
24111 + pgd_t *pgd;
24112 + pud_t *pud;
24113 + pmd_t *pmd;
24114 +
24115 + pgd = pgd_offset(mm, address);
24116 + if (!pgd_present(*pgd))
24117 + return NULL;
24118 + pud = pud_offset(pgd, address);
24119 + if (!pud_present(*pud))
24120 + return NULL;
24121 + pmd = pmd_offset(pud, address);
24122 + if (!pmd_present(*pmd))
24123 + return NULL;
24124 + return pmd;
24125 +}
24126 +#endif
24127 +
24128 DEFINE_SPINLOCK(pgd_lock);
24129 LIST_HEAD(pgd_list);
24130
24131 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
24132 for (address = VMALLOC_START & PMD_MASK;
24133 address >= TASK_SIZE && address < FIXADDR_TOP;
24134 address += PMD_SIZE) {
24135 +
24136 +#ifdef CONFIG_PAX_PER_CPU_PGD
24137 + unsigned long cpu;
24138 +#else
24139 struct page *page;
24140 +#endif
24141
24142 spin_lock(&pgd_lock);
24143 +
24144 +#ifdef CONFIG_PAX_PER_CPU_PGD
24145 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24146 + pgd_t *pgd = get_cpu_pgd(cpu);
24147 + pmd_t *ret;
24148 +#else
24149 list_for_each_entry(page, &pgd_list, lru) {
24150 + pgd_t *pgd = page_address(page);
24151 spinlock_t *pgt_lock;
24152 pmd_t *ret;
24153
24154 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
24155 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24156
24157 spin_lock(pgt_lock);
24158 - ret = vmalloc_sync_one(page_address(page), address);
24159 +#endif
24160 +
24161 + ret = vmalloc_sync_one(pgd, address);
24162 +
24163 +#ifndef CONFIG_PAX_PER_CPU_PGD
24164 spin_unlock(pgt_lock);
24165 +#endif
24166
24167 if (!ret)
24168 break;
24169 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
24170 * an interrupt in the middle of a task switch..
24171 */
24172 pgd_paddr = read_cr3();
24173 +
24174 +#ifdef CONFIG_PAX_PER_CPU_PGD
24175 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
24176 +#endif
24177 +
24178 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
24179 if (!pmd_k)
24180 return -1;
24181 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
24182 * happen within a race in page table update. In the later
24183 * case just flush:
24184 */
24185 +
24186 +#ifdef CONFIG_PAX_PER_CPU_PGD
24187 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
24188 + pgd = pgd_offset_cpu(smp_processor_id(), address);
24189 +#else
24190 pgd = pgd_offset(current->active_mm, address);
24191 +#endif
24192 +
24193 pgd_ref = pgd_offset_k(address);
24194 if (pgd_none(*pgd_ref))
24195 return -1;
24196 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
24197 static int is_errata100(struct pt_regs *regs, unsigned long address)
24198 {
24199 #ifdef CONFIG_X86_64
24200 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
24201 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
24202 return 1;
24203 #endif
24204 return 0;
24205 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
24206 }
24207
24208 static const char nx_warning[] = KERN_CRIT
24209 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
24210 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
24211
24212 static void
24213 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
24214 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
24215 if (!oops_may_print())
24216 return;
24217
24218 - if (error_code & PF_INSTR) {
24219 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
24220 unsigned int level;
24221
24222 pte_t *pte = lookup_address(address, &level);
24223
24224 if (pte && pte_present(*pte) && !pte_exec(*pte))
24225 - printk(nx_warning, current_uid());
24226 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
24227 }
24228
24229 +#ifdef CONFIG_PAX_KERNEXEC
24230 + if (init_mm.start_code <= address && address < init_mm.end_code) {
24231 + if (current->signal->curr_ip)
24232 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
24233 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
24234 + else
24235 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
24236 + current->comm, task_pid_nr(current), current_uid(), current_euid());
24237 + }
24238 +#endif
24239 +
24240 printk(KERN_ALERT "BUG: unable to handle kernel ");
24241 if (address < PAGE_SIZE)
24242 printk(KERN_CONT "NULL pointer dereference");
24243 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
24244 }
24245 #endif
24246
24247 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24248 + if (pax_is_fetch_fault(regs, error_code, address)) {
24249 +
24250 +#ifdef CONFIG_PAX_EMUTRAMP
24251 + switch (pax_handle_fetch_fault(regs)) {
24252 + case 2:
24253 + return;
24254 + }
24255 +#endif
24256 +
24257 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24258 + do_group_exit(SIGKILL);
24259 + }
24260 +#endif
24261 +
24262 if (unlikely(show_unhandled_signals))
24263 show_signal_msg(regs, error_code, address, tsk);
24264
24265 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
24266 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
24267 printk(KERN_ERR
24268 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
24269 - tsk->comm, tsk->pid, address);
24270 + tsk->comm, task_pid_nr(tsk), address);
24271 code = BUS_MCEERR_AR;
24272 }
24273 #endif
24274 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
24275 return 1;
24276 }
24277
24278 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24279 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
24280 +{
24281 + pte_t *pte;
24282 + pmd_t *pmd;
24283 + spinlock_t *ptl;
24284 + unsigned char pte_mask;
24285 +
24286 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
24287 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
24288 + return 0;
24289 +
24290 + /* PaX: it's our fault, let's handle it if we can */
24291 +
24292 + /* PaX: take a look at read faults before acquiring any locks */
24293 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
24294 + /* instruction fetch attempt from a protected page in user mode */
24295 + up_read(&mm->mmap_sem);
24296 +
24297 +#ifdef CONFIG_PAX_EMUTRAMP
24298 + switch (pax_handle_fetch_fault(regs)) {
24299 + case 2:
24300 + return 1;
24301 + }
24302 +#endif
24303 +
24304 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24305 + do_group_exit(SIGKILL);
24306 + }
24307 +
24308 + pmd = pax_get_pmd(mm, address);
24309 + if (unlikely(!pmd))
24310 + return 0;
24311 +
24312 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
24313 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
24314 + pte_unmap_unlock(pte, ptl);
24315 + return 0;
24316 + }
24317 +
24318 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
24319 + /* write attempt to a protected page in user mode */
24320 + pte_unmap_unlock(pte, ptl);
24321 + return 0;
24322 + }
24323 +
24324 +#ifdef CONFIG_SMP
24325 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
24326 +#else
24327 + if (likely(address > get_limit(regs->cs)))
24328 +#endif
24329 + {
24330 + set_pte(pte, pte_mkread(*pte));
24331 + __flush_tlb_one(address);
24332 + pte_unmap_unlock(pte, ptl);
24333 + up_read(&mm->mmap_sem);
24334 + return 1;
24335 + }
24336 +
24337 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
24338 +
24339 + /*
24340 + * PaX: fill DTLB with user rights and retry
24341 + */
24342 + __asm__ __volatile__ (
24343 + "orb %2,(%1)\n"
24344 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
24345 +/*
24346 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
24347 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
24348 + * page fault when examined during a TLB load attempt. this is true not only
24349 + * for PTEs holding a non-present entry but also present entries that will
24350 + * raise a page fault (such as those set up by PaX, or the copy-on-write
24351 + * mechanism). in effect it means that we do *not* need to flush the TLBs
24352 + * for our target pages since their PTEs are simply not in the TLBs at all.
24353 +
24354 + * the best thing in omitting it is that we gain around 15-20% speed in the
24355 + * fast path of the page fault handler and can get rid of tracing since we
24356 + * can no longer flush unintended entries.
24357 + */
24358 + "invlpg (%0)\n"
24359 +#endif
24360 + __copyuser_seg"testb $0,(%0)\n"
24361 + "xorb %3,(%1)\n"
24362 + :
24363 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24364 + : "memory", "cc");
24365 + pte_unmap_unlock(pte, ptl);
24366 + up_read(&mm->mmap_sem);
24367 + return 1;
24368 +}
24369 +#endif
24370 +
24371 /*
24372 * Handle a spurious fault caused by a stale TLB entry.
24373 *
24374 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
24375 static inline int
24376 access_error(unsigned long error_code, struct vm_area_struct *vma)
24377 {
24378 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24379 + return 1;
24380 +
24381 if (error_code & PF_WRITE) {
24382 /* write, present and write, not present: */
24383 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24384 @@ -1005,18 +1197,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24385 {
24386 struct vm_area_struct *vma;
24387 struct task_struct *tsk;
24388 - unsigned long address;
24389 struct mm_struct *mm;
24390 int fault;
24391 int write = error_code & PF_WRITE;
24392 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
24393 (write ? FAULT_FLAG_WRITE : 0);
24394
24395 - tsk = current;
24396 - mm = tsk->mm;
24397 -
24398 /* Get the faulting address: */
24399 - address = read_cr2();
24400 + unsigned long address = read_cr2();
24401 +
24402 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24403 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24404 + if (!search_exception_tables(regs->ip)) {
24405 + bad_area_nosemaphore(regs, error_code, address);
24406 + return;
24407 + }
24408 + if (address < PAX_USER_SHADOW_BASE) {
24409 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24410 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24411 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24412 + } else
24413 + address -= PAX_USER_SHADOW_BASE;
24414 + }
24415 +#endif
24416 +
24417 + tsk = current;
24418 + mm = tsk->mm;
24419
24420 /*
24421 * Detect and handle instructions that would cause a page fault for
24422 @@ -1077,7 +1283,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24423 * User-mode registers count as a user access even for any
24424 * potential system fault or CPU buglet:
24425 */
24426 - if (user_mode_vm(regs)) {
24427 + if (user_mode(regs)) {
24428 local_irq_enable();
24429 error_code |= PF_USER;
24430 } else {
24431 @@ -1132,6 +1338,11 @@ retry:
24432 might_sleep();
24433 }
24434
24435 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24436 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24437 + return;
24438 +#endif
24439 +
24440 vma = find_vma(mm, address);
24441 if (unlikely(!vma)) {
24442 bad_area(regs, error_code, address);
24443 @@ -1143,18 +1354,24 @@ retry:
24444 bad_area(regs, error_code, address);
24445 return;
24446 }
24447 - if (error_code & PF_USER) {
24448 - /*
24449 - * Accessing the stack below %sp is always a bug.
24450 - * The large cushion allows instructions like enter
24451 - * and pusha to work. ("enter $65535, $31" pushes
24452 - * 32 pointers and then decrements %sp by 65535.)
24453 - */
24454 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24455 - bad_area(regs, error_code, address);
24456 - return;
24457 - }
24458 + /*
24459 + * Accessing the stack below %sp is always a bug.
24460 + * The large cushion allows instructions like enter
24461 + * and pusha to work. ("enter $65535, $31" pushes
24462 + * 32 pointers and then decrements %sp by 65535.)
24463 + */
24464 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24465 + bad_area(regs, error_code, address);
24466 + return;
24467 }
24468 +
24469 +#ifdef CONFIG_PAX_SEGMEXEC
24470 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24471 + bad_area(regs, error_code, address);
24472 + return;
24473 + }
24474 +#endif
24475 +
24476 if (unlikely(expand_stack(vma, address))) {
24477 bad_area(regs, error_code, address);
24478 return;
24479 @@ -1209,3 +1426,292 @@ good_area:
24480
24481 up_read(&mm->mmap_sem);
24482 }
24483 +
24484 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24485 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24486 +{
24487 + struct mm_struct *mm = current->mm;
24488 + unsigned long ip = regs->ip;
24489 +
24490 + if (v8086_mode(regs))
24491 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24492 +
24493 +#ifdef CONFIG_PAX_PAGEEXEC
24494 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24495 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24496 + return true;
24497 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24498 + return true;
24499 + return false;
24500 + }
24501 +#endif
24502 +
24503 +#ifdef CONFIG_PAX_SEGMEXEC
24504 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24505 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24506 + return true;
24507 + return false;
24508 + }
24509 +#endif
24510 +
24511 + return false;
24512 +}
24513 +#endif
24514 +
24515 +#ifdef CONFIG_PAX_EMUTRAMP
24516 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24517 +{
24518 + int err;
24519 +
24520 + do { /* PaX: libffi trampoline emulation */
24521 + unsigned char mov, jmp;
24522 + unsigned int addr1, addr2;
24523 +
24524 +#ifdef CONFIG_X86_64
24525 + if ((regs->ip + 9) >> 32)
24526 + break;
24527 +#endif
24528 +
24529 + err = get_user(mov, (unsigned char __user *)regs->ip);
24530 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24531 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24532 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24533 +
24534 + if (err)
24535 + break;
24536 +
24537 + if (mov == 0xB8 && jmp == 0xE9) {
24538 + regs->ax = addr1;
24539 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24540 + return 2;
24541 + }
24542 + } while (0);
24543 +
24544 + do { /* PaX: gcc trampoline emulation #1 */
24545 + unsigned char mov1, mov2;
24546 + unsigned short jmp;
24547 + unsigned int addr1, addr2;
24548 +
24549 +#ifdef CONFIG_X86_64
24550 + if ((regs->ip + 11) >> 32)
24551 + break;
24552 +#endif
24553 +
24554 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24555 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24556 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24557 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24558 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24559 +
24560 + if (err)
24561 + break;
24562 +
24563 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24564 + regs->cx = addr1;
24565 + regs->ax = addr2;
24566 + regs->ip = addr2;
24567 + return 2;
24568 + }
24569 + } while (0);
24570 +
24571 + do { /* PaX: gcc trampoline emulation #2 */
24572 + unsigned char mov, jmp;
24573 + unsigned int addr1, addr2;
24574 +
24575 +#ifdef CONFIG_X86_64
24576 + if ((regs->ip + 9) >> 32)
24577 + break;
24578 +#endif
24579 +
24580 + err = get_user(mov, (unsigned char __user *)regs->ip);
24581 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24582 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24583 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24584 +
24585 + if (err)
24586 + break;
24587 +
24588 + if (mov == 0xB9 && jmp == 0xE9) {
24589 + regs->cx = addr1;
24590 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24591 + return 2;
24592 + }
24593 + } while (0);
24594 +
24595 + return 1; /* PaX in action */
24596 +}
24597 +
24598 +#ifdef CONFIG_X86_64
24599 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24600 +{
24601 + int err;
24602 +
24603 + do { /* PaX: libffi trampoline emulation */
24604 + unsigned short mov1, mov2, jmp1;
24605 + unsigned char stcclc, jmp2;
24606 + unsigned long addr1, addr2;
24607 +
24608 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24609 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24610 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24611 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24612 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24613 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24614 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24615 +
24616 + if (err)
24617 + break;
24618 +
24619 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24620 + regs->r11 = addr1;
24621 + regs->r10 = addr2;
24622 + if (stcclc == 0xF8)
24623 + regs->flags &= ~X86_EFLAGS_CF;
24624 + else
24625 + regs->flags |= X86_EFLAGS_CF;
24626 + regs->ip = addr1;
24627 + return 2;
24628 + }
24629 + } while (0);
24630 +
24631 + do { /* PaX: gcc trampoline emulation #1 */
24632 + unsigned short mov1, mov2, jmp1;
24633 + unsigned char jmp2;
24634 + unsigned int addr1;
24635 + unsigned long addr2;
24636 +
24637 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24638 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24639 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24640 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24641 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24642 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24643 +
24644 + if (err)
24645 + break;
24646 +
24647 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24648 + regs->r11 = addr1;
24649 + regs->r10 = addr2;
24650 + regs->ip = addr1;
24651 + return 2;
24652 + }
24653 + } while (0);
24654 +
24655 + do { /* PaX: gcc trampoline emulation #2 */
24656 + unsigned short mov1, mov2, jmp1;
24657 + unsigned char jmp2;
24658 + unsigned long addr1, addr2;
24659 +
24660 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24661 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24662 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24663 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24664 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24665 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24666 +
24667 + if (err)
24668 + break;
24669 +
24670 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24671 + regs->r11 = addr1;
24672 + regs->r10 = addr2;
24673 + regs->ip = addr1;
24674 + return 2;
24675 + }
24676 + } while (0);
24677 +
24678 + return 1; /* PaX in action */
24679 +}
24680 +#endif
24681 +
24682 +/*
24683 + * PaX: decide what to do with offenders (regs->ip = fault address)
24684 + *
24685 + * returns 1 when task should be killed
24686 + * 2 when gcc trampoline was detected
24687 + */
24688 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24689 +{
24690 + if (v8086_mode(regs))
24691 + return 1;
24692 +
24693 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24694 + return 1;
24695 +
24696 +#ifdef CONFIG_X86_32
24697 + return pax_handle_fetch_fault_32(regs);
24698 +#else
24699 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24700 + return pax_handle_fetch_fault_32(regs);
24701 + else
24702 + return pax_handle_fetch_fault_64(regs);
24703 +#endif
24704 +}
24705 +#endif
24706 +
24707 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24708 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24709 +{
24710 + long i;
24711 +
24712 + printk(KERN_ERR "PAX: bytes at PC: ");
24713 + for (i = 0; i < 20; i++) {
24714 + unsigned char c;
24715 + if (get_user(c, (unsigned char __force_user *)pc+i))
24716 + printk(KERN_CONT "?? ");
24717 + else
24718 + printk(KERN_CONT "%02x ", c);
24719 + }
24720 + printk("\n");
24721 +
24722 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24723 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24724 + unsigned long c;
24725 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24726 +#ifdef CONFIG_X86_32
24727 + printk(KERN_CONT "???????? ");
24728 +#else
24729 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24730 + printk(KERN_CONT "???????? ???????? ");
24731 + else
24732 + printk(KERN_CONT "???????????????? ");
24733 +#endif
24734 + } else {
24735 +#ifdef CONFIG_X86_64
24736 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24737 + printk(KERN_CONT "%08x ", (unsigned int)c);
24738 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24739 + } else
24740 +#endif
24741 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24742 + }
24743 + }
24744 + printk("\n");
24745 +}
24746 +#endif
24747 +
24748 +/**
24749 + * probe_kernel_write(): safely attempt to write to a location
24750 + * @dst: address to write to
24751 + * @src: pointer to the data that shall be written
24752 + * @size: size of the data chunk
24753 + *
24754 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24755 + * happens, handle that and return -EFAULT.
24756 + */
24757 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24758 +{
24759 + long ret;
24760 + mm_segment_t old_fs = get_fs();
24761 +
24762 + set_fs(KERNEL_DS);
24763 + pagefault_disable();
24764 + pax_open_kernel();
24765 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24766 + pax_close_kernel();
24767 + pagefault_enable();
24768 + set_fs(old_fs);
24769 +
24770 + return ret ? -EFAULT : 0;
24771 +}
24772 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24773 index dd74e46..7d26398 100644
24774 --- a/arch/x86/mm/gup.c
24775 +++ b/arch/x86/mm/gup.c
24776 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24777 addr = start;
24778 len = (unsigned long) nr_pages << PAGE_SHIFT;
24779 end = start + len;
24780 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24781 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24782 (void __user *)start, len)))
24783 return 0;
24784
24785 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24786 index f4f29b1..5cac4fb 100644
24787 --- a/arch/x86/mm/highmem_32.c
24788 +++ b/arch/x86/mm/highmem_32.c
24789 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24790 idx = type + KM_TYPE_NR*smp_processor_id();
24791 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24792 BUG_ON(!pte_none(*(kmap_pte-idx)));
24793 +
24794 + pax_open_kernel();
24795 set_pte(kmap_pte-idx, mk_pte(page, prot));
24796 + pax_close_kernel();
24797 +
24798 arch_flush_lazy_mmu_mode();
24799
24800 return (void *)vaddr;
24801 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24802 index 8ecbb4b..a269cab 100644
24803 --- a/arch/x86/mm/hugetlbpage.c
24804 +++ b/arch/x86/mm/hugetlbpage.c
24805 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24806 struct hstate *h = hstate_file(file);
24807 struct mm_struct *mm = current->mm;
24808 struct vm_area_struct *vma;
24809 - unsigned long start_addr;
24810 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24811 +
24812 +#ifdef CONFIG_PAX_SEGMEXEC
24813 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24814 + pax_task_size = SEGMEXEC_TASK_SIZE;
24815 +#endif
24816 +
24817 + pax_task_size -= PAGE_SIZE;
24818
24819 if (len > mm->cached_hole_size) {
24820 - start_addr = mm->free_area_cache;
24821 + start_addr = mm->free_area_cache;
24822 } else {
24823 - start_addr = TASK_UNMAPPED_BASE;
24824 - mm->cached_hole_size = 0;
24825 + start_addr = mm->mmap_base;
24826 + mm->cached_hole_size = 0;
24827 }
24828
24829 full_search:
24830 @@ -280,26 +287,27 @@ full_search:
24831
24832 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24833 /* At this point: (!vma || addr < vma->vm_end). */
24834 - if (TASK_SIZE - len < addr) {
24835 + if (pax_task_size - len < addr) {
24836 /*
24837 * Start a new search - just in case we missed
24838 * some holes.
24839 */
24840 - if (start_addr != TASK_UNMAPPED_BASE) {
24841 - start_addr = TASK_UNMAPPED_BASE;
24842 + if (start_addr != mm->mmap_base) {
24843 + start_addr = mm->mmap_base;
24844 mm->cached_hole_size = 0;
24845 goto full_search;
24846 }
24847 return -ENOMEM;
24848 }
24849 - if (!vma || addr + len <= vma->vm_start) {
24850 - mm->free_area_cache = addr + len;
24851 - return addr;
24852 - }
24853 + if (check_heap_stack_gap(vma, addr, len))
24854 + break;
24855 if (addr + mm->cached_hole_size < vma->vm_start)
24856 mm->cached_hole_size = vma->vm_start - addr;
24857 addr = ALIGN(vma->vm_end, huge_page_size(h));
24858 }
24859 +
24860 + mm->free_area_cache = addr + len;
24861 + return addr;
24862 }
24863
24864 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24865 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24866 {
24867 struct hstate *h = hstate_file(file);
24868 struct mm_struct *mm = current->mm;
24869 - struct vm_area_struct *vma, *prev_vma;
24870 - unsigned long base = mm->mmap_base, addr = addr0;
24871 + struct vm_area_struct *vma;
24872 + unsigned long base = mm->mmap_base, addr;
24873 unsigned long largest_hole = mm->cached_hole_size;
24874 - int first_time = 1;
24875
24876 /* don't allow allocations above current base */
24877 if (mm->free_area_cache > base)
24878 @@ -321,14 +328,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24879 largest_hole = 0;
24880 mm->free_area_cache = base;
24881 }
24882 -try_again:
24883 +
24884 /* make sure it can fit in the remaining address space */
24885 if (mm->free_area_cache < len)
24886 goto fail;
24887
24888 /* either no address requested or can't fit in requested address hole */
24889 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24890 + addr = (mm->free_area_cache - len);
24891 do {
24892 + addr &= huge_page_mask(h);
24893 /*
24894 * Lookup failure means no vma is above this address,
24895 * i.e. return with success:
24896 @@ -341,46 +349,47 @@ try_again:
24897 * new region fits between prev_vma->vm_end and
24898 * vma->vm_start, use it:
24899 */
24900 - prev_vma = vma->vm_prev;
24901 - if (addr + len <= vma->vm_start &&
24902 - (!prev_vma || (addr >= prev_vma->vm_end))) {
24903 + if (check_heap_stack_gap(vma, addr, len)) {
24904 /* remember the address as a hint for next time */
24905 - mm->cached_hole_size = largest_hole;
24906 - return (mm->free_area_cache = addr);
24907 - } else {
24908 - /* pull free_area_cache down to the first hole */
24909 - if (mm->free_area_cache == vma->vm_end) {
24910 - mm->free_area_cache = vma->vm_start;
24911 - mm->cached_hole_size = largest_hole;
24912 - }
24913 + mm->cached_hole_size = largest_hole;
24914 + return (mm->free_area_cache = addr);
24915 + }
24916 + /* pull free_area_cache down to the first hole */
24917 + if (mm->free_area_cache == vma->vm_end) {
24918 + mm->free_area_cache = vma->vm_start;
24919 + mm->cached_hole_size = largest_hole;
24920 }
24921
24922 /* remember the largest hole we saw so far */
24923 if (addr + largest_hole < vma->vm_start)
24924 - largest_hole = vma->vm_start - addr;
24925 + largest_hole = vma->vm_start - addr;
24926
24927 /* try just below the current vma->vm_start */
24928 - addr = (vma->vm_start - len) & huge_page_mask(h);
24929 - } while (len <= vma->vm_start);
24930 + addr = skip_heap_stack_gap(vma, len);
24931 + } while (!IS_ERR_VALUE(addr));
24932
24933 fail:
24934 /*
24935 - * if hint left us with no space for the requested
24936 - * mapping then try again:
24937 - */
24938 - if (first_time) {
24939 - mm->free_area_cache = base;
24940 - largest_hole = 0;
24941 - first_time = 0;
24942 - goto try_again;
24943 - }
24944 - /*
24945 * A failed mmap() very likely causes application failure,
24946 * so fall back to the bottom-up function here. This scenario
24947 * can happen with large stack limits and large mmap()
24948 * allocations.
24949 */
24950 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24951 +
24952 +#ifdef CONFIG_PAX_SEGMEXEC
24953 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24954 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24955 + else
24956 +#endif
24957 +
24958 + mm->mmap_base = TASK_UNMAPPED_BASE;
24959 +
24960 +#ifdef CONFIG_PAX_RANDMMAP
24961 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24962 + mm->mmap_base += mm->delta_mmap;
24963 +#endif
24964 +
24965 + mm->free_area_cache = mm->mmap_base;
24966 mm->cached_hole_size = ~0UL;
24967 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24968 len, pgoff, flags);
24969 @@ -388,6 +397,7 @@ fail:
24970 /*
24971 * Restore the topdown base:
24972 */
24973 + mm->mmap_base = base;
24974 mm->free_area_cache = base;
24975 mm->cached_hole_size = ~0UL;
24976
24977 @@ -401,10 +411,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24978 struct hstate *h = hstate_file(file);
24979 struct mm_struct *mm = current->mm;
24980 struct vm_area_struct *vma;
24981 + unsigned long pax_task_size = TASK_SIZE;
24982
24983 if (len & ~huge_page_mask(h))
24984 return -EINVAL;
24985 - if (len > TASK_SIZE)
24986 +
24987 +#ifdef CONFIG_PAX_SEGMEXEC
24988 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24989 + pax_task_size = SEGMEXEC_TASK_SIZE;
24990 +#endif
24991 +
24992 + pax_task_size -= PAGE_SIZE;
24993 +
24994 + if (len > pax_task_size)
24995 return -ENOMEM;
24996
24997 if (flags & MAP_FIXED) {
24998 @@ -416,8 +435,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24999 if (addr) {
25000 addr = ALIGN(addr, huge_page_size(h));
25001 vma = find_vma(mm, addr);
25002 - if (TASK_SIZE - len >= addr &&
25003 - (!vma || addr + len <= vma->vm_start))
25004 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
25005 return addr;
25006 }
25007 if (mm->get_unmapped_area == arch_get_unmapped_area)
25008 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
25009 index 6cabf65..00139c4 100644
25010 --- a/arch/x86/mm/init.c
25011 +++ b/arch/x86/mm/init.c
25012 @@ -17,6 +17,8 @@
25013 #include <asm/tlb.h>
25014 #include <asm/proto.h>
25015 #include <asm/dma.h> /* for MAX_DMA_PFN */
25016 +#include <asm/desc.h>
25017 +#include <asm/bios_ebda.h>
25018
25019 unsigned long __initdata pgt_buf_start;
25020 unsigned long __meminitdata pgt_buf_end;
25021 @@ -33,7 +35,7 @@ int direct_gbpages
25022 static void __init find_early_table_space(unsigned long end, int use_pse,
25023 int use_gbpages)
25024 {
25025 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
25026 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
25027 phys_addr_t base;
25028
25029 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
25030 @@ -312,10 +314,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
25031 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
25032 * mmio resources as well as potential bios/acpi data regions.
25033 */
25034 +
25035 +#ifdef CONFIG_GRKERNSEC_KMEM
25036 +static unsigned int ebda_start __read_only;
25037 +static unsigned int ebda_end __read_only;
25038 +#endif
25039 +
25040 int devmem_is_allowed(unsigned long pagenr)
25041 {
25042 +#ifdef CONFIG_GRKERNSEC_KMEM
25043 + /* allow BDA */
25044 + if (!pagenr)
25045 + return 1;
25046 + /* allow EBDA */
25047 + if (pagenr >= ebda_start && pagenr < ebda_end)
25048 + return 1;
25049 +#else
25050 + if (!pagenr)
25051 + return 1;
25052 +#ifdef CONFIG_VM86
25053 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
25054 + return 1;
25055 +#endif
25056 +#endif
25057 +
25058 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
25059 + return 1;
25060 +#ifdef CONFIG_GRKERNSEC_KMEM
25061 + /* throw out everything else below 1MB */
25062 if (pagenr <= 256)
25063 - return 1;
25064 + return 0;
25065 +#endif
25066 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
25067 return 0;
25068 if (!page_is_ram(pagenr))
25069 @@ -372,8 +401,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
25070 #endif
25071 }
25072
25073 +#ifdef CONFIG_GRKERNSEC_KMEM
25074 +static inline void gr_init_ebda(void)
25075 +{
25076 + unsigned int ebda_addr;
25077 + unsigned int ebda_size = 0;
25078 +
25079 + ebda_addr = get_bios_ebda();
25080 + if (ebda_addr) {
25081 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
25082 + ebda_size <<= 10;
25083 + }
25084 + if (ebda_addr && ebda_size) {
25085 + ebda_start = ebda_addr >> PAGE_SHIFT;
25086 + ebda_end = min(PAGE_ALIGN(ebda_addr + ebda_size), 0xa0000) >> PAGE_SHIFT;
25087 + } else {
25088 + ebda_start = 0x9f000 >> PAGE_SHIFT;
25089 + ebda_end = 0xa0000 >> PAGE_SHIFT;
25090 + }
25091 +}
25092 +#else
25093 +static inline void gr_init_ebda(void) { }
25094 +#endif
25095 +
25096 void free_initmem(void)
25097 {
25098 +#ifdef CONFIG_PAX_KERNEXEC
25099 +#ifdef CONFIG_X86_32
25100 + /* PaX: limit KERNEL_CS to actual size */
25101 + unsigned long addr, limit;
25102 + struct desc_struct d;
25103 + int cpu;
25104 +#endif
25105 +#endif
25106 +
25107 + gr_init_ebda();
25108 +
25109 +#ifdef CONFIG_PAX_KERNEXEC
25110 +#ifdef CONFIG_X86_32
25111 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
25112 + limit = (limit - 1UL) >> PAGE_SHIFT;
25113 +
25114 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
25115 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
25116 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
25117 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
25118 + }
25119 +
25120 + /* PaX: make KERNEL_CS read-only */
25121 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
25122 + if (!paravirt_enabled())
25123 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
25124 +/*
25125 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
25126 + pgd = pgd_offset_k(addr);
25127 + pud = pud_offset(pgd, addr);
25128 + pmd = pmd_offset(pud, addr);
25129 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
25130 + }
25131 +*/
25132 +#ifdef CONFIG_X86_PAE
25133 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
25134 +/*
25135 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
25136 + pgd = pgd_offset_k(addr);
25137 + pud = pud_offset(pgd, addr);
25138 + pmd = pmd_offset(pud, addr);
25139 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
25140 + }
25141 +*/
25142 +#endif
25143 +
25144 +#ifdef CONFIG_MODULES
25145 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
25146 +#endif
25147 +
25148 +#else
25149 + pgd_t *pgd;
25150 + pud_t *pud;
25151 + pmd_t *pmd;
25152 + unsigned long addr, end;
25153 +
25154 + /* PaX: make kernel code/rodata read-only, rest non-executable */
25155 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
25156 + pgd = pgd_offset_k(addr);
25157 + pud = pud_offset(pgd, addr);
25158 + pmd = pmd_offset(pud, addr);
25159 + if (!pmd_present(*pmd))
25160 + continue;
25161 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
25162 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
25163 + else
25164 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
25165 + }
25166 +
25167 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
25168 + end = addr + KERNEL_IMAGE_SIZE;
25169 + for (; addr < end; addr += PMD_SIZE) {
25170 + pgd = pgd_offset_k(addr);
25171 + pud = pud_offset(pgd, addr);
25172 + pmd = pmd_offset(pud, addr);
25173 + if (!pmd_present(*pmd))
25174 + continue;
25175 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
25176 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
25177 + }
25178 +#endif
25179 +
25180 + flush_tlb_all();
25181 +#endif
25182 +
25183 free_init_pages("unused kernel memory",
25184 (unsigned long)(&__init_begin),
25185 (unsigned long)(&__init_end));
25186 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
25187 index 8663f6c..829ae76 100644
25188 --- a/arch/x86/mm/init_32.c
25189 +++ b/arch/x86/mm/init_32.c
25190 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
25191 }
25192
25193 /*
25194 - * Creates a middle page table and puts a pointer to it in the
25195 - * given global directory entry. This only returns the gd entry
25196 - * in non-PAE compilation mode, since the middle layer is folded.
25197 - */
25198 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
25199 -{
25200 - pud_t *pud;
25201 - pmd_t *pmd_table;
25202 -
25203 -#ifdef CONFIG_X86_PAE
25204 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
25205 - if (after_bootmem)
25206 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
25207 - else
25208 - pmd_table = (pmd_t *)alloc_low_page();
25209 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
25210 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
25211 - pud = pud_offset(pgd, 0);
25212 - BUG_ON(pmd_table != pmd_offset(pud, 0));
25213 -
25214 - return pmd_table;
25215 - }
25216 -#endif
25217 - pud = pud_offset(pgd, 0);
25218 - pmd_table = pmd_offset(pud, 0);
25219 -
25220 - return pmd_table;
25221 -}
25222 -
25223 -/*
25224 * Create a page table and place a pointer to it in a middle page
25225 * directory entry:
25226 */
25227 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
25228 page_table = (pte_t *)alloc_low_page();
25229
25230 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
25231 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25232 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
25233 +#else
25234 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
25235 +#endif
25236 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
25237 }
25238
25239 return pte_offset_kernel(pmd, 0);
25240 }
25241
25242 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
25243 +{
25244 + pud_t *pud;
25245 + pmd_t *pmd_table;
25246 +
25247 + pud = pud_offset(pgd, 0);
25248 + pmd_table = pmd_offset(pud, 0);
25249 +
25250 + return pmd_table;
25251 +}
25252 +
25253 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
25254 {
25255 int pgd_idx = pgd_index(vaddr);
25256 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25257 int pgd_idx, pmd_idx;
25258 unsigned long vaddr;
25259 pgd_t *pgd;
25260 + pud_t *pud;
25261 pmd_t *pmd;
25262 pte_t *pte = NULL;
25263
25264 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25265 pgd = pgd_base + pgd_idx;
25266
25267 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
25268 - pmd = one_md_table_init(pgd);
25269 - pmd = pmd + pmd_index(vaddr);
25270 + pud = pud_offset(pgd, vaddr);
25271 + pmd = pmd_offset(pud, vaddr);
25272 +
25273 +#ifdef CONFIG_X86_PAE
25274 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25275 +#endif
25276 +
25277 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
25278 pmd++, pmd_idx++) {
25279 pte = page_table_kmap_check(one_page_table_init(pmd),
25280 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25281 }
25282 }
25283
25284 -static inline int is_kernel_text(unsigned long addr)
25285 +static inline int is_kernel_text(unsigned long start, unsigned long end)
25286 {
25287 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
25288 - return 1;
25289 - return 0;
25290 + if ((start > ktla_ktva((unsigned long)_etext) ||
25291 + end <= ktla_ktva((unsigned long)_stext)) &&
25292 + (start > ktla_ktva((unsigned long)_einittext) ||
25293 + end <= ktla_ktva((unsigned long)_sinittext)) &&
25294 +
25295 +#ifdef CONFIG_ACPI_SLEEP
25296 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
25297 +#endif
25298 +
25299 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
25300 + return 0;
25301 + return 1;
25302 }
25303
25304 /*
25305 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
25306 unsigned long last_map_addr = end;
25307 unsigned long start_pfn, end_pfn;
25308 pgd_t *pgd_base = swapper_pg_dir;
25309 - int pgd_idx, pmd_idx, pte_ofs;
25310 + unsigned int pgd_idx, pmd_idx, pte_ofs;
25311 unsigned long pfn;
25312 pgd_t *pgd;
25313 + pud_t *pud;
25314 pmd_t *pmd;
25315 pte_t *pte;
25316 unsigned pages_2m, pages_4k;
25317 @@ -281,8 +282,13 @@ repeat:
25318 pfn = start_pfn;
25319 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25320 pgd = pgd_base + pgd_idx;
25321 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
25322 - pmd = one_md_table_init(pgd);
25323 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
25324 + pud = pud_offset(pgd, 0);
25325 + pmd = pmd_offset(pud, 0);
25326 +
25327 +#ifdef CONFIG_X86_PAE
25328 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25329 +#endif
25330
25331 if (pfn >= end_pfn)
25332 continue;
25333 @@ -294,14 +300,13 @@ repeat:
25334 #endif
25335 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
25336 pmd++, pmd_idx++) {
25337 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
25338 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
25339
25340 /*
25341 * Map with big pages if possible, otherwise
25342 * create normal page tables:
25343 */
25344 if (use_pse) {
25345 - unsigned int addr2;
25346 pgprot_t prot = PAGE_KERNEL_LARGE;
25347 /*
25348 * first pass will use the same initial
25349 @@ -311,11 +316,7 @@ repeat:
25350 __pgprot(PTE_IDENT_ATTR |
25351 _PAGE_PSE);
25352
25353 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
25354 - PAGE_OFFSET + PAGE_SIZE-1;
25355 -
25356 - if (is_kernel_text(addr) ||
25357 - is_kernel_text(addr2))
25358 + if (is_kernel_text(address, address + PMD_SIZE))
25359 prot = PAGE_KERNEL_LARGE_EXEC;
25360
25361 pages_2m++;
25362 @@ -332,7 +333,7 @@ repeat:
25363 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25364 pte += pte_ofs;
25365 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25366 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25367 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25368 pgprot_t prot = PAGE_KERNEL;
25369 /*
25370 * first pass will use the same initial
25371 @@ -340,7 +341,7 @@ repeat:
25372 */
25373 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25374
25375 - if (is_kernel_text(addr))
25376 + if (is_kernel_text(address, address + PAGE_SIZE))
25377 prot = PAGE_KERNEL_EXEC;
25378
25379 pages_4k++;
25380 @@ -466,7 +467,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25381
25382 pud = pud_offset(pgd, va);
25383 pmd = pmd_offset(pud, va);
25384 - if (!pmd_present(*pmd))
25385 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
25386 break;
25387
25388 pte = pte_offset_kernel(pmd, va);
25389 @@ -518,12 +519,10 @@ void __init early_ioremap_page_table_range_init(void)
25390
25391 static void __init pagetable_init(void)
25392 {
25393 - pgd_t *pgd_base = swapper_pg_dir;
25394 -
25395 - permanent_kmaps_init(pgd_base);
25396 + permanent_kmaps_init(swapper_pg_dir);
25397 }
25398
25399 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25400 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25401 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25402
25403 /* user-defined highmem size */
25404 @@ -735,6 +734,12 @@ void __init mem_init(void)
25405
25406 pci_iommu_alloc();
25407
25408 +#ifdef CONFIG_PAX_PER_CPU_PGD
25409 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25410 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25411 + KERNEL_PGD_PTRS);
25412 +#endif
25413 +
25414 #ifdef CONFIG_FLATMEM
25415 BUG_ON(!mem_map);
25416 #endif
25417 @@ -761,7 +766,7 @@ void __init mem_init(void)
25418 reservedpages++;
25419
25420 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25421 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25422 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25423 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25424
25425 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25426 @@ -802,10 +807,10 @@ void __init mem_init(void)
25427 ((unsigned long)&__init_end -
25428 (unsigned long)&__init_begin) >> 10,
25429
25430 - (unsigned long)&_etext, (unsigned long)&_edata,
25431 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25432 + (unsigned long)&_sdata, (unsigned long)&_edata,
25433 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25434
25435 - (unsigned long)&_text, (unsigned long)&_etext,
25436 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25437 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25438
25439 /*
25440 @@ -883,6 +888,7 @@ void set_kernel_text_rw(void)
25441 if (!kernel_set_to_readonly)
25442 return;
25443
25444 + start = ktla_ktva(start);
25445 pr_debug("Set kernel text: %lx - %lx for read write\n",
25446 start, start+size);
25447
25448 @@ -897,6 +903,7 @@ void set_kernel_text_ro(void)
25449 if (!kernel_set_to_readonly)
25450 return;
25451
25452 + start = ktla_ktva(start);
25453 pr_debug("Set kernel text: %lx - %lx for read only\n",
25454 start, start+size);
25455
25456 @@ -925,6 +932,7 @@ void mark_rodata_ro(void)
25457 unsigned long start = PFN_ALIGN(_text);
25458 unsigned long size = PFN_ALIGN(_etext) - start;
25459
25460 + start = ktla_ktva(start);
25461 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25462 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25463 size >> 10);
25464 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25465 index 436a030..4f97ffc 100644
25466 --- a/arch/x86/mm/init_64.c
25467 +++ b/arch/x86/mm/init_64.c
25468 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25469 * around without checking the pgd every time.
25470 */
25471
25472 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25473 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25474 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25475
25476 int force_personality32;
25477 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25478
25479 for (address = start; address <= end; address += PGDIR_SIZE) {
25480 const pgd_t *pgd_ref = pgd_offset_k(address);
25481 +
25482 +#ifdef CONFIG_PAX_PER_CPU_PGD
25483 + unsigned long cpu;
25484 +#else
25485 struct page *page;
25486 +#endif
25487
25488 if (pgd_none(*pgd_ref))
25489 continue;
25490
25491 spin_lock(&pgd_lock);
25492 +
25493 +#ifdef CONFIG_PAX_PER_CPU_PGD
25494 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25495 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25496 +#else
25497 list_for_each_entry(page, &pgd_list, lru) {
25498 pgd_t *pgd;
25499 spinlock_t *pgt_lock;
25500 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25501 /* the pgt_lock only for Xen */
25502 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25503 spin_lock(pgt_lock);
25504 +#endif
25505
25506 if (pgd_none(*pgd))
25507 set_pgd(pgd, *pgd_ref);
25508 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25509 BUG_ON(pgd_page_vaddr(*pgd)
25510 != pgd_page_vaddr(*pgd_ref));
25511
25512 +#ifndef CONFIG_PAX_PER_CPU_PGD
25513 spin_unlock(pgt_lock);
25514 +#endif
25515 +
25516 }
25517 spin_unlock(&pgd_lock);
25518 }
25519 @@ -162,7 +176,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25520 {
25521 if (pgd_none(*pgd)) {
25522 pud_t *pud = (pud_t *)spp_getpage();
25523 - pgd_populate(&init_mm, pgd, pud);
25524 + pgd_populate_kernel(&init_mm, pgd, pud);
25525 if (pud != pud_offset(pgd, 0))
25526 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25527 pud, pud_offset(pgd, 0));
25528 @@ -174,7 +188,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25529 {
25530 if (pud_none(*pud)) {
25531 pmd_t *pmd = (pmd_t *) spp_getpage();
25532 - pud_populate(&init_mm, pud, pmd);
25533 + pud_populate_kernel(&init_mm, pud, pmd);
25534 if (pmd != pmd_offset(pud, 0))
25535 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25536 pmd, pmd_offset(pud, 0));
25537 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25538 pmd = fill_pmd(pud, vaddr);
25539 pte = fill_pte(pmd, vaddr);
25540
25541 + pax_open_kernel();
25542 set_pte(pte, new_pte);
25543 + pax_close_kernel();
25544
25545 /*
25546 * It's enough to flush this one mapping.
25547 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25548 pgd = pgd_offset_k((unsigned long)__va(phys));
25549 if (pgd_none(*pgd)) {
25550 pud = (pud_t *) spp_getpage();
25551 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25552 - _PAGE_USER));
25553 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25554 }
25555 pud = pud_offset(pgd, (unsigned long)__va(phys));
25556 if (pud_none(*pud)) {
25557 pmd = (pmd_t *) spp_getpage();
25558 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25559 - _PAGE_USER));
25560 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25561 }
25562 pmd = pmd_offset(pud, phys);
25563 BUG_ON(!pmd_none(*pmd));
25564 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25565 if (pfn >= pgt_buf_top)
25566 panic("alloc_low_page: ran out of memory");
25567
25568 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25569 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25570 clear_page(adr);
25571 *phys = pfn * PAGE_SIZE;
25572 return adr;
25573 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
25574
25575 phys = __pa(virt);
25576 left = phys & (PAGE_SIZE - 1);
25577 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25578 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25579 adr = (void *)(((unsigned long)adr) | left);
25580
25581 return adr;
25582 @@ -546,7 +560,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25583 unmap_low_page(pmd);
25584
25585 spin_lock(&init_mm.page_table_lock);
25586 - pud_populate(&init_mm, pud, __va(pmd_phys));
25587 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25588 spin_unlock(&init_mm.page_table_lock);
25589 }
25590 __flush_tlb_all();
25591 @@ -592,7 +606,7 @@ kernel_physical_mapping_init(unsigned long start,
25592 unmap_low_page(pud);
25593
25594 spin_lock(&init_mm.page_table_lock);
25595 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25596 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25597 spin_unlock(&init_mm.page_table_lock);
25598 pgd_changed = true;
25599 }
25600 @@ -684,6 +698,12 @@ void __init mem_init(void)
25601
25602 pci_iommu_alloc();
25603
25604 +#ifdef CONFIG_PAX_PER_CPU_PGD
25605 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25606 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25607 + KERNEL_PGD_PTRS);
25608 +#endif
25609 +
25610 /* clear_bss() already clear the empty_zero_page */
25611
25612 reservedpages = 0;
25613 @@ -844,8 +864,8 @@ int kern_addr_valid(unsigned long addr)
25614 static struct vm_area_struct gate_vma = {
25615 .vm_start = VSYSCALL_START,
25616 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25617 - .vm_page_prot = PAGE_READONLY_EXEC,
25618 - .vm_flags = VM_READ | VM_EXEC
25619 + .vm_page_prot = PAGE_READONLY,
25620 + .vm_flags = VM_READ
25621 };
25622
25623 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25624 @@ -879,7 +899,7 @@ int in_gate_area_no_mm(unsigned long addr)
25625
25626 const char *arch_vma_name(struct vm_area_struct *vma)
25627 {
25628 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25629 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25630 return "[vdso]";
25631 if (vma == &gate_vma)
25632 return "[vsyscall]";
25633 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25634 index 7b179b4..6bd1777 100644
25635 --- a/arch/x86/mm/iomap_32.c
25636 +++ b/arch/x86/mm/iomap_32.c
25637 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25638 type = kmap_atomic_idx_push();
25639 idx = type + KM_TYPE_NR * smp_processor_id();
25640 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25641 +
25642 + pax_open_kernel();
25643 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25644 + pax_close_kernel();
25645 +
25646 arch_flush_lazy_mmu_mode();
25647
25648 return (void *)vaddr;
25649 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25650 index be1ef57..55f0160 100644
25651 --- a/arch/x86/mm/ioremap.c
25652 +++ b/arch/x86/mm/ioremap.c
25653 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25654 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25655 int is_ram = page_is_ram(pfn);
25656
25657 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25658 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25659 return NULL;
25660 WARN_ON_ONCE(is_ram);
25661 }
25662 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25663
25664 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25665 if (page_is_ram(start >> PAGE_SHIFT))
25666 +#ifdef CONFIG_HIGHMEM
25667 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25668 +#endif
25669 return __va(phys);
25670
25671 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25672 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25673 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25674
25675 static __initdata int after_paging_init;
25676 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25677 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25678
25679 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25680 {
25681 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25682 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25683
25684 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25685 - memset(bm_pte, 0, sizeof(bm_pte));
25686 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25687 + pmd_populate_user(&init_mm, pmd, bm_pte);
25688
25689 /*
25690 * The boot-ioremap range spans multiple pmds, for which
25691 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25692 index d87dd6d..bf3fa66 100644
25693 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25694 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25695 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25696 * memory (e.g. tracked pages)? For now, we need this to avoid
25697 * invoking kmemcheck for PnP BIOS calls.
25698 */
25699 - if (regs->flags & X86_VM_MASK)
25700 + if (v8086_mode(regs))
25701 return false;
25702 - if (regs->cs != __KERNEL_CS)
25703 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25704 return false;
25705
25706 pte = kmemcheck_pte_lookup(address);
25707 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25708 index 845df68..1d8d29f 100644
25709 --- a/arch/x86/mm/mmap.c
25710 +++ b/arch/x86/mm/mmap.c
25711 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25712 * Leave an at least ~128 MB hole with possible stack randomization.
25713 */
25714 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25715 -#define MAX_GAP (TASK_SIZE/6*5)
25716 +#define MAX_GAP (pax_task_size/6*5)
25717
25718 static int mmap_is_legacy(void)
25719 {
25720 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25721 return rnd << PAGE_SHIFT;
25722 }
25723
25724 -static unsigned long mmap_base(void)
25725 +static unsigned long mmap_base(struct mm_struct *mm)
25726 {
25727 unsigned long gap = rlimit(RLIMIT_STACK);
25728 + unsigned long pax_task_size = TASK_SIZE;
25729 +
25730 +#ifdef CONFIG_PAX_SEGMEXEC
25731 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25732 + pax_task_size = SEGMEXEC_TASK_SIZE;
25733 +#endif
25734
25735 if (gap < MIN_GAP)
25736 gap = MIN_GAP;
25737 else if (gap > MAX_GAP)
25738 gap = MAX_GAP;
25739
25740 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25741 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25742 }
25743
25744 /*
25745 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25746 * does, but not when emulating X86_32
25747 */
25748 -static unsigned long mmap_legacy_base(void)
25749 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25750 {
25751 - if (mmap_is_ia32())
25752 + if (mmap_is_ia32()) {
25753 +
25754 +#ifdef CONFIG_PAX_SEGMEXEC
25755 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25756 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25757 + else
25758 +#endif
25759 +
25760 return TASK_UNMAPPED_BASE;
25761 - else
25762 + } else
25763 return TASK_UNMAPPED_BASE + mmap_rnd();
25764 }
25765
25766 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25767 void arch_pick_mmap_layout(struct mm_struct *mm)
25768 {
25769 if (mmap_is_legacy()) {
25770 - mm->mmap_base = mmap_legacy_base();
25771 + mm->mmap_base = mmap_legacy_base(mm);
25772 +
25773 +#ifdef CONFIG_PAX_RANDMMAP
25774 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25775 + mm->mmap_base += mm->delta_mmap;
25776 +#endif
25777 +
25778 mm->get_unmapped_area = arch_get_unmapped_area;
25779 mm->unmap_area = arch_unmap_area;
25780 } else {
25781 - mm->mmap_base = mmap_base();
25782 + mm->mmap_base = mmap_base(mm);
25783 +
25784 +#ifdef CONFIG_PAX_RANDMMAP
25785 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25786 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25787 +#endif
25788 +
25789 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25790 mm->unmap_area = arch_unmap_area_topdown;
25791 }
25792 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25793 index dc0b727..dc9d71a 100644
25794 --- a/arch/x86/mm/mmio-mod.c
25795 +++ b/arch/x86/mm/mmio-mod.c
25796 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25797 break;
25798 default:
25799 {
25800 - unsigned char *ip = (unsigned char *)instptr;
25801 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25802 my_trace->opcode = MMIO_UNKNOWN_OP;
25803 my_trace->width = 0;
25804 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25805 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25806 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25807 void __iomem *addr)
25808 {
25809 - static atomic_t next_id;
25810 + static atomic_unchecked_t next_id;
25811 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25812 /* These are page-unaligned. */
25813 struct mmiotrace_map map = {
25814 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25815 .private = trace
25816 },
25817 .phys = offset,
25818 - .id = atomic_inc_return(&next_id)
25819 + .id = atomic_inc_return_unchecked(&next_id)
25820 };
25821 map.map_id = trace->id;
25822
25823 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25824 index b008656..773eac2 100644
25825 --- a/arch/x86/mm/pageattr-test.c
25826 +++ b/arch/x86/mm/pageattr-test.c
25827 @@ -36,7 +36,7 @@ enum {
25828
25829 static int pte_testbit(pte_t pte)
25830 {
25831 - return pte_flags(pte) & _PAGE_UNUSED1;
25832 + return pte_flags(pte) & _PAGE_CPA_TEST;
25833 }
25834
25835 struct split_state {
25836 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25837 index e1ebde3..b1e1db38 100644
25838 --- a/arch/x86/mm/pageattr.c
25839 +++ b/arch/x86/mm/pageattr.c
25840 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25841 */
25842 #ifdef CONFIG_PCI_BIOS
25843 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25844 - pgprot_val(forbidden) |= _PAGE_NX;
25845 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25846 #endif
25847
25848 /*
25849 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25850 * Does not cover __inittext since that is gone later on. On
25851 * 64bit we do not enforce !NX on the low mapping
25852 */
25853 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25854 - pgprot_val(forbidden) |= _PAGE_NX;
25855 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25856 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25857
25858 +#ifdef CONFIG_DEBUG_RODATA
25859 /*
25860 * The .rodata section needs to be read-only. Using the pfn
25861 * catches all aliases.
25862 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25863 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25864 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25865 pgprot_val(forbidden) |= _PAGE_RW;
25866 +#endif
25867
25868 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25869 /*
25870 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25871 }
25872 #endif
25873
25874 +#ifdef CONFIG_PAX_KERNEXEC
25875 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25876 + pgprot_val(forbidden) |= _PAGE_RW;
25877 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25878 + }
25879 +#endif
25880 +
25881 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25882
25883 return prot;
25884 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25885 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25886 {
25887 /* change init_mm */
25888 + pax_open_kernel();
25889 set_pte_atomic(kpte, pte);
25890 +
25891 #ifdef CONFIG_X86_32
25892 if (!SHARED_KERNEL_PMD) {
25893 +
25894 +#ifdef CONFIG_PAX_PER_CPU_PGD
25895 + unsigned long cpu;
25896 +#else
25897 struct page *page;
25898 +#endif
25899
25900 +#ifdef CONFIG_PAX_PER_CPU_PGD
25901 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25902 + pgd_t *pgd = get_cpu_pgd(cpu);
25903 +#else
25904 list_for_each_entry(page, &pgd_list, lru) {
25905 - pgd_t *pgd;
25906 + pgd_t *pgd = (pgd_t *)page_address(page);
25907 +#endif
25908 +
25909 pud_t *pud;
25910 pmd_t *pmd;
25911
25912 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25913 + pgd += pgd_index(address);
25914 pud = pud_offset(pgd, address);
25915 pmd = pmd_offset(pud, address);
25916 set_pte_atomic((pte_t *)pmd, pte);
25917 }
25918 }
25919 #endif
25920 + pax_close_kernel();
25921 }
25922
25923 static int
25924 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25925 index f6ff57b..481690f 100644
25926 --- a/arch/x86/mm/pat.c
25927 +++ b/arch/x86/mm/pat.c
25928 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25929
25930 if (!entry) {
25931 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25932 - current->comm, current->pid, start, end);
25933 + current->comm, task_pid_nr(current), start, end);
25934 return -EINVAL;
25935 }
25936
25937 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25938 while (cursor < to) {
25939 if (!devmem_is_allowed(pfn)) {
25940 printk(KERN_INFO
25941 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25942 - current->comm, from, to);
25943 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25944 + current->comm, from, to, cursor);
25945 return 0;
25946 }
25947 cursor += PAGE_SIZE;
25948 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25949 printk(KERN_INFO
25950 "%s:%d ioremap_change_attr failed %s "
25951 "for %Lx-%Lx\n",
25952 - current->comm, current->pid,
25953 + current->comm, task_pid_nr(current),
25954 cattr_name(flags),
25955 base, (unsigned long long)(base + size));
25956 return -EINVAL;
25957 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25958 if (want_flags != flags) {
25959 printk(KERN_WARNING
25960 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25961 - current->comm, current->pid,
25962 + current->comm, task_pid_nr(current),
25963 cattr_name(want_flags),
25964 (unsigned long long)paddr,
25965 (unsigned long long)(paddr + size),
25966 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25967 free_memtype(paddr, paddr + size);
25968 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25969 " for %Lx-%Lx, got %s\n",
25970 - current->comm, current->pid,
25971 + current->comm, task_pid_nr(current),
25972 cattr_name(want_flags),
25973 (unsigned long long)paddr,
25974 (unsigned long long)(paddr + size),
25975 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25976 index 9f0614d..92ae64a 100644
25977 --- a/arch/x86/mm/pf_in.c
25978 +++ b/arch/x86/mm/pf_in.c
25979 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25980 int i;
25981 enum reason_type rv = OTHERS;
25982
25983 - p = (unsigned char *)ins_addr;
25984 + p = (unsigned char *)ktla_ktva(ins_addr);
25985 p += skip_prefix(p, &prf);
25986 p += get_opcode(p, &opcode);
25987
25988 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25989 struct prefix_bits prf;
25990 int i;
25991
25992 - p = (unsigned char *)ins_addr;
25993 + p = (unsigned char *)ktla_ktva(ins_addr);
25994 p += skip_prefix(p, &prf);
25995 p += get_opcode(p, &opcode);
25996
25997 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25998 struct prefix_bits prf;
25999 int i;
26000
26001 - p = (unsigned char *)ins_addr;
26002 + p = (unsigned char *)ktla_ktva(ins_addr);
26003 p += skip_prefix(p, &prf);
26004 p += get_opcode(p, &opcode);
26005
26006 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
26007 struct prefix_bits prf;
26008 int i;
26009
26010 - p = (unsigned char *)ins_addr;
26011 + p = (unsigned char *)ktla_ktva(ins_addr);
26012 p += skip_prefix(p, &prf);
26013 p += get_opcode(p, &opcode);
26014 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
26015 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
26016 struct prefix_bits prf;
26017 int i;
26018
26019 - p = (unsigned char *)ins_addr;
26020 + p = (unsigned char *)ktla_ktva(ins_addr);
26021 p += skip_prefix(p, &prf);
26022 p += get_opcode(p, &opcode);
26023 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
26024 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
26025 index 8573b83..7d9628f 100644
26026 --- a/arch/x86/mm/pgtable.c
26027 +++ b/arch/x86/mm/pgtable.c
26028 @@ -84,10 +84,60 @@ static inline void pgd_list_del(pgd_t *pgd)
26029 list_del(&page->lru);
26030 }
26031
26032 -#define UNSHARED_PTRS_PER_PGD \
26033 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
26034 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26035 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
26036
26037 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
26038 +{
26039 + while (count--)
26040 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
26041 +}
26042 +#endif
26043
26044 +#ifdef CONFIG_PAX_PER_CPU_PGD
26045 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
26046 +{
26047 + while (count--) {
26048 + pgd_t pgd;
26049 +
26050 +#ifdef CONFIG_X86_64
26051 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
26052 +#else
26053 + pgd = *src++;
26054 +#endif
26055 +
26056 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26057 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
26058 +#endif
26059 +
26060 + *dst++ = pgd;
26061 + }
26062 +
26063 +}
26064 +#endif
26065 +
26066 +#ifdef CONFIG_X86_64
26067 +#define pxd_t pud_t
26068 +#define pyd_t pgd_t
26069 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
26070 +#define pxd_free(mm, pud) pud_free((mm), (pud))
26071 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
26072 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
26073 +#define PYD_SIZE PGDIR_SIZE
26074 +#else
26075 +#define pxd_t pmd_t
26076 +#define pyd_t pud_t
26077 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
26078 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
26079 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
26080 +#define pyd_offset(mm, address) pud_offset((mm), (address))
26081 +#define PYD_SIZE PUD_SIZE
26082 +#endif
26083 +
26084 +#ifdef CONFIG_PAX_PER_CPU_PGD
26085 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
26086 +static inline void pgd_dtor(pgd_t *pgd) {}
26087 +#else
26088 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
26089 {
26090 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
26091 @@ -128,6 +178,7 @@ static void pgd_dtor(pgd_t *pgd)
26092 pgd_list_del(pgd);
26093 spin_unlock(&pgd_lock);
26094 }
26095 +#endif
26096
26097 /*
26098 * List of all pgd's needed for non-PAE so it can invalidate entries
26099 @@ -140,7 +191,7 @@ static void pgd_dtor(pgd_t *pgd)
26100 * -- wli
26101 */
26102
26103 -#ifdef CONFIG_X86_PAE
26104 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26105 /*
26106 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
26107 * updating the top-level pagetable entries to guarantee the
26108 @@ -152,7 +203,7 @@ static void pgd_dtor(pgd_t *pgd)
26109 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
26110 * and initialize the kernel pmds here.
26111 */
26112 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
26113 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
26114
26115 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
26116 {
26117 @@ -170,36 +221,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
26118 */
26119 flush_tlb_mm(mm);
26120 }
26121 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
26122 +#define PREALLOCATED_PXDS USER_PGD_PTRS
26123 #else /* !CONFIG_X86_PAE */
26124
26125 /* No need to prepopulate any pagetable entries in non-PAE modes. */
26126 -#define PREALLOCATED_PMDS 0
26127 +#define PREALLOCATED_PXDS 0
26128
26129 #endif /* CONFIG_X86_PAE */
26130
26131 -static void free_pmds(pmd_t *pmds[])
26132 +static void free_pxds(pxd_t *pxds[])
26133 {
26134 int i;
26135
26136 - for(i = 0; i < PREALLOCATED_PMDS; i++)
26137 - if (pmds[i])
26138 - free_page((unsigned long)pmds[i]);
26139 + for(i = 0; i < PREALLOCATED_PXDS; i++)
26140 + if (pxds[i])
26141 + free_page((unsigned long)pxds[i]);
26142 }
26143
26144 -static int preallocate_pmds(pmd_t *pmds[])
26145 +static int preallocate_pxds(pxd_t *pxds[])
26146 {
26147 int i;
26148 bool failed = false;
26149
26150 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
26151 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
26152 - if (pmd == NULL)
26153 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
26154 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
26155 + if (pxd == NULL)
26156 failed = true;
26157 - pmds[i] = pmd;
26158 + pxds[i] = pxd;
26159 }
26160
26161 if (failed) {
26162 - free_pmds(pmds);
26163 + free_pxds(pxds);
26164 return -ENOMEM;
26165 }
26166
26167 @@ -212,51 +265,55 @@ static int preallocate_pmds(pmd_t *pmds[])
26168 * preallocate which never got a corresponding vma will need to be
26169 * freed manually.
26170 */
26171 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
26172 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
26173 {
26174 int i;
26175
26176 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
26177 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
26178 pgd_t pgd = pgdp[i];
26179
26180 if (pgd_val(pgd) != 0) {
26181 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
26182 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
26183
26184 - pgdp[i] = native_make_pgd(0);
26185 + set_pgd(pgdp + i, native_make_pgd(0));
26186
26187 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
26188 - pmd_free(mm, pmd);
26189 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
26190 + pxd_free(mm, pxd);
26191 }
26192 }
26193 }
26194
26195 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
26196 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
26197 {
26198 - pud_t *pud;
26199 + pyd_t *pyd;
26200 unsigned long addr;
26201 int i;
26202
26203 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
26204 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
26205 return;
26206
26207 - pud = pud_offset(pgd, 0);
26208 +#ifdef CONFIG_X86_64
26209 + pyd = pyd_offset(mm, 0L);
26210 +#else
26211 + pyd = pyd_offset(pgd, 0L);
26212 +#endif
26213
26214 - for (addr = i = 0; i < PREALLOCATED_PMDS;
26215 - i++, pud++, addr += PUD_SIZE) {
26216 - pmd_t *pmd = pmds[i];
26217 + for (addr = i = 0; i < PREALLOCATED_PXDS;
26218 + i++, pyd++, addr += PYD_SIZE) {
26219 + pxd_t *pxd = pxds[i];
26220
26221 if (i >= KERNEL_PGD_BOUNDARY)
26222 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
26223 - sizeof(pmd_t) * PTRS_PER_PMD);
26224 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
26225 + sizeof(pxd_t) * PTRS_PER_PMD);
26226
26227 - pud_populate(mm, pud, pmd);
26228 + pyd_populate(mm, pyd, pxd);
26229 }
26230 }
26231
26232 pgd_t *pgd_alloc(struct mm_struct *mm)
26233 {
26234 pgd_t *pgd;
26235 - pmd_t *pmds[PREALLOCATED_PMDS];
26236 + pxd_t *pxds[PREALLOCATED_PXDS];
26237
26238 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
26239
26240 @@ -265,11 +322,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
26241
26242 mm->pgd = pgd;
26243
26244 - if (preallocate_pmds(pmds) != 0)
26245 + if (preallocate_pxds(pxds) != 0)
26246 goto out_free_pgd;
26247
26248 if (paravirt_pgd_alloc(mm) != 0)
26249 - goto out_free_pmds;
26250 + goto out_free_pxds;
26251
26252 /*
26253 * Make sure that pre-populating the pmds is atomic with
26254 @@ -279,14 +336,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
26255 spin_lock(&pgd_lock);
26256
26257 pgd_ctor(mm, pgd);
26258 - pgd_prepopulate_pmd(mm, pgd, pmds);
26259 + pgd_prepopulate_pxd(mm, pgd, pxds);
26260
26261 spin_unlock(&pgd_lock);
26262
26263 return pgd;
26264
26265 -out_free_pmds:
26266 - free_pmds(pmds);
26267 +out_free_pxds:
26268 + free_pxds(pxds);
26269 out_free_pgd:
26270 free_page((unsigned long)pgd);
26271 out:
26272 @@ -295,7 +352,7 @@ out:
26273
26274 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
26275 {
26276 - pgd_mop_up_pmds(mm, pgd);
26277 + pgd_mop_up_pxds(mm, pgd);
26278 pgd_dtor(pgd);
26279 paravirt_pgd_free(mm, pgd);
26280 free_page((unsigned long)pgd);
26281 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
26282 index cac7184..09a39fa 100644
26283 --- a/arch/x86/mm/pgtable_32.c
26284 +++ b/arch/x86/mm/pgtable_32.c
26285 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
26286 return;
26287 }
26288 pte = pte_offset_kernel(pmd, vaddr);
26289 +
26290 + pax_open_kernel();
26291 if (pte_val(pteval))
26292 set_pte_at(&init_mm, vaddr, pte, pteval);
26293 else
26294 pte_clear(&init_mm, vaddr, pte);
26295 + pax_close_kernel();
26296
26297 /*
26298 * It's enough to flush this one mapping.
26299 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
26300 index 410531d..0f16030 100644
26301 --- a/arch/x86/mm/setup_nx.c
26302 +++ b/arch/x86/mm/setup_nx.c
26303 @@ -5,8 +5,10 @@
26304 #include <asm/pgtable.h>
26305 #include <asm/proto.h>
26306
26307 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26308 static int disable_nx __cpuinitdata;
26309
26310 +#ifndef CONFIG_PAX_PAGEEXEC
26311 /*
26312 * noexec = on|off
26313 *
26314 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
26315 return 0;
26316 }
26317 early_param("noexec", noexec_setup);
26318 +#endif
26319 +
26320 +#endif
26321
26322 void __cpuinit x86_configure_nx(void)
26323 {
26324 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26325 if (cpu_has_nx && !disable_nx)
26326 __supported_pte_mask |= _PAGE_NX;
26327 else
26328 +#endif
26329 __supported_pte_mask &= ~_PAGE_NX;
26330 }
26331
26332 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
26333 index d6c0418..06a0ad5 100644
26334 --- a/arch/x86/mm/tlb.c
26335 +++ b/arch/x86/mm/tlb.c
26336 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
26337 BUG();
26338 cpumask_clear_cpu(cpu,
26339 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
26340 +
26341 +#ifndef CONFIG_PAX_PER_CPU_PGD
26342 load_cr3(swapper_pg_dir);
26343 +#endif
26344 +
26345 }
26346 EXPORT_SYMBOL_GPL(leave_mm);
26347
26348 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
26349 index 6687022..ceabcfa 100644
26350 --- a/arch/x86/net/bpf_jit.S
26351 +++ b/arch/x86/net/bpf_jit.S
26352 @@ -9,6 +9,7 @@
26353 */
26354 #include <linux/linkage.h>
26355 #include <asm/dwarf2.h>
26356 +#include <asm/alternative-asm.h>
26357
26358 /*
26359 * Calling convention :
26360 @@ -35,6 +36,7 @@ sk_load_word:
26361 jle bpf_slow_path_word
26362 mov (SKBDATA,%rsi),%eax
26363 bswap %eax /* ntohl() */
26364 + pax_force_retaddr
26365 ret
26366
26367
26368 @@ -53,6 +55,7 @@ sk_load_half:
26369 jle bpf_slow_path_half
26370 movzwl (SKBDATA,%rsi),%eax
26371 rol $8,%ax # ntohs()
26372 + pax_force_retaddr
26373 ret
26374
26375 sk_load_byte_ind:
26376 @@ -66,6 +69,7 @@ sk_load_byte:
26377 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
26378 jle bpf_slow_path_byte
26379 movzbl (SKBDATA,%rsi),%eax
26380 + pax_force_retaddr
26381 ret
26382
26383 /**
26384 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
26385 movzbl (SKBDATA,%rsi),%ebx
26386 and $15,%bl
26387 shl $2,%bl
26388 + pax_force_retaddr
26389 ret
26390 CFI_ENDPROC
26391 ENDPROC(sk_load_byte_msh)
26392 @@ -91,6 +96,7 @@ bpf_error:
26393 xor %eax,%eax
26394 mov -8(%rbp),%rbx
26395 leaveq
26396 + pax_force_retaddr
26397 ret
26398
26399 /* rsi contains offset and can be scratched */
26400 @@ -113,6 +119,7 @@ bpf_slow_path_word:
26401 js bpf_error
26402 mov -12(%rbp),%eax
26403 bswap %eax
26404 + pax_force_retaddr
26405 ret
26406
26407 bpf_slow_path_half:
26408 @@ -121,12 +128,14 @@ bpf_slow_path_half:
26409 mov -12(%rbp),%ax
26410 rol $8,%ax
26411 movzwl %ax,%eax
26412 + pax_force_retaddr
26413 ret
26414
26415 bpf_slow_path_byte:
26416 bpf_slow_path_common(1)
26417 js bpf_error
26418 movzbl -12(%rbp),%eax
26419 + pax_force_retaddr
26420 ret
26421
26422 bpf_slow_path_byte_msh:
26423 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
26424 and $15,%al
26425 shl $2,%al
26426 xchg %eax,%ebx
26427 + pax_force_retaddr
26428 ret
26429 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26430 index 5a5b6e4..201d42e 100644
26431 --- a/arch/x86/net/bpf_jit_comp.c
26432 +++ b/arch/x86/net/bpf_jit_comp.c
26433 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
26434 set_fs(old_fs);
26435 }
26436
26437 +struct bpf_jit_work {
26438 + struct work_struct work;
26439 + void *image;
26440 +};
26441
26442 void bpf_jit_compile(struct sk_filter *fp)
26443 {
26444 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26445 if (addrs == NULL)
26446 return;
26447
26448 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26449 + if (!fp->work)
26450 + goto out;
26451 +
26452 /* Before first pass, make a rough estimation of addrs[]
26453 * each bpf instruction is translated to less than 64 bytes
26454 */
26455 @@ -477,7 +485,7 @@ void bpf_jit_compile(struct sk_filter *fp)
26456 common_load: seen |= SEEN_DATAREF;
26457 if ((int)K < 0) {
26458 /* Abort the JIT because __load_pointer() is needed. */
26459 - goto out;
26460 + goto error;
26461 }
26462 t_offset = func - (image + addrs[i]);
26463 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
26464 @@ -492,7 +500,7 @@ common_load: seen |= SEEN_DATAREF;
26465 case BPF_S_LDX_B_MSH:
26466 if ((int)K < 0) {
26467 /* Abort the JIT because __load_pointer() is needed. */
26468 - goto out;
26469 + goto error;
26470 }
26471 seen |= SEEN_DATAREF | SEEN_XREG;
26472 t_offset = sk_load_byte_msh - (image + addrs[i]);
26473 @@ -582,17 +590,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26474 break;
26475 default:
26476 /* hmm, too complex filter, give up with jit compiler */
26477 - goto out;
26478 + goto error;
26479 }
26480 ilen = prog - temp;
26481 if (image) {
26482 if (unlikely(proglen + ilen > oldproglen)) {
26483 pr_err("bpb_jit_compile fatal error\n");
26484 - kfree(addrs);
26485 - module_free(NULL, image);
26486 - return;
26487 + module_free_exec(NULL, image);
26488 + goto error;
26489 }
26490 + pax_open_kernel();
26491 memcpy(image + proglen, temp, ilen);
26492 + pax_close_kernel();
26493 }
26494 proglen += ilen;
26495 addrs[i] = proglen;
26496 @@ -613,11 +622,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26497 break;
26498 }
26499 if (proglen == oldproglen) {
26500 - image = module_alloc(max_t(unsigned int,
26501 - proglen,
26502 - sizeof(struct work_struct)));
26503 + image = module_alloc_exec(proglen);
26504 if (!image)
26505 - goto out;
26506 + goto error;
26507 }
26508 oldproglen = proglen;
26509 }
26510 @@ -633,7 +640,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26511 bpf_flush_icache(image, image + proglen);
26512
26513 fp->bpf_func = (void *)image;
26514 - }
26515 + } else
26516 +error:
26517 + kfree(fp->work);
26518 +
26519 out:
26520 kfree(addrs);
26521 return;
26522 @@ -641,18 +651,20 @@ out:
26523
26524 static void jit_free_defer(struct work_struct *arg)
26525 {
26526 - module_free(NULL, arg);
26527 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26528 + kfree(arg);
26529 }
26530
26531 /* run from softirq, we must use a work_struct to call
26532 - * module_free() from process context
26533 + * module_free_exec() from process context
26534 */
26535 void bpf_jit_free(struct sk_filter *fp)
26536 {
26537 if (fp->bpf_func != sk_run_filter) {
26538 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26539 + struct work_struct *work = &fp->work->work;
26540
26541 INIT_WORK(work, jit_free_defer);
26542 + fp->work->image = fp->bpf_func;
26543 schedule_work(work);
26544 }
26545 }
26546 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26547 index bff89df..377758a 100644
26548 --- a/arch/x86/oprofile/backtrace.c
26549 +++ b/arch/x86/oprofile/backtrace.c
26550 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26551 struct stack_frame_ia32 *fp;
26552 unsigned long bytes;
26553
26554 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26555 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26556 if (bytes != sizeof(bufhead))
26557 return NULL;
26558
26559 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26560 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26561
26562 oprofile_add_trace(bufhead[0].return_address);
26563
26564 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26565 struct stack_frame bufhead[2];
26566 unsigned long bytes;
26567
26568 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26569 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26570 if (bytes != sizeof(bufhead))
26571 return NULL;
26572
26573 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26574 {
26575 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26576
26577 - if (!user_mode_vm(regs)) {
26578 + if (!user_mode(regs)) {
26579 unsigned long stack = kernel_stack_pointer(regs);
26580 if (depth)
26581 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26582 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26583 index cb29191..036766d 100644
26584 --- a/arch/x86/pci/mrst.c
26585 +++ b/arch/x86/pci/mrst.c
26586 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
26587 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
26588 pci_mmcfg_late_init();
26589 pcibios_enable_irq = mrst_pci_irq_enable;
26590 - pci_root_ops = pci_mrst_ops;
26591 + pax_open_kernel();
26592 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26593 + pax_close_kernel();
26594 /* Continue with standard init */
26595 return 1;
26596 }
26597 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26598 index da8fe05..7ee6704 100644
26599 --- a/arch/x86/pci/pcbios.c
26600 +++ b/arch/x86/pci/pcbios.c
26601 @@ -79,50 +79,93 @@ union bios32 {
26602 static struct {
26603 unsigned long address;
26604 unsigned short segment;
26605 -} bios32_indirect = { 0, __KERNEL_CS };
26606 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26607
26608 /*
26609 * Returns the entry point for the given service, NULL on error
26610 */
26611
26612 -static unsigned long bios32_service(unsigned long service)
26613 +static unsigned long __devinit bios32_service(unsigned long service)
26614 {
26615 unsigned char return_code; /* %al */
26616 unsigned long address; /* %ebx */
26617 unsigned long length; /* %ecx */
26618 unsigned long entry; /* %edx */
26619 unsigned long flags;
26620 + struct desc_struct d, *gdt;
26621
26622 local_irq_save(flags);
26623 - __asm__("lcall *(%%edi); cld"
26624 +
26625 + gdt = get_cpu_gdt_table(smp_processor_id());
26626 +
26627 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26628 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26629 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26630 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26631 +
26632 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26633 : "=a" (return_code),
26634 "=b" (address),
26635 "=c" (length),
26636 "=d" (entry)
26637 : "0" (service),
26638 "1" (0),
26639 - "D" (&bios32_indirect));
26640 + "D" (&bios32_indirect),
26641 + "r"(__PCIBIOS_DS)
26642 + : "memory");
26643 +
26644 + pax_open_kernel();
26645 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26646 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26647 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26648 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26649 + pax_close_kernel();
26650 +
26651 local_irq_restore(flags);
26652
26653 switch (return_code) {
26654 - case 0:
26655 - return address + entry;
26656 - case 0x80: /* Not present */
26657 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26658 - return 0;
26659 - default: /* Shouldn't happen */
26660 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26661 - service, return_code);
26662 + case 0: {
26663 + int cpu;
26664 + unsigned char flags;
26665 +
26666 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26667 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26668 + printk(KERN_WARNING "bios32_service: not valid\n");
26669 return 0;
26670 + }
26671 + address = address + PAGE_OFFSET;
26672 + length += 16UL; /* some BIOSs underreport this... */
26673 + flags = 4;
26674 + if (length >= 64*1024*1024) {
26675 + length >>= PAGE_SHIFT;
26676 + flags |= 8;
26677 + }
26678 +
26679 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26680 + gdt = get_cpu_gdt_table(cpu);
26681 + pack_descriptor(&d, address, length, 0x9b, flags);
26682 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26683 + pack_descriptor(&d, address, length, 0x93, flags);
26684 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26685 + }
26686 + return entry;
26687 + }
26688 + case 0x80: /* Not present */
26689 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26690 + return 0;
26691 + default: /* Shouldn't happen */
26692 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26693 + service, return_code);
26694 + return 0;
26695 }
26696 }
26697
26698 static struct {
26699 unsigned long address;
26700 unsigned short segment;
26701 -} pci_indirect = { 0, __KERNEL_CS };
26702 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26703
26704 -static int pci_bios_present;
26705 +static int pci_bios_present __read_only;
26706
26707 static int __devinit check_pcibios(void)
26708 {
26709 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26710 unsigned long flags, pcibios_entry;
26711
26712 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26713 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26714 + pci_indirect.address = pcibios_entry;
26715
26716 local_irq_save(flags);
26717 - __asm__(
26718 - "lcall *(%%edi); cld\n\t"
26719 + __asm__("movw %w6, %%ds\n\t"
26720 + "lcall *%%ss:(%%edi); cld\n\t"
26721 + "push %%ss\n\t"
26722 + "pop %%ds\n\t"
26723 "jc 1f\n\t"
26724 "xor %%ah, %%ah\n"
26725 "1:"
26726 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26727 "=b" (ebx),
26728 "=c" (ecx)
26729 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26730 - "D" (&pci_indirect)
26731 + "D" (&pci_indirect),
26732 + "r" (__PCIBIOS_DS)
26733 : "memory");
26734 local_irq_restore(flags);
26735
26736 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26737
26738 switch (len) {
26739 case 1:
26740 - __asm__("lcall *(%%esi); cld\n\t"
26741 + __asm__("movw %w6, %%ds\n\t"
26742 + "lcall *%%ss:(%%esi); cld\n\t"
26743 + "push %%ss\n\t"
26744 + "pop %%ds\n\t"
26745 "jc 1f\n\t"
26746 "xor %%ah, %%ah\n"
26747 "1:"
26748 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26749 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26750 "b" (bx),
26751 "D" ((long)reg),
26752 - "S" (&pci_indirect));
26753 + "S" (&pci_indirect),
26754 + "r" (__PCIBIOS_DS));
26755 /*
26756 * Zero-extend the result beyond 8 bits, do not trust the
26757 * BIOS having done it:
26758 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26759 *value &= 0xff;
26760 break;
26761 case 2:
26762 - __asm__("lcall *(%%esi); cld\n\t"
26763 + __asm__("movw %w6, %%ds\n\t"
26764 + "lcall *%%ss:(%%esi); cld\n\t"
26765 + "push %%ss\n\t"
26766 + "pop %%ds\n\t"
26767 "jc 1f\n\t"
26768 "xor %%ah, %%ah\n"
26769 "1:"
26770 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26771 : "1" (PCIBIOS_READ_CONFIG_WORD),
26772 "b" (bx),
26773 "D" ((long)reg),
26774 - "S" (&pci_indirect));
26775 + "S" (&pci_indirect),
26776 + "r" (__PCIBIOS_DS));
26777 /*
26778 * Zero-extend the result beyond 16 bits, do not trust the
26779 * BIOS having done it:
26780 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26781 *value &= 0xffff;
26782 break;
26783 case 4:
26784 - __asm__("lcall *(%%esi); cld\n\t"
26785 + __asm__("movw %w6, %%ds\n\t"
26786 + "lcall *%%ss:(%%esi); cld\n\t"
26787 + "push %%ss\n\t"
26788 + "pop %%ds\n\t"
26789 "jc 1f\n\t"
26790 "xor %%ah, %%ah\n"
26791 "1:"
26792 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26793 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26794 "b" (bx),
26795 "D" ((long)reg),
26796 - "S" (&pci_indirect));
26797 + "S" (&pci_indirect),
26798 + "r" (__PCIBIOS_DS));
26799 break;
26800 }
26801
26802 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26803
26804 switch (len) {
26805 case 1:
26806 - __asm__("lcall *(%%esi); cld\n\t"
26807 + __asm__("movw %w6, %%ds\n\t"
26808 + "lcall *%%ss:(%%esi); cld\n\t"
26809 + "push %%ss\n\t"
26810 + "pop %%ds\n\t"
26811 "jc 1f\n\t"
26812 "xor %%ah, %%ah\n"
26813 "1:"
26814 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26815 "c" (value),
26816 "b" (bx),
26817 "D" ((long)reg),
26818 - "S" (&pci_indirect));
26819 + "S" (&pci_indirect),
26820 + "r" (__PCIBIOS_DS));
26821 break;
26822 case 2:
26823 - __asm__("lcall *(%%esi); cld\n\t"
26824 + __asm__("movw %w6, %%ds\n\t"
26825 + "lcall *%%ss:(%%esi); cld\n\t"
26826 + "push %%ss\n\t"
26827 + "pop %%ds\n\t"
26828 "jc 1f\n\t"
26829 "xor %%ah, %%ah\n"
26830 "1:"
26831 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26832 "c" (value),
26833 "b" (bx),
26834 "D" ((long)reg),
26835 - "S" (&pci_indirect));
26836 + "S" (&pci_indirect),
26837 + "r" (__PCIBIOS_DS));
26838 break;
26839 case 4:
26840 - __asm__("lcall *(%%esi); cld\n\t"
26841 + __asm__("movw %w6, %%ds\n\t"
26842 + "lcall *%%ss:(%%esi); cld\n\t"
26843 + "push %%ss\n\t"
26844 + "pop %%ds\n\t"
26845 "jc 1f\n\t"
26846 "xor %%ah, %%ah\n"
26847 "1:"
26848 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26849 "c" (value),
26850 "b" (bx),
26851 "D" ((long)reg),
26852 - "S" (&pci_indirect));
26853 + "S" (&pci_indirect),
26854 + "r" (__PCIBIOS_DS));
26855 break;
26856 }
26857
26858 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26859
26860 DBG("PCI: Fetching IRQ routing table... ");
26861 __asm__("push %%es\n\t"
26862 + "movw %w8, %%ds\n\t"
26863 "push %%ds\n\t"
26864 "pop %%es\n\t"
26865 - "lcall *(%%esi); cld\n\t"
26866 + "lcall *%%ss:(%%esi); cld\n\t"
26867 "pop %%es\n\t"
26868 + "push %%ss\n\t"
26869 + "pop %%ds\n"
26870 "jc 1f\n\t"
26871 "xor %%ah, %%ah\n"
26872 "1:"
26873 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26874 "1" (0),
26875 "D" ((long) &opt),
26876 "S" (&pci_indirect),
26877 - "m" (opt)
26878 + "m" (opt),
26879 + "r" (__PCIBIOS_DS)
26880 : "memory");
26881 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26882 if (ret & 0xff00)
26883 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26884 {
26885 int ret;
26886
26887 - __asm__("lcall *(%%esi); cld\n\t"
26888 + __asm__("movw %w5, %%ds\n\t"
26889 + "lcall *%%ss:(%%esi); cld\n\t"
26890 + "push %%ss\n\t"
26891 + "pop %%ds\n"
26892 "jc 1f\n\t"
26893 "xor %%ah, %%ah\n"
26894 "1:"
26895 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26896 : "0" (PCIBIOS_SET_PCI_HW_INT),
26897 "b" ((dev->bus->number << 8) | dev->devfn),
26898 "c" ((irq << 8) | (pin + 10)),
26899 - "S" (&pci_indirect));
26900 + "S" (&pci_indirect),
26901 + "r" (__PCIBIOS_DS));
26902 return !(ret & 0xff00);
26903 }
26904 EXPORT_SYMBOL(pcibios_set_irq_routing);
26905 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26906 index 40e4469..1ab536e 100644
26907 --- a/arch/x86/platform/efi/efi_32.c
26908 +++ b/arch/x86/platform/efi/efi_32.c
26909 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26910 {
26911 struct desc_ptr gdt_descr;
26912
26913 +#ifdef CONFIG_PAX_KERNEXEC
26914 + struct desc_struct d;
26915 +#endif
26916 +
26917 local_irq_save(efi_rt_eflags);
26918
26919 load_cr3(initial_page_table);
26920 __flush_tlb_all();
26921
26922 +#ifdef CONFIG_PAX_KERNEXEC
26923 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26924 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26925 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26926 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26927 +#endif
26928 +
26929 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26930 gdt_descr.size = GDT_SIZE - 1;
26931 load_gdt(&gdt_descr);
26932 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26933 {
26934 struct desc_ptr gdt_descr;
26935
26936 +#ifdef CONFIG_PAX_KERNEXEC
26937 + struct desc_struct d;
26938 +
26939 + memset(&d, 0, sizeof d);
26940 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26941 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26942 +#endif
26943 +
26944 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26945 gdt_descr.size = GDT_SIZE - 1;
26946 load_gdt(&gdt_descr);
26947 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26948 index fbe66e6..c5c0dd2 100644
26949 --- a/arch/x86/platform/efi/efi_stub_32.S
26950 +++ b/arch/x86/platform/efi/efi_stub_32.S
26951 @@ -6,7 +6,9 @@
26952 */
26953
26954 #include <linux/linkage.h>
26955 +#include <linux/init.h>
26956 #include <asm/page_types.h>
26957 +#include <asm/segment.h>
26958
26959 /*
26960 * efi_call_phys(void *, ...) is a function with variable parameters.
26961 @@ -20,7 +22,7 @@
26962 * service functions will comply with gcc calling convention, too.
26963 */
26964
26965 -.text
26966 +__INIT
26967 ENTRY(efi_call_phys)
26968 /*
26969 * 0. The function can only be called in Linux kernel. So CS has been
26970 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26971 * The mapping of lower virtual memory has been created in prelog and
26972 * epilog.
26973 */
26974 - movl $1f, %edx
26975 - subl $__PAGE_OFFSET, %edx
26976 - jmp *%edx
26977 + movl $(__KERNEXEC_EFI_DS), %edx
26978 + mov %edx, %ds
26979 + mov %edx, %es
26980 + mov %edx, %ss
26981 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26982 1:
26983
26984 /*
26985 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26986 * parameter 2, ..., param n. To make things easy, we save the return
26987 * address of efi_call_phys in a global variable.
26988 */
26989 - popl %edx
26990 - movl %edx, saved_return_addr
26991 - /* get the function pointer into ECX*/
26992 - popl %ecx
26993 - movl %ecx, efi_rt_function_ptr
26994 - movl $2f, %edx
26995 - subl $__PAGE_OFFSET, %edx
26996 - pushl %edx
26997 + popl (saved_return_addr)
26998 + popl (efi_rt_function_ptr)
26999
27000 /*
27001 * 3. Clear PG bit in %CR0.
27002 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
27003 /*
27004 * 5. Call the physical function.
27005 */
27006 - jmp *%ecx
27007 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
27008
27009 -2:
27010 /*
27011 * 6. After EFI runtime service returns, control will return to
27012 * following instruction. We'd better readjust stack pointer first.
27013 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
27014 movl %cr0, %edx
27015 orl $0x80000000, %edx
27016 movl %edx, %cr0
27017 - jmp 1f
27018 -1:
27019 +
27020 /*
27021 * 8. Now restore the virtual mode from flat mode by
27022 * adding EIP with PAGE_OFFSET.
27023 */
27024 - movl $1f, %edx
27025 - jmp *%edx
27026 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
27027 1:
27028 + movl $(__KERNEL_DS), %edx
27029 + mov %edx, %ds
27030 + mov %edx, %es
27031 + mov %edx, %ss
27032
27033 /*
27034 * 9. Balance the stack. And because EAX contain the return value,
27035 * we'd better not clobber it.
27036 */
27037 - leal efi_rt_function_ptr, %edx
27038 - movl (%edx), %ecx
27039 - pushl %ecx
27040 + pushl (efi_rt_function_ptr)
27041
27042 /*
27043 - * 10. Push the saved return address onto the stack and return.
27044 + * 10. Return to the saved return address.
27045 */
27046 - leal saved_return_addr, %edx
27047 - movl (%edx), %ecx
27048 - pushl %ecx
27049 - ret
27050 + jmpl *(saved_return_addr)
27051 ENDPROC(efi_call_phys)
27052 .previous
27053
27054 -.data
27055 +__INITDATA
27056 saved_return_addr:
27057 .long 0
27058 efi_rt_function_ptr:
27059 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
27060 index 4c07cca..2c8427d 100644
27061 --- a/arch/x86/platform/efi/efi_stub_64.S
27062 +++ b/arch/x86/platform/efi/efi_stub_64.S
27063 @@ -7,6 +7,7 @@
27064 */
27065
27066 #include <linux/linkage.h>
27067 +#include <asm/alternative-asm.h>
27068
27069 #define SAVE_XMM \
27070 mov %rsp, %rax; \
27071 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
27072 call *%rdi
27073 addq $32, %rsp
27074 RESTORE_XMM
27075 + pax_force_retaddr 0, 1
27076 ret
27077 ENDPROC(efi_call0)
27078
27079 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
27080 call *%rdi
27081 addq $32, %rsp
27082 RESTORE_XMM
27083 + pax_force_retaddr 0, 1
27084 ret
27085 ENDPROC(efi_call1)
27086
27087 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
27088 call *%rdi
27089 addq $32, %rsp
27090 RESTORE_XMM
27091 + pax_force_retaddr 0, 1
27092 ret
27093 ENDPROC(efi_call2)
27094
27095 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
27096 call *%rdi
27097 addq $32, %rsp
27098 RESTORE_XMM
27099 + pax_force_retaddr 0, 1
27100 ret
27101 ENDPROC(efi_call3)
27102
27103 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
27104 call *%rdi
27105 addq $32, %rsp
27106 RESTORE_XMM
27107 + pax_force_retaddr 0, 1
27108 ret
27109 ENDPROC(efi_call4)
27110
27111 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
27112 call *%rdi
27113 addq $48, %rsp
27114 RESTORE_XMM
27115 + pax_force_retaddr 0, 1
27116 ret
27117 ENDPROC(efi_call5)
27118
27119 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
27120 call *%rdi
27121 addq $48, %rsp
27122 RESTORE_XMM
27123 + pax_force_retaddr 0, 1
27124 ret
27125 ENDPROC(efi_call6)
27126 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
27127 index 475e2cd..1b8e708 100644
27128 --- a/arch/x86/platform/mrst/mrst.c
27129 +++ b/arch/x86/platform/mrst/mrst.c
27130 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
27131 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
27132 int sfi_mrtc_num;
27133
27134 -static void mrst_power_off(void)
27135 +static __noreturn void mrst_power_off(void)
27136 {
27137 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
27138 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
27139 + BUG();
27140 }
27141
27142 -static void mrst_reboot(void)
27143 +static __noreturn void mrst_reboot(void)
27144 {
27145 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
27146 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
27147 else
27148 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
27149 + BUG();
27150 }
27151
27152 /* parse all the mtimer info to a static mtimer array */
27153 diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
27154 index 3ae0e61..4202d86 100644
27155 --- a/arch/x86/platform/uv/tlb_uv.c
27156 +++ b/arch/x86/platform/uv/tlb_uv.c
27157 @@ -1424,6 +1424,8 @@ static ssize_t tunables_read(struct file *file, char __user *userbuf,
27158 * 0: display meaning of the statistics
27159 */
27160 static ssize_t ptc_proc_write(struct file *file, const char __user *user,
27161 + size_t count, loff_t *data) __size_overflow(3);
27162 +static ssize_t ptc_proc_write(struct file *file, const char __user *user,
27163 size_t count, loff_t *data)
27164 {
27165 int cpu;
27166 @@ -1539,6 +1541,8 @@ static int parse_tunables_write(struct bau_control *bcp, char *instr,
27167 * Handle a write to debugfs. (/sys/kernel/debug/sgi_uv/bau_tunables)
27168 */
27169 static ssize_t tunables_write(struct file *file, const char __user *user,
27170 + size_t count, loff_t *data) __size_overflow(3);
27171 +static ssize_t tunables_write(struct file *file, const char __user *user,
27172 size_t count, loff_t *data)
27173 {
27174 int cpu;
27175 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
27176 index f10c0af..3ec1f95 100644
27177 --- a/arch/x86/power/cpu.c
27178 +++ b/arch/x86/power/cpu.c
27179 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
27180 static void fix_processor_context(void)
27181 {
27182 int cpu = smp_processor_id();
27183 - struct tss_struct *t = &per_cpu(init_tss, cpu);
27184 + struct tss_struct *t = init_tss + cpu;
27185
27186 set_tss_desc(cpu, t); /*
27187 * This just modifies memory; should not be
27188 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
27189 */
27190
27191 #ifdef CONFIG_X86_64
27192 + pax_open_kernel();
27193 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
27194 + pax_close_kernel();
27195
27196 syscall_init(); /* This sets MSR_*STAR and related */
27197 #endif
27198 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27199 index 5d17950..2253fc9 100644
27200 --- a/arch/x86/vdso/Makefile
27201 +++ b/arch/x86/vdso/Makefile
27202 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
27203 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27204 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27205
27206 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27207 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27208 GCOV_PROFILE := n
27209
27210 #
27211 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27212 index 468d591..8e80a0a 100644
27213 --- a/arch/x86/vdso/vdso32-setup.c
27214 +++ b/arch/x86/vdso/vdso32-setup.c
27215 @@ -25,6 +25,7 @@
27216 #include <asm/tlbflush.h>
27217 #include <asm/vdso.h>
27218 #include <asm/proto.h>
27219 +#include <asm/mman.h>
27220
27221 enum {
27222 VDSO_DISABLED = 0,
27223 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27224 void enable_sep_cpu(void)
27225 {
27226 int cpu = get_cpu();
27227 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27228 + struct tss_struct *tss = init_tss + cpu;
27229
27230 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27231 put_cpu();
27232 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27233 gate_vma.vm_start = FIXADDR_USER_START;
27234 gate_vma.vm_end = FIXADDR_USER_END;
27235 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27236 - gate_vma.vm_page_prot = __P101;
27237 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27238 /*
27239 * Make sure the vDSO gets into every core dump.
27240 * Dumping its contents makes post-mortem fully interpretable later
27241 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27242 if (compat)
27243 addr = VDSO_HIGH_BASE;
27244 else {
27245 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27246 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27247 if (IS_ERR_VALUE(addr)) {
27248 ret = addr;
27249 goto up_fail;
27250 }
27251 }
27252
27253 - current->mm->context.vdso = (void *)addr;
27254 + current->mm->context.vdso = addr;
27255
27256 if (compat_uses_vma || !compat) {
27257 /*
27258 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27259 }
27260
27261 current_thread_info()->sysenter_return =
27262 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27263 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27264
27265 up_fail:
27266 if (ret)
27267 - current->mm->context.vdso = NULL;
27268 + current->mm->context.vdso = 0;
27269
27270 up_write(&mm->mmap_sem);
27271
27272 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
27273
27274 const char *arch_vma_name(struct vm_area_struct *vma)
27275 {
27276 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27277 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27278 return "[vdso]";
27279 +
27280 +#ifdef CONFIG_PAX_SEGMEXEC
27281 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27282 + return "[vdso]";
27283 +#endif
27284 +
27285 return NULL;
27286 }
27287
27288 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27289 * Check to see if the corresponding task was created in compat vdso
27290 * mode.
27291 */
27292 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27293 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27294 return &gate_vma;
27295 return NULL;
27296 }
27297 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27298 index 153407c..611cba9 100644
27299 --- a/arch/x86/vdso/vma.c
27300 +++ b/arch/x86/vdso/vma.c
27301 @@ -16,8 +16,6 @@
27302 #include <asm/vdso.h>
27303 #include <asm/page.h>
27304
27305 -unsigned int __read_mostly vdso_enabled = 1;
27306 -
27307 extern char vdso_start[], vdso_end[];
27308 extern unsigned short vdso_sync_cpuid;
27309
27310 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27311 * unaligned here as a result of stack start randomization.
27312 */
27313 addr = PAGE_ALIGN(addr);
27314 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27315
27316 return addr;
27317 }
27318 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27319 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27320 {
27321 struct mm_struct *mm = current->mm;
27322 - unsigned long addr;
27323 + unsigned long addr = 0;
27324 int ret;
27325
27326 - if (!vdso_enabled)
27327 - return 0;
27328 -
27329 down_write(&mm->mmap_sem);
27330 +
27331 +#ifdef CONFIG_PAX_RANDMMAP
27332 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27333 +#endif
27334 +
27335 addr = vdso_addr(mm->start_stack, vdso_size);
27336 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27337 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
27338 if (IS_ERR_VALUE(addr)) {
27339 ret = addr;
27340 goto up_fail;
27341 }
27342
27343 - current->mm->context.vdso = (void *)addr;
27344 + mm->context.vdso = addr;
27345
27346 ret = install_special_mapping(mm, addr, vdso_size,
27347 VM_READ|VM_EXEC|
27348 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
27349 VM_ALWAYSDUMP,
27350 vdso_pages);
27351 - if (ret) {
27352 - current->mm->context.vdso = NULL;
27353 - goto up_fail;
27354 - }
27355 +
27356 + if (ret)
27357 + mm->context.vdso = 0;
27358
27359 up_fail:
27360 up_write(&mm->mmap_sem);
27361 return ret;
27362 }
27363 -
27364 -static __init int vdso_setup(char *s)
27365 -{
27366 - vdso_enabled = simple_strtoul(s, NULL, 0);
27367 - return 0;
27368 -}
27369 -__setup("vdso=", vdso_setup);
27370 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27371 index 4e517d4..68a48f5 100644
27372 --- a/arch/x86/xen/enlighten.c
27373 +++ b/arch/x86/xen/enlighten.c
27374 @@ -86,8 +86,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27375
27376 struct shared_info xen_dummy_shared_info;
27377
27378 -void *xen_initial_gdt;
27379 -
27380 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27381 __read_mostly int xen_have_vector_callback;
27382 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27383 @@ -1030,30 +1028,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27384 #endif
27385 };
27386
27387 -static void xen_reboot(int reason)
27388 +static __noreturn void xen_reboot(int reason)
27389 {
27390 struct sched_shutdown r = { .reason = reason };
27391
27392 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27393 - BUG();
27394 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27395 + BUG();
27396 }
27397
27398 -static void xen_restart(char *msg)
27399 +static __noreturn void xen_restart(char *msg)
27400 {
27401 xen_reboot(SHUTDOWN_reboot);
27402 }
27403
27404 -static void xen_emergency_restart(void)
27405 +static __noreturn void xen_emergency_restart(void)
27406 {
27407 xen_reboot(SHUTDOWN_reboot);
27408 }
27409
27410 -static void xen_machine_halt(void)
27411 +static __noreturn void xen_machine_halt(void)
27412 {
27413 xen_reboot(SHUTDOWN_poweroff);
27414 }
27415
27416 -static void xen_machine_power_off(void)
27417 +static __noreturn void xen_machine_power_off(void)
27418 {
27419 if (pm_power_off)
27420 pm_power_off();
27421 @@ -1156,7 +1154,17 @@ asmlinkage void __init xen_start_kernel(void)
27422 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27423
27424 /* Work out if we support NX */
27425 - x86_configure_nx();
27426 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27427 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27428 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27429 + unsigned l, h;
27430 +
27431 + __supported_pte_mask |= _PAGE_NX;
27432 + rdmsr(MSR_EFER, l, h);
27433 + l |= EFER_NX;
27434 + wrmsr(MSR_EFER, l, h);
27435 + }
27436 +#endif
27437
27438 xen_setup_features();
27439
27440 @@ -1187,13 +1195,6 @@ asmlinkage void __init xen_start_kernel(void)
27441
27442 machine_ops = xen_machine_ops;
27443
27444 - /*
27445 - * The only reliable way to retain the initial address of the
27446 - * percpu gdt_page is to remember it here, so we can go and
27447 - * mark it RW later, when the initial percpu area is freed.
27448 - */
27449 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27450 -
27451 xen_smp_init();
27452
27453 #ifdef CONFIG_ACPI_NUMA
27454 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27455 index dc19347..1b07a2c 100644
27456 --- a/arch/x86/xen/mmu.c
27457 +++ b/arch/x86/xen/mmu.c
27458 @@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27459 convert_pfn_mfn(init_level4_pgt);
27460 convert_pfn_mfn(level3_ident_pgt);
27461 convert_pfn_mfn(level3_kernel_pgt);
27462 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27463 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27464 + convert_pfn_mfn(level3_vmemmap_pgt);
27465
27466 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27467 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27468 @@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27469 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27470 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27471 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27472 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27473 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27474 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27475 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27476 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27477 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27478 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27479
27480 @@ -1963,6 +1970,7 @@ static void __init xen_post_allocator_init(void)
27481 pv_mmu_ops.set_pud = xen_set_pud;
27482 #if PAGETABLE_LEVELS == 4
27483 pv_mmu_ops.set_pgd = xen_set_pgd;
27484 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27485 #endif
27486
27487 /* This will work as long as patching hasn't happened yet
27488 @@ -2044,6 +2052,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27489 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27490 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27491 .set_pgd = xen_set_pgd_hyper,
27492 + .set_pgd_batched = xen_set_pgd_hyper,
27493
27494 .alloc_pud = xen_alloc_pmd_init,
27495 .release_pud = xen_release_pmd_init,
27496 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27497 index f2ce60a..14e08dc 100644
27498 --- a/arch/x86/xen/smp.c
27499 +++ b/arch/x86/xen/smp.c
27500 @@ -209,11 +209,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27501 {
27502 BUG_ON(smp_processor_id() != 0);
27503 native_smp_prepare_boot_cpu();
27504 -
27505 - /* We've switched to the "real" per-cpu gdt, so make sure the
27506 - old memory can be recycled */
27507 - make_lowmem_page_readwrite(xen_initial_gdt);
27508 -
27509 xen_filter_cpu_maps();
27510 xen_setup_vcpu_info_placement();
27511 }
27512 @@ -290,12 +285,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27513 gdt = get_cpu_gdt_table(cpu);
27514
27515 ctxt->flags = VGCF_IN_KERNEL;
27516 - ctxt->user_regs.ds = __USER_DS;
27517 - ctxt->user_regs.es = __USER_DS;
27518 + ctxt->user_regs.ds = __KERNEL_DS;
27519 + ctxt->user_regs.es = __KERNEL_DS;
27520 ctxt->user_regs.ss = __KERNEL_DS;
27521 #ifdef CONFIG_X86_32
27522 ctxt->user_regs.fs = __KERNEL_PERCPU;
27523 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27524 + savesegment(gs, ctxt->user_regs.gs);
27525 #else
27526 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27527 #endif
27528 @@ -346,13 +341,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27529 int rc;
27530
27531 per_cpu(current_task, cpu) = idle;
27532 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27533 #ifdef CONFIG_X86_32
27534 irq_ctx_init(cpu);
27535 #else
27536 clear_tsk_thread_flag(idle, TIF_FORK);
27537 - per_cpu(kernel_stack, cpu) =
27538 - (unsigned long)task_stack_page(idle) -
27539 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27540 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27541 #endif
27542 xen_setup_runstate_info(cpu);
27543 xen_setup_timer(cpu);
27544 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27545 index b040b0e..8cc4fe0 100644
27546 --- a/arch/x86/xen/xen-asm_32.S
27547 +++ b/arch/x86/xen/xen-asm_32.S
27548 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
27549 ESP_OFFSET=4 # bytes pushed onto stack
27550
27551 /*
27552 - * Store vcpu_info pointer for easy access. Do it this way to
27553 - * avoid having to reload %fs
27554 + * Store vcpu_info pointer for easy access.
27555 */
27556 #ifdef CONFIG_SMP
27557 - GET_THREAD_INFO(%eax)
27558 - movl TI_cpu(%eax), %eax
27559 - movl __per_cpu_offset(,%eax,4), %eax
27560 - mov xen_vcpu(%eax), %eax
27561 + push %fs
27562 + mov $(__KERNEL_PERCPU), %eax
27563 + mov %eax, %fs
27564 + mov PER_CPU_VAR(xen_vcpu), %eax
27565 + pop %fs
27566 #else
27567 movl xen_vcpu, %eax
27568 #endif
27569 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27570 index aaa7291..3f77960 100644
27571 --- a/arch/x86/xen/xen-head.S
27572 +++ b/arch/x86/xen/xen-head.S
27573 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27574 #ifdef CONFIG_X86_32
27575 mov %esi,xen_start_info
27576 mov $init_thread_union+THREAD_SIZE,%esp
27577 +#ifdef CONFIG_SMP
27578 + movl $cpu_gdt_table,%edi
27579 + movl $__per_cpu_load,%eax
27580 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27581 + rorl $16,%eax
27582 + movb %al,__KERNEL_PERCPU + 4(%edi)
27583 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27584 + movl $__per_cpu_end - 1,%eax
27585 + subl $__per_cpu_start,%eax
27586 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27587 +#endif
27588 #else
27589 mov %rsi,xen_start_info
27590 mov $init_thread_union+THREAD_SIZE,%rsp
27591 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27592 index b095739..8c17bcd 100644
27593 --- a/arch/x86/xen/xen-ops.h
27594 +++ b/arch/x86/xen/xen-ops.h
27595 @@ -10,8 +10,6 @@
27596 extern const char xen_hypervisor_callback[];
27597 extern const char xen_failsafe_callback[];
27598
27599 -extern void *xen_initial_gdt;
27600 -
27601 struct trap_info;
27602 void xen_copy_trap_info(struct trap_info *traps);
27603
27604 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27605 index 525bd3d..ef888b1 100644
27606 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27607 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27608 @@ -119,9 +119,9 @@
27609 ----------------------------------------------------------------------*/
27610
27611 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27612 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27613 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27614 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27615 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27616
27617 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27618 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27619 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27620 index 2f33760..835e50a 100644
27621 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27622 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27623 @@ -11,6 +11,7 @@
27624 #ifndef _XTENSA_CORE_H
27625 #define _XTENSA_CORE_H
27626
27627 +#include <linux/const.h>
27628
27629 /****************************************************************************
27630 Parameters Useful for Any Code, USER or PRIVILEGED
27631 @@ -112,9 +113,9 @@
27632 ----------------------------------------------------------------------*/
27633
27634 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27635 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27636 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27637 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27638 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27639
27640 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27641 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27642 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27643 index af00795..2bb8105 100644
27644 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27645 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27646 @@ -11,6 +11,7 @@
27647 #ifndef _XTENSA_CORE_CONFIGURATION_H
27648 #define _XTENSA_CORE_CONFIGURATION_H
27649
27650 +#include <linux/const.h>
27651
27652 /****************************************************************************
27653 Parameters Useful for Any Code, USER or PRIVILEGED
27654 @@ -118,9 +119,9 @@
27655 ----------------------------------------------------------------------*/
27656
27657 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27658 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27659 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27660 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27661 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27662
27663 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27664 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27665 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27666 index 58916af..9cb880b 100644
27667 --- a/block/blk-iopoll.c
27668 +++ b/block/blk-iopoll.c
27669 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27670 }
27671 EXPORT_SYMBOL(blk_iopoll_complete);
27672
27673 -static void blk_iopoll_softirq(struct softirq_action *h)
27674 +static void blk_iopoll_softirq(void)
27675 {
27676 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27677 int rearm = 0, budget = blk_iopoll_budget;
27678 diff --git a/block/blk-map.c b/block/blk-map.c
27679 index 623e1cd..ca1e109 100644
27680 --- a/block/blk-map.c
27681 +++ b/block/blk-map.c
27682 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27683 if (!len || !kbuf)
27684 return -EINVAL;
27685
27686 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27687 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27688 if (do_copy)
27689 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27690 else
27691 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27692 index 1366a89..e17f54b 100644
27693 --- a/block/blk-softirq.c
27694 +++ b/block/blk-softirq.c
27695 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27696 * Softirq action handler - move entries to local list and loop over them
27697 * while passing them to the queue registered handler.
27698 */
27699 -static void blk_done_softirq(struct softirq_action *h)
27700 +static void blk_done_softirq(void)
27701 {
27702 struct list_head *cpu_list, local_list;
27703
27704 diff --git a/block/bsg.c b/block/bsg.c
27705 index ff64ae3..593560c 100644
27706 --- a/block/bsg.c
27707 +++ b/block/bsg.c
27708 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27709 struct sg_io_v4 *hdr, struct bsg_device *bd,
27710 fmode_t has_write_perm)
27711 {
27712 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27713 + unsigned char *cmdptr;
27714 +
27715 if (hdr->request_len > BLK_MAX_CDB) {
27716 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27717 if (!rq->cmd)
27718 return -ENOMEM;
27719 - }
27720 + cmdptr = rq->cmd;
27721 + } else
27722 + cmdptr = tmpcmd;
27723
27724 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27725 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27726 hdr->request_len))
27727 return -EFAULT;
27728
27729 + if (cmdptr != rq->cmd)
27730 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27731 +
27732 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27733 if (blk_verify_command(rq->cmd, has_write_perm))
27734 return -EPERM;
27735 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27736 index 7c668c8..db3521c 100644
27737 --- a/block/compat_ioctl.c
27738 +++ b/block/compat_ioctl.c
27739 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27740 err |= __get_user(f->spec1, &uf->spec1);
27741 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27742 err |= __get_user(name, &uf->name);
27743 - f->name = compat_ptr(name);
27744 + f->name = (void __force_kernel *)compat_ptr(name);
27745 if (err) {
27746 err = -EFAULT;
27747 goto out;
27748 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27749 index 6296b40..417c00f 100644
27750 --- a/block/partitions/efi.c
27751 +++ b/block/partitions/efi.c
27752 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27753 if (!gpt)
27754 return NULL;
27755
27756 + if (!le32_to_cpu(gpt->num_partition_entries))
27757 + return NULL;
27758 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27759 + if (!pte)
27760 + return NULL;
27761 +
27762 count = le32_to_cpu(gpt->num_partition_entries) *
27763 le32_to_cpu(gpt->sizeof_partition_entry);
27764 - if (!count)
27765 - return NULL;
27766 - pte = kzalloc(count, GFP_KERNEL);
27767 - if (!pte)
27768 - return NULL;
27769 -
27770 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27771 (u8 *) pte,
27772 count) < count) {
27773 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27774 index 260fa80..e8f3caf 100644
27775 --- a/block/scsi_ioctl.c
27776 +++ b/block/scsi_ioctl.c
27777 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27778 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27779 struct sg_io_hdr *hdr, fmode_t mode)
27780 {
27781 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27782 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27783 + unsigned char *cmdptr;
27784 +
27785 + if (rq->cmd != rq->__cmd)
27786 + cmdptr = rq->cmd;
27787 + else
27788 + cmdptr = tmpcmd;
27789 +
27790 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27791 return -EFAULT;
27792 +
27793 + if (cmdptr != rq->cmd)
27794 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27795 +
27796 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27797 return -EPERM;
27798
27799 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27800 int err;
27801 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27802 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27803 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27804 + unsigned char *cmdptr;
27805
27806 if (!sic)
27807 return -EINVAL;
27808 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27809 */
27810 err = -EFAULT;
27811 rq->cmd_len = cmdlen;
27812 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27813 +
27814 + if (rq->cmd != rq->__cmd)
27815 + cmdptr = rq->cmd;
27816 + else
27817 + cmdptr = tmpcmd;
27818 +
27819 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27820 goto error;
27821
27822 + if (rq->cmd != cmdptr)
27823 + memcpy(rq->cmd, cmdptr, cmdlen);
27824 +
27825 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27826 goto error;
27827
27828 diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
27829 index a0f768c..1da9c73 100644
27830 --- a/crypto/ablkcipher.c
27831 +++ b/crypto/ablkcipher.c
27832 @@ -307,6 +307,8 @@ int ablkcipher_walk_phys(struct ablkcipher_request *req,
27833 EXPORT_SYMBOL_GPL(ablkcipher_walk_phys);
27834
27835 static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27836 + unsigned int keylen) __size_overflow(3);
27837 +static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27838 unsigned int keylen)
27839 {
27840 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27841 @@ -329,6 +331,8 @@ static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
27842 }
27843
27844 static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27845 + unsigned int keylen) __size_overflow(3);
27846 +static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
27847 unsigned int keylen)
27848 {
27849 struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
27850 diff --git a/crypto/aead.c b/crypto/aead.c
27851 index 04add3dc..983032f 100644
27852 --- a/crypto/aead.c
27853 +++ b/crypto/aead.c
27854 @@ -27,6 +27,8 @@
27855 #include "internal.h"
27856
27857 static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27858 + unsigned int keylen) __size_overflow(3);
27859 +static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27860 unsigned int keylen)
27861 {
27862 struct aead_alg *aead = crypto_aead_alg(tfm);
27863 @@ -48,6 +50,7 @@ static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
27864 return ret;
27865 }
27866
27867 +static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27868 static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
27869 {
27870 struct aead_alg *aead = crypto_aead_alg(tfm);
27871 diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
27872 index 1e61d1a..cf06b86 100644
27873 --- a/crypto/blkcipher.c
27874 +++ b/crypto/blkcipher.c
27875 @@ -359,6 +359,8 @@ int blkcipher_walk_virt_block(struct blkcipher_desc *desc,
27876 EXPORT_SYMBOL_GPL(blkcipher_walk_virt_block);
27877
27878 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27879 + unsigned int keylen) __size_overflow(3);
27880 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27881 unsigned int keylen)
27882 {
27883 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27884 @@ -380,6 +382,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27885 return ret;
27886 }
27887
27888 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27889 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27890 {
27891 struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
27892 diff --git a/crypto/cipher.c b/crypto/cipher.c
27893 index 39541e0..802d956 100644
27894 --- a/crypto/cipher.c
27895 +++ b/crypto/cipher.c
27896 @@ -21,6 +21,8 @@
27897 #include "internal.h"
27898
27899 static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27900 + unsigned int keylen) __size_overflow(3);
27901 +static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27902 unsigned int keylen)
27903 {
27904 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27905 @@ -43,6 +45,7 @@ static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key,
27906
27907 }
27908
27909 +static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) __size_overflow(3);
27910 static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
27911 {
27912 struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
27913 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27914 index 671d4d6..5f24030 100644
27915 --- a/crypto/cryptd.c
27916 +++ b/crypto/cryptd.c
27917 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27918
27919 struct cryptd_blkcipher_request_ctx {
27920 crypto_completion_t complete;
27921 -};
27922 +} __no_const;
27923
27924 struct cryptd_hash_ctx {
27925 struct crypto_shash *child;
27926 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27927
27928 struct cryptd_aead_request_ctx {
27929 crypto_completion_t complete;
27930 -};
27931 +} __no_const;
27932
27933 static void cryptd_queue_worker(struct work_struct *work);
27934
27935 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27936 index 5d41894..22021e4 100644
27937 --- a/drivers/acpi/apei/cper.c
27938 +++ b/drivers/acpi/apei/cper.c
27939 @@ -38,12 +38,12 @@
27940 */
27941 u64 cper_next_record_id(void)
27942 {
27943 - static atomic64_t seq;
27944 + static atomic64_unchecked_t seq;
27945
27946 - if (!atomic64_read(&seq))
27947 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27948 + if (!atomic64_read_unchecked(&seq))
27949 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27950
27951 - return atomic64_inc_return(&seq);
27952 + return atomic64_inc_return_unchecked(&seq);
27953 }
27954 EXPORT_SYMBOL_GPL(cper_next_record_id);
27955
27956 diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
27957 index 86933ca..5cb1a69 100644
27958 --- a/drivers/acpi/battery.c
27959 +++ b/drivers/acpi/battery.c
27960 @@ -787,6 +787,9 @@ static int acpi_battery_print_alarm(struct seq_file *seq, int result)
27961
27962 static ssize_t acpi_battery_write_alarm(struct file *file,
27963 const char __user * buffer,
27964 + size_t count, loff_t * ppos) __size_overflow(3);
27965 +static ssize_t acpi_battery_write_alarm(struct file *file,
27966 + const char __user * buffer,
27967 size_t count, loff_t * ppos)
27968 {
27969 int result = 0;
27970 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27971 index b258cab..3fb7da7 100644
27972 --- a/drivers/acpi/ec_sys.c
27973 +++ b/drivers/acpi/ec_sys.c
27974 @@ -12,6 +12,7 @@
27975 #include <linux/acpi.h>
27976 #include <linux/debugfs.h>
27977 #include <linux/module.h>
27978 +#include <linux/uaccess.h>
27979 #include "internal.h"
27980
27981 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27982 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27983 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27984 */
27985 unsigned int size = EC_SPACE_SIZE;
27986 - u8 *data = (u8 *) buf;
27987 + u8 data;
27988 loff_t init_off = *off;
27989 int err = 0;
27990
27991 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27992 size = count;
27993
27994 while (size) {
27995 - err = ec_read(*off, &data[*off - init_off]);
27996 + err = ec_read(*off, &data);
27997 if (err)
27998 return err;
27999 + if (put_user(data, &buf[*off - init_off]))
28000 + return -EFAULT;
28001 *off += 1;
28002 size--;
28003 }
28004 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28005
28006 unsigned int size = count;
28007 loff_t init_off = *off;
28008 - u8 *data = (u8 *) buf;
28009 int err = 0;
28010
28011 if (*off >= EC_SPACE_SIZE)
28012 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
28013 }
28014
28015 while (size) {
28016 - u8 byte_write = data[*off - init_off];
28017 + u8 byte_write;
28018 + if (get_user(byte_write, &buf[*off - init_off]))
28019 + return -EFAULT;
28020 err = ec_write(*off, byte_write);
28021 if (err)
28022 return err;
28023 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
28024 index 251c7b62..000462d 100644
28025 --- a/drivers/acpi/proc.c
28026 +++ b/drivers/acpi/proc.c
28027 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
28028 size_t count, loff_t * ppos)
28029 {
28030 struct list_head *node, *next;
28031 - char strbuf[5];
28032 - char str[5] = "";
28033 - unsigned int len = count;
28034 + char strbuf[5] = {0};
28035
28036 - if (len > 4)
28037 - len = 4;
28038 - if (len < 0)
28039 + if (count > 4)
28040 + count = 4;
28041 + if (copy_from_user(strbuf, buffer, count))
28042 return -EFAULT;
28043 -
28044 - if (copy_from_user(strbuf, buffer, len))
28045 - return -EFAULT;
28046 - strbuf[len] = '\0';
28047 - sscanf(strbuf, "%s", str);
28048 + strbuf[count] = '\0';
28049
28050 mutex_lock(&acpi_device_lock);
28051 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
28052 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
28053 if (!dev->wakeup.flags.valid)
28054 continue;
28055
28056 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
28057 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
28058 if (device_can_wakeup(&dev->dev)) {
28059 bool enable = !device_may_wakeup(&dev->dev);
28060 device_set_wakeup_enable(&dev->dev, enable);
28061 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
28062 index 8ae05ce..7dbbed9 100644
28063 --- a/drivers/acpi/processor_driver.c
28064 +++ b/drivers/acpi/processor_driver.c
28065 @@ -555,7 +555,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
28066 return 0;
28067 #endif
28068
28069 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
28070 + BUG_ON(pr->id >= nr_cpu_ids);
28071
28072 /*
28073 * Buggy BIOS check
28074 diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
28075 index 6e36d0c..f319944 100644
28076 --- a/drivers/acpi/sbs.c
28077 +++ b/drivers/acpi/sbs.c
28078 @@ -655,6 +655,9 @@ static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
28079
28080 static ssize_t
28081 acpi_battery_write_alarm(struct file *file, const char __user * buffer,
28082 + size_t count, loff_t * ppos) __size_overflow(3);
28083 +static ssize_t
28084 +acpi_battery_write_alarm(struct file *file, const char __user * buffer,
28085 size_t count, loff_t * ppos)
28086 {
28087 struct seq_file *seq = file->private_data;
28088 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
28089 index c06e0ec..a2c06ba 100644
28090 --- a/drivers/ata/libata-core.c
28091 +++ b/drivers/ata/libata-core.c
28092 @@ -4736,7 +4736,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
28093 struct ata_port *ap;
28094 unsigned int tag;
28095
28096 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28097 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28098 ap = qc->ap;
28099
28100 qc->flags = 0;
28101 @@ -4752,7 +4752,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
28102 struct ata_port *ap;
28103 struct ata_link *link;
28104
28105 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28106 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
28107 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
28108 ap = qc->ap;
28109 link = qc->dev->link;
28110 @@ -5816,6 +5816,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28111 return;
28112
28113 spin_lock(&lock);
28114 + pax_open_kernel();
28115
28116 for (cur = ops->inherits; cur; cur = cur->inherits) {
28117 void **inherit = (void **)cur;
28118 @@ -5829,8 +5830,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
28119 if (IS_ERR(*pp))
28120 *pp = NULL;
28121
28122 - ops->inherits = NULL;
28123 + *(struct ata_port_operations **)&ops->inherits = NULL;
28124
28125 + pax_close_kernel();
28126 spin_unlock(&lock);
28127 }
28128
28129 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
28130 index 048589f..4002b98 100644
28131 --- a/drivers/ata/pata_arasan_cf.c
28132 +++ b/drivers/ata/pata_arasan_cf.c
28133 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
28134 /* Handle platform specific quirks */
28135 if (pdata->quirk) {
28136 if (pdata->quirk & CF_BROKEN_PIO) {
28137 - ap->ops->set_piomode = NULL;
28138 + pax_open_kernel();
28139 + *(void **)&ap->ops->set_piomode = NULL;
28140 + pax_close_kernel();
28141 ap->pio_mask = 0;
28142 }
28143 if (pdata->quirk & CF_BROKEN_MWDMA)
28144 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
28145 index f9b983a..887b9d8 100644
28146 --- a/drivers/atm/adummy.c
28147 +++ b/drivers/atm/adummy.c
28148 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
28149 vcc->pop(vcc, skb);
28150 else
28151 dev_kfree_skb_any(skb);
28152 - atomic_inc(&vcc->stats->tx);
28153 + atomic_inc_unchecked(&vcc->stats->tx);
28154
28155 return 0;
28156 }
28157 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28158 index f8f41e0..1f987dd 100644
28159 --- a/drivers/atm/ambassador.c
28160 +++ b/drivers/atm/ambassador.c
28161 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28162 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28163
28164 // VC layer stats
28165 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28166 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28167
28168 // free the descriptor
28169 kfree (tx_descr);
28170 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28171 dump_skb ("<<<", vc, skb);
28172
28173 // VC layer stats
28174 - atomic_inc(&atm_vcc->stats->rx);
28175 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28176 __net_timestamp(skb);
28177 // end of our responsibility
28178 atm_vcc->push (atm_vcc, skb);
28179 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28180 } else {
28181 PRINTK (KERN_INFO, "dropped over-size frame");
28182 // should we count this?
28183 - atomic_inc(&atm_vcc->stats->rx_drop);
28184 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28185 }
28186
28187 } else {
28188 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28189 }
28190
28191 if (check_area (skb->data, skb->len)) {
28192 - atomic_inc(&atm_vcc->stats->tx_err);
28193 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28194 return -ENOMEM; // ?
28195 }
28196
28197 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28198 index b22d71c..d6e1049 100644
28199 --- a/drivers/atm/atmtcp.c
28200 +++ b/drivers/atm/atmtcp.c
28201 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28202 if (vcc->pop) vcc->pop(vcc,skb);
28203 else dev_kfree_skb(skb);
28204 if (dev_data) return 0;
28205 - atomic_inc(&vcc->stats->tx_err);
28206 + atomic_inc_unchecked(&vcc->stats->tx_err);
28207 return -ENOLINK;
28208 }
28209 size = skb->len+sizeof(struct atmtcp_hdr);
28210 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28211 if (!new_skb) {
28212 if (vcc->pop) vcc->pop(vcc,skb);
28213 else dev_kfree_skb(skb);
28214 - atomic_inc(&vcc->stats->tx_err);
28215 + atomic_inc_unchecked(&vcc->stats->tx_err);
28216 return -ENOBUFS;
28217 }
28218 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28219 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28220 if (vcc->pop) vcc->pop(vcc,skb);
28221 else dev_kfree_skb(skb);
28222 out_vcc->push(out_vcc,new_skb);
28223 - atomic_inc(&vcc->stats->tx);
28224 - atomic_inc(&out_vcc->stats->rx);
28225 + atomic_inc_unchecked(&vcc->stats->tx);
28226 + atomic_inc_unchecked(&out_vcc->stats->rx);
28227 return 0;
28228 }
28229
28230 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28231 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28232 read_unlock(&vcc_sklist_lock);
28233 if (!out_vcc) {
28234 - atomic_inc(&vcc->stats->tx_err);
28235 + atomic_inc_unchecked(&vcc->stats->tx_err);
28236 goto done;
28237 }
28238 skb_pull(skb,sizeof(struct atmtcp_hdr));
28239 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28240 __net_timestamp(new_skb);
28241 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28242 out_vcc->push(out_vcc,new_skb);
28243 - atomic_inc(&vcc->stats->tx);
28244 - atomic_inc(&out_vcc->stats->rx);
28245 + atomic_inc_unchecked(&vcc->stats->tx);
28246 + atomic_inc_unchecked(&out_vcc->stats->rx);
28247 done:
28248 if (vcc->pop) vcc->pop(vcc,skb);
28249 else dev_kfree_skb(skb);
28250 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28251 index 956e9ac..133516d 100644
28252 --- a/drivers/atm/eni.c
28253 +++ b/drivers/atm/eni.c
28254 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28255 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28256 vcc->dev->number);
28257 length = 0;
28258 - atomic_inc(&vcc->stats->rx_err);
28259 + atomic_inc_unchecked(&vcc->stats->rx_err);
28260 }
28261 else {
28262 length = ATM_CELL_SIZE-1; /* no HEC */
28263 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28264 size);
28265 }
28266 eff = length = 0;
28267 - atomic_inc(&vcc->stats->rx_err);
28268 + atomic_inc_unchecked(&vcc->stats->rx_err);
28269 }
28270 else {
28271 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28272 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28273 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28274 vcc->dev->number,vcc->vci,length,size << 2,descr);
28275 length = eff = 0;
28276 - atomic_inc(&vcc->stats->rx_err);
28277 + atomic_inc_unchecked(&vcc->stats->rx_err);
28278 }
28279 }
28280 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28281 @@ -771,7 +771,7 @@ rx_dequeued++;
28282 vcc->push(vcc,skb);
28283 pushed++;
28284 }
28285 - atomic_inc(&vcc->stats->rx);
28286 + atomic_inc_unchecked(&vcc->stats->rx);
28287 }
28288 wake_up(&eni_dev->rx_wait);
28289 }
28290 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
28291 PCI_DMA_TODEVICE);
28292 if (vcc->pop) vcc->pop(vcc,skb);
28293 else dev_kfree_skb_irq(skb);
28294 - atomic_inc(&vcc->stats->tx);
28295 + atomic_inc_unchecked(&vcc->stats->tx);
28296 wake_up(&eni_dev->tx_wait);
28297 dma_complete++;
28298 }
28299 @@ -1569,7 +1569,7 @@ tx_complete++;
28300 /*--------------------------------- entries ---------------------------------*/
28301
28302
28303 -static const char *media_name[] __devinitdata = {
28304 +static const char *media_name[] __devinitconst = {
28305 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28306 "UTP", "05?", "06?", "07?", /* 4- 7 */
28307 "TAXI","09?", "10?", "11?", /* 8-11 */
28308 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28309 index 5072f8a..fa52520d 100644
28310 --- a/drivers/atm/firestream.c
28311 +++ b/drivers/atm/firestream.c
28312 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28313 }
28314 }
28315
28316 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28317 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28318
28319 fs_dprintk (FS_DEBUG_TXMEM, "i");
28320 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28321 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28322 #endif
28323 skb_put (skb, qe->p1 & 0xffff);
28324 ATM_SKB(skb)->vcc = atm_vcc;
28325 - atomic_inc(&atm_vcc->stats->rx);
28326 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28327 __net_timestamp(skb);
28328 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28329 atm_vcc->push (atm_vcc, skb);
28330 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28331 kfree (pe);
28332 }
28333 if (atm_vcc)
28334 - atomic_inc(&atm_vcc->stats->rx_drop);
28335 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28336 break;
28337 case 0x1f: /* Reassembly abort: no buffers. */
28338 /* Silently increment error counter. */
28339 if (atm_vcc)
28340 - atomic_inc(&atm_vcc->stats->rx_drop);
28341 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28342 break;
28343 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28344 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28345 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28346 index 361f5ae..7fc552d 100644
28347 --- a/drivers/atm/fore200e.c
28348 +++ b/drivers/atm/fore200e.c
28349 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28350 #endif
28351 /* check error condition */
28352 if (*entry->status & STATUS_ERROR)
28353 - atomic_inc(&vcc->stats->tx_err);
28354 + atomic_inc_unchecked(&vcc->stats->tx_err);
28355 else
28356 - atomic_inc(&vcc->stats->tx);
28357 + atomic_inc_unchecked(&vcc->stats->tx);
28358 }
28359 }
28360
28361 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28362 if (skb == NULL) {
28363 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28364
28365 - atomic_inc(&vcc->stats->rx_drop);
28366 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28367 return -ENOMEM;
28368 }
28369
28370 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28371
28372 dev_kfree_skb_any(skb);
28373
28374 - atomic_inc(&vcc->stats->rx_drop);
28375 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28376 return -ENOMEM;
28377 }
28378
28379 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28380
28381 vcc->push(vcc, skb);
28382 - atomic_inc(&vcc->stats->rx);
28383 + atomic_inc_unchecked(&vcc->stats->rx);
28384
28385 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28386
28387 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28388 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28389 fore200e->atm_dev->number,
28390 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28391 - atomic_inc(&vcc->stats->rx_err);
28392 + atomic_inc_unchecked(&vcc->stats->rx_err);
28393 }
28394 }
28395
28396 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28397 goto retry_here;
28398 }
28399
28400 - atomic_inc(&vcc->stats->tx_err);
28401 + atomic_inc_unchecked(&vcc->stats->tx_err);
28402
28403 fore200e->tx_sat++;
28404 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28405 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28406 index b182c2f..1c6fa8a 100644
28407 --- a/drivers/atm/he.c
28408 +++ b/drivers/atm/he.c
28409 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28410
28411 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28412 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28413 - atomic_inc(&vcc->stats->rx_drop);
28414 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28415 goto return_host_buffers;
28416 }
28417
28418 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28419 RBRQ_LEN_ERR(he_dev->rbrq_head)
28420 ? "LEN_ERR" : "",
28421 vcc->vpi, vcc->vci);
28422 - atomic_inc(&vcc->stats->rx_err);
28423 + atomic_inc_unchecked(&vcc->stats->rx_err);
28424 goto return_host_buffers;
28425 }
28426
28427 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28428 vcc->push(vcc, skb);
28429 spin_lock(&he_dev->global_lock);
28430
28431 - atomic_inc(&vcc->stats->rx);
28432 + atomic_inc_unchecked(&vcc->stats->rx);
28433
28434 return_host_buffers:
28435 ++pdus_assembled;
28436 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28437 tpd->vcc->pop(tpd->vcc, tpd->skb);
28438 else
28439 dev_kfree_skb_any(tpd->skb);
28440 - atomic_inc(&tpd->vcc->stats->tx_err);
28441 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28442 }
28443 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28444 return;
28445 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28446 vcc->pop(vcc, skb);
28447 else
28448 dev_kfree_skb_any(skb);
28449 - atomic_inc(&vcc->stats->tx_err);
28450 + atomic_inc_unchecked(&vcc->stats->tx_err);
28451 return -EINVAL;
28452 }
28453
28454 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28455 vcc->pop(vcc, skb);
28456 else
28457 dev_kfree_skb_any(skb);
28458 - atomic_inc(&vcc->stats->tx_err);
28459 + atomic_inc_unchecked(&vcc->stats->tx_err);
28460 return -EINVAL;
28461 }
28462 #endif
28463 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28464 vcc->pop(vcc, skb);
28465 else
28466 dev_kfree_skb_any(skb);
28467 - atomic_inc(&vcc->stats->tx_err);
28468 + atomic_inc_unchecked(&vcc->stats->tx_err);
28469 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28470 return -ENOMEM;
28471 }
28472 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28473 vcc->pop(vcc, skb);
28474 else
28475 dev_kfree_skb_any(skb);
28476 - atomic_inc(&vcc->stats->tx_err);
28477 + atomic_inc_unchecked(&vcc->stats->tx_err);
28478 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28479 return -ENOMEM;
28480 }
28481 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28482 __enqueue_tpd(he_dev, tpd, cid);
28483 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28484
28485 - atomic_inc(&vcc->stats->tx);
28486 + atomic_inc_unchecked(&vcc->stats->tx);
28487
28488 return 0;
28489 }
28490 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28491 index b812103..e391a49 100644
28492 --- a/drivers/atm/horizon.c
28493 +++ b/drivers/atm/horizon.c
28494 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28495 {
28496 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28497 // VC layer stats
28498 - atomic_inc(&vcc->stats->rx);
28499 + atomic_inc_unchecked(&vcc->stats->rx);
28500 __net_timestamp(skb);
28501 // end of our responsibility
28502 vcc->push (vcc, skb);
28503 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28504 dev->tx_iovec = NULL;
28505
28506 // VC layer stats
28507 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28508 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28509
28510 // free the skb
28511 hrz_kfree_skb (skb);
28512 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28513 index 1c05212..c28e200 100644
28514 --- a/drivers/atm/idt77252.c
28515 +++ b/drivers/atm/idt77252.c
28516 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28517 else
28518 dev_kfree_skb(skb);
28519
28520 - atomic_inc(&vcc->stats->tx);
28521 + atomic_inc_unchecked(&vcc->stats->tx);
28522 }
28523
28524 atomic_dec(&scq->used);
28525 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28526 if ((sb = dev_alloc_skb(64)) == NULL) {
28527 printk("%s: Can't allocate buffers for aal0.\n",
28528 card->name);
28529 - atomic_add(i, &vcc->stats->rx_drop);
28530 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28531 break;
28532 }
28533 if (!atm_charge(vcc, sb->truesize)) {
28534 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28535 card->name);
28536 - atomic_add(i - 1, &vcc->stats->rx_drop);
28537 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28538 dev_kfree_skb(sb);
28539 break;
28540 }
28541 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28542 ATM_SKB(sb)->vcc = vcc;
28543 __net_timestamp(sb);
28544 vcc->push(vcc, sb);
28545 - atomic_inc(&vcc->stats->rx);
28546 + atomic_inc_unchecked(&vcc->stats->rx);
28547
28548 cell += ATM_CELL_PAYLOAD;
28549 }
28550 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28551 "(CDC: %08x)\n",
28552 card->name, len, rpp->len, readl(SAR_REG_CDC));
28553 recycle_rx_pool_skb(card, rpp);
28554 - atomic_inc(&vcc->stats->rx_err);
28555 + atomic_inc_unchecked(&vcc->stats->rx_err);
28556 return;
28557 }
28558 if (stat & SAR_RSQE_CRC) {
28559 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28560 recycle_rx_pool_skb(card, rpp);
28561 - atomic_inc(&vcc->stats->rx_err);
28562 + atomic_inc_unchecked(&vcc->stats->rx_err);
28563 return;
28564 }
28565 if (skb_queue_len(&rpp->queue) > 1) {
28566 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28567 RXPRINTK("%s: Can't alloc RX skb.\n",
28568 card->name);
28569 recycle_rx_pool_skb(card, rpp);
28570 - atomic_inc(&vcc->stats->rx_err);
28571 + atomic_inc_unchecked(&vcc->stats->rx_err);
28572 return;
28573 }
28574 if (!atm_charge(vcc, skb->truesize)) {
28575 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28576 __net_timestamp(skb);
28577
28578 vcc->push(vcc, skb);
28579 - atomic_inc(&vcc->stats->rx);
28580 + atomic_inc_unchecked(&vcc->stats->rx);
28581
28582 return;
28583 }
28584 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28585 __net_timestamp(skb);
28586
28587 vcc->push(vcc, skb);
28588 - atomic_inc(&vcc->stats->rx);
28589 + atomic_inc_unchecked(&vcc->stats->rx);
28590
28591 if (skb->truesize > SAR_FB_SIZE_3)
28592 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28593 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28594 if (vcc->qos.aal != ATM_AAL0) {
28595 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28596 card->name, vpi, vci);
28597 - atomic_inc(&vcc->stats->rx_drop);
28598 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28599 goto drop;
28600 }
28601
28602 if ((sb = dev_alloc_skb(64)) == NULL) {
28603 printk("%s: Can't allocate buffers for AAL0.\n",
28604 card->name);
28605 - atomic_inc(&vcc->stats->rx_err);
28606 + atomic_inc_unchecked(&vcc->stats->rx_err);
28607 goto drop;
28608 }
28609
28610 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28611 ATM_SKB(sb)->vcc = vcc;
28612 __net_timestamp(sb);
28613 vcc->push(vcc, sb);
28614 - atomic_inc(&vcc->stats->rx);
28615 + atomic_inc_unchecked(&vcc->stats->rx);
28616
28617 drop:
28618 skb_pull(queue, 64);
28619 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28620
28621 if (vc == NULL) {
28622 printk("%s: NULL connection in send().\n", card->name);
28623 - atomic_inc(&vcc->stats->tx_err);
28624 + atomic_inc_unchecked(&vcc->stats->tx_err);
28625 dev_kfree_skb(skb);
28626 return -EINVAL;
28627 }
28628 if (!test_bit(VCF_TX, &vc->flags)) {
28629 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28630 - atomic_inc(&vcc->stats->tx_err);
28631 + atomic_inc_unchecked(&vcc->stats->tx_err);
28632 dev_kfree_skb(skb);
28633 return -EINVAL;
28634 }
28635 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28636 break;
28637 default:
28638 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28639 - atomic_inc(&vcc->stats->tx_err);
28640 + atomic_inc_unchecked(&vcc->stats->tx_err);
28641 dev_kfree_skb(skb);
28642 return -EINVAL;
28643 }
28644
28645 if (skb_shinfo(skb)->nr_frags != 0) {
28646 printk("%s: No scatter-gather yet.\n", card->name);
28647 - atomic_inc(&vcc->stats->tx_err);
28648 + atomic_inc_unchecked(&vcc->stats->tx_err);
28649 dev_kfree_skb(skb);
28650 return -EINVAL;
28651 }
28652 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28653
28654 err = queue_skb(card, vc, skb, oam);
28655 if (err) {
28656 - atomic_inc(&vcc->stats->tx_err);
28657 + atomic_inc_unchecked(&vcc->stats->tx_err);
28658 dev_kfree_skb(skb);
28659 return err;
28660 }
28661 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28662 skb = dev_alloc_skb(64);
28663 if (!skb) {
28664 printk("%s: Out of memory in send_oam().\n", card->name);
28665 - atomic_inc(&vcc->stats->tx_err);
28666 + atomic_inc_unchecked(&vcc->stats->tx_err);
28667 return -ENOMEM;
28668 }
28669 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28670 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28671 index 9e373ba..cf93727 100644
28672 --- a/drivers/atm/iphase.c
28673 +++ b/drivers/atm/iphase.c
28674 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
28675 status = (u_short) (buf_desc_ptr->desc_mode);
28676 if (status & (RX_CER | RX_PTE | RX_OFL))
28677 {
28678 - atomic_inc(&vcc->stats->rx_err);
28679 + atomic_inc_unchecked(&vcc->stats->rx_err);
28680 IF_ERR(printk("IA: bad packet, dropping it");)
28681 if (status & RX_CER) {
28682 IF_ERR(printk(" cause: packet CRC error\n");)
28683 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
28684 len = dma_addr - buf_addr;
28685 if (len > iadev->rx_buf_sz) {
28686 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28687 - atomic_inc(&vcc->stats->rx_err);
28688 + atomic_inc_unchecked(&vcc->stats->rx_err);
28689 goto out_free_desc;
28690 }
28691
28692 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28693 ia_vcc = INPH_IA_VCC(vcc);
28694 if (ia_vcc == NULL)
28695 {
28696 - atomic_inc(&vcc->stats->rx_err);
28697 + atomic_inc_unchecked(&vcc->stats->rx_err);
28698 atm_return(vcc, skb->truesize);
28699 dev_kfree_skb_any(skb);
28700 goto INCR_DLE;
28701 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28702 if ((length > iadev->rx_buf_sz) || (length >
28703 (skb->len - sizeof(struct cpcs_trailer))))
28704 {
28705 - atomic_inc(&vcc->stats->rx_err);
28706 + atomic_inc_unchecked(&vcc->stats->rx_err);
28707 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28708 length, skb->len);)
28709 atm_return(vcc, skb->truesize);
28710 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28711
28712 IF_RX(printk("rx_dle_intr: skb push");)
28713 vcc->push(vcc,skb);
28714 - atomic_inc(&vcc->stats->rx);
28715 + atomic_inc_unchecked(&vcc->stats->rx);
28716 iadev->rx_pkt_cnt++;
28717 }
28718 INCR_DLE:
28719 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28720 {
28721 struct k_sonet_stats *stats;
28722 stats = &PRIV(_ia_dev[board])->sonet_stats;
28723 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28724 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28725 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28726 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28727 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28728 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28729 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28730 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28731 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28732 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28733 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28734 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28735 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28736 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28737 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28738 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28739 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28740 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28741 }
28742 ia_cmds.status = 0;
28743 break;
28744 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28745 if ((desc == 0) || (desc > iadev->num_tx_desc))
28746 {
28747 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28748 - atomic_inc(&vcc->stats->tx);
28749 + atomic_inc_unchecked(&vcc->stats->tx);
28750 if (vcc->pop)
28751 vcc->pop(vcc, skb);
28752 else
28753 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28754 ATM_DESC(skb) = vcc->vci;
28755 skb_queue_tail(&iadev->tx_dma_q, skb);
28756
28757 - atomic_inc(&vcc->stats->tx);
28758 + atomic_inc_unchecked(&vcc->stats->tx);
28759 iadev->tx_pkt_cnt++;
28760 /* Increment transaction counter */
28761 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28762
28763 #if 0
28764 /* add flow control logic */
28765 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28766 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28767 if (iavcc->vc_desc_cnt > 10) {
28768 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28769 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28770 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28771 index f556969..0da15eb 100644
28772 --- a/drivers/atm/lanai.c
28773 +++ b/drivers/atm/lanai.c
28774 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28775 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28776 lanai_endtx(lanai, lvcc);
28777 lanai_free_skb(lvcc->tx.atmvcc, skb);
28778 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28779 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28780 }
28781
28782 /* Try to fill the buffer - don't call unless there is backlog */
28783 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28784 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28785 __net_timestamp(skb);
28786 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28787 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28788 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28789 out:
28790 lvcc->rx.buf.ptr = end;
28791 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28792 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28793 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28794 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28795 lanai->stats.service_rxnotaal5++;
28796 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28797 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28798 return 0;
28799 }
28800 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28801 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28802 int bytes;
28803 read_unlock(&vcc_sklist_lock);
28804 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28805 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28806 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28807 lvcc->stats.x.aal5.service_trash++;
28808 bytes = (SERVICE_GET_END(s) * 16) -
28809 (((unsigned long) lvcc->rx.buf.ptr) -
28810 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28811 }
28812 if (s & SERVICE_STREAM) {
28813 read_unlock(&vcc_sklist_lock);
28814 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28815 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28816 lvcc->stats.x.aal5.service_stream++;
28817 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28818 "PDU on VCI %d!\n", lanai->number, vci);
28819 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28820 return 0;
28821 }
28822 DPRINTK("got rx crc error on vci %d\n", vci);
28823 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28824 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28825 lvcc->stats.x.aal5.service_rxcrc++;
28826 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28827 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28828 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28829 index 1c70c45..300718d 100644
28830 --- a/drivers/atm/nicstar.c
28831 +++ b/drivers/atm/nicstar.c
28832 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28833 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28834 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28835 card->index);
28836 - atomic_inc(&vcc->stats->tx_err);
28837 + atomic_inc_unchecked(&vcc->stats->tx_err);
28838 dev_kfree_skb_any(skb);
28839 return -EINVAL;
28840 }
28841 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28842 if (!vc->tx) {
28843 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28844 card->index);
28845 - atomic_inc(&vcc->stats->tx_err);
28846 + atomic_inc_unchecked(&vcc->stats->tx_err);
28847 dev_kfree_skb_any(skb);
28848 return -EINVAL;
28849 }
28850 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28851 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28852 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28853 card->index);
28854 - atomic_inc(&vcc->stats->tx_err);
28855 + atomic_inc_unchecked(&vcc->stats->tx_err);
28856 dev_kfree_skb_any(skb);
28857 return -EINVAL;
28858 }
28859
28860 if (skb_shinfo(skb)->nr_frags != 0) {
28861 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28862 - atomic_inc(&vcc->stats->tx_err);
28863 + atomic_inc_unchecked(&vcc->stats->tx_err);
28864 dev_kfree_skb_any(skb);
28865 return -EINVAL;
28866 }
28867 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28868 }
28869
28870 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28871 - atomic_inc(&vcc->stats->tx_err);
28872 + atomic_inc_unchecked(&vcc->stats->tx_err);
28873 dev_kfree_skb_any(skb);
28874 return -EIO;
28875 }
28876 - atomic_inc(&vcc->stats->tx);
28877 + atomic_inc_unchecked(&vcc->stats->tx);
28878
28879 return 0;
28880 }
28881 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28882 printk
28883 ("nicstar%d: Can't allocate buffers for aal0.\n",
28884 card->index);
28885 - atomic_add(i, &vcc->stats->rx_drop);
28886 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28887 break;
28888 }
28889 if (!atm_charge(vcc, sb->truesize)) {
28890 RXPRINTK
28891 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28892 card->index);
28893 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28894 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28895 dev_kfree_skb_any(sb);
28896 break;
28897 }
28898 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28899 ATM_SKB(sb)->vcc = vcc;
28900 __net_timestamp(sb);
28901 vcc->push(vcc, sb);
28902 - atomic_inc(&vcc->stats->rx);
28903 + atomic_inc_unchecked(&vcc->stats->rx);
28904 cell += ATM_CELL_PAYLOAD;
28905 }
28906
28907 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28908 if (iovb == NULL) {
28909 printk("nicstar%d: Out of iovec buffers.\n",
28910 card->index);
28911 - atomic_inc(&vcc->stats->rx_drop);
28912 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28913 recycle_rx_buf(card, skb);
28914 return;
28915 }
28916 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28917 small or large buffer itself. */
28918 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28919 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28920 - atomic_inc(&vcc->stats->rx_err);
28921 + atomic_inc_unchecked(&vcc->stats->rx_err);
28922 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28923 NS_MAX_IOVECS);
28924 NS_PRV_IOVCNT(iovb) = 0;
28925 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28926 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28927 card->index);
28928 which_list(card, skb);
28929 - atomic_inc(&vcc->stats->rx_err);
28930 + atomic_inc_unchecked(&vcc->stats->rx_err);
28931 recycle_rx_buf(card, skb);
28932 vc->rx_iov = NULL;
28933 recycle_iov_buf(card, iovb);
28934 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28935 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28936 card->index);
28937 which_list(card, skb);
28938 - atomic_inc(&vcc->stats->rx_err);
28939 + atomic_inc_unchecked(&vcc->stats->rx_err);
28940 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28941 NS_PRV_IOVCNT(iovb));
28942 vc->rx_iov = NULL;
28943 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28944 printk(" - PDU size mismatch.\n");
28945 else
28946 printk(".\n");
28947 - atomic_inc(&vcc->stats->rx_err);
28948 + atomic_inc_unchecked(&vcc->stats->rx_err);
28949 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28950 NS_PRV_IOVCNT(iovb));
28951 vc->rx_iov = NULL;
28952 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28953 /* skb points to a small buffer */
28954 if (!atm_charge(vcc, skb->truesize)) {
28955 push_rxbufs(card, skb);
28956 - atomic_inc(&vcc->stats->rx_drop);
28957 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28958 } else {
28959 skb_put(skb, len);
28960 dequeue_sm_buf(card, skb);
28961 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28962 ATM_SKB(skb)->vcc = vcc;
28963 __net_timestamp(skb);
28964 vcc->push(vcc, skb);
28965 - atomic_inc(&vcc->stats->rx);
28966 + atomic_inc_unchecked(&vcc->stats->rx);
28967 }
28968 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28969 struct sk_buff *sb;
28970 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28971 if (len <= NS_SMBUFSIZE) {
28972 if (!atm_charge(vcc, sb->truesize)) {
28973 push_rxbufs(card, sb);
28974 - atomic_inc(&vcc->stats->rx_drop);
28975 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28976 } else {
28977 skb_put(sb, len);
28978 dequeue_sm_buf(card, sb);
28979 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28980 ATM_SKB(sb)->vcc = vcc;
28981 __net_timestamp(sb);
28982 vcc->push(vcc, sb);
28983 - atomic_inc(&vcc->stats->rx);
28984 + atomic_inc_unchecked(&vcc->stats->rx);
28985 }
28986
28987 push_rxbufs(card, skb);
28988 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28989
28990 if (!atm_charge(vcc, skb->truesize)) {
28991 push_rxbufs(card, skb);
28992 - atomic_inc(&vcc->stats->rx_drop);
28993 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28994 } else {
28995 dequeue_lg_buf(card, skb);
28996 #ifdef NS_USE_DESTRUCTORS
28997 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28998 ATM_SKB(skb)->vcc = vcc;
28999 __net_timestamp(skb);
29000 vcc->push(vcc, skb);
29001 - atomic_inc(&vcc->stats->rx);
29002 + atomic_inc_unchecked(&vcc->stats->rx);
29003 }
29004
29005 push_rxbufs(card, sb);
29006 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29007 printk
29008 ("nicstar%d: Out of huge buffers.\n",
29009 card->index);
29010 - atomic_inc(&vcc->stats->rx_drop);
29011 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29012 recycle_iovec_rx_bufs(card,
29013 (struct iovec *)
29014 iovb->data,
29015 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29016 card->hbpool.count++;
29017 } else
29018 dev_kfree_skb_any(hb);
29019 - atomic_inc(&vcc->stats->rx_drop);
29020 + atomic_inc_unchecked(&vcc->stats->rx_drop);
29021 } else {
29022 /* Copy the small buffer to the huge buffer */
29023 sb = (struct sk_buff *)iov->iov_base;
29024 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
29025 #endif /* NS_USE_DESTRUCTORS */
29026 __net_timestamp(hb);
29027 vcc->push(vcc, hb);
29028 - atomic_inc(&vcc->stats->rx);
29029 + atomic_inc_unchecked(&vcc->stats->rx);
29030 }
29031 }
29032
29033 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
29034 index e8cd652..bbbd1fc 100644
29035 --- a/drivers/atm/solos-pci.c
29036 +++ b/drivers/atm/solos-pci.c
29037 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
29038 }
29039 atm_charge(vcc, skb->truesize);
29040 vcc->push(vcc, skb);
29041 - atomic_inc(&vcc->stats->rx);
29042 + atomic_inc_unchecked(&vcc->stats->rx);
29043 break;
29044
29045 case PKT_STATUS:
29046 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
29047 vcc = SKB_CB(oldskb)->vcc;
29048
29049 if (vcc) {
29050 - atomic_inc(&vcc->stats->tx);
29051 + atomic_inc_unchecked(&vcc->stats->tx);
29052 solos_pop(vcc, oldskb);
29053 } else
29054 dev_kfree_skb_irq(oldskb);
29055 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
29056 index 90f1ccc..04c4a1e 100644
29057 --- a/drivers/atm/suni.c
29058 +++ b/drivers/atm/suni.c
29059 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
29060
29061
29062 #define ADD_LIMITED(s,v) \
29063 - atomic_add((v),&stats->s); \
29064 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
29065 + atomic_add_unchecked((v),&stats->s); \
29066 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
29067
29068
29069 static void suni_hz(unsigned long from_timer)
29070 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
29071 index 5120a96..e2572bd 100644
29072 --- a/drivers/atm/uPD98402.c
29073 +++ b/drivers/atm/uPD98402.c
29074 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
29075 struct sonet_stats tmp;
29076 int error = 0;
29077
29078 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29079 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
29080 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
29081 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
29082 if (zero && !error) {
29083 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
29084
29085
29086 #define ADD_LIMITED(s,v) \
29087 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
29088 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
29089 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29090 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
29091 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
29092 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
29093
29094
29095 static void stat_event(struct atm_dev *dev)
29096 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
29097 if (reason & uPD98402_INT_PFM) stat_event(dev);
29098 if (reason & uPD98402_INT_PCO) {
29099 (void) GET(PCOCR); /* clear interrupt cause */
29100 - atomic_add(GET(HECCT),
29101 + atomic_add_unchecked(GET(HECCT),
29102 &PRIV(dev)->sonet_stats.uncorr_hcs);
29103 }
29104 if ((reason & uPD98402_INT_RFO) &&
29105 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
29106 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
29107 uPD98402_INT_LOS),PIMR); /* enable them */
29108 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
29109 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29110 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
29111 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
29112 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
29113 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
29114 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
29115 return 0;
29116 }
29117
29118 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
29119 index d889f56..17eb71e 100644
29120 --- a/drivers/atm/zatm.c
29121 +++ b/drivers/atm/zatm.c
29122 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29123 }
29124 if (!size) {
29125 dev_kfree_skb_irq(skb);
29126 - if (vcc) atomic_inc(&vcc->stats->rx_err);
29127 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
29128 continue;
29129 }
29130 if (!atm_charge(vcc,skb->truesize)) {
29131 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
29132 skb->len = size;
29133 ATM_SKB(skb)->vcc = vcc;
29134 vcc->push(vcc,skb);
29135 - atomic_inc(&vcc->stats->rx);
29136 + atomic_inc_unchecked(&vcc->stats->rx);
29137 }
29138 zout(pos & 0xffff,MTA(mbx));
29139 #if 0 /* probably a stupid idea */
29140 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
29141 skb_queue_head(&zatm_vcc->backlog,skb);
29142 break;
29143 }
29144 - atomic_inc(&vcc->stats->tx);
29145 + atomic_inc_unchecked(&vcc->stats->tx);
29146 wake_up(&zatm_vcc->tx_wait);
29147 }
29148
29149 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
29150 index 8493536..31adee0 100644
29151 --- a/drivers/base/devtmpfs.c
29152 +++ b/drivers/base/devtmpfs.c
29153 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
29154 if (!thread)
29155 return 0;
29156
29157 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29158 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29159 if (err)
29160 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29161 else
29162 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29163 index caf995f..6f76697 100644
29164 --- a/drivers/base/power/wakeup.c
29165 +++ b/drivers/base/power/wakeup.c
29166 @@ -30,14 +30,14 @@ bool events_check_enabled;
29167 * They need to be modified together atomically, so it's better to use one
29168 * atomic variable to hold them both.
29169 */
29170 -static atomic_t combined_event_count = ATOMIC_INIT(0);
29171 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29172
29173 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29174 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29175
29176 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29177 {
29178 - unsigned int comb = atomic_read(&combined_event_count);
29179 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29180
29181 *cnt = (comb >> IN_PROGRESS_BITS);
29182 *inpr = comb & MAX_IN_PROGRESS;
29183 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29184 ws->last_time = ktime_get();
29185
29186 /* Increment the counter of events in progress. */
29187 - atomic_inc(&combined_event_count);
29188 + atomic_inc_unchecked(&combined_event_count);
29189 }
29190
29191 /**
29192 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29193 * Increment the counter of registered wakeup events and decrement the
29194 * couter of wakeup events in progress simultaneously.
29195 */
29196 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
29197 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29198 }
29199
29200 /**
29201 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29202 index b0f553b..77b928b 100644
29203 --- a/drivers/block/cciss.c
29204 +++ b/drivers/block/cciss.c
29205 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29206 int err;
29207 u32 cp;
29208
29209 + memset(&arg64, 0, sizeof(arg64));
29210 +
29211 err = 0;
29212 err |=
29213 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29214 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29215 while (!list_empty(&h->reqQ)) {
29216 c = list_entry(h->reqQ.next, CommandList_struct, list);
29217 /* can't do anything if fifo is full */
29218 - if ((h->access.fifo_full(h))) {
29219 + if ((h->access->fifo_full(h))) {
29220 dev_warn(&h->pdev->dev, "fifo full\n");
29221 break;
29222 }
29223 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29224 h->Qdepth--;
29225
29226 /* Tell the controller execute command */
29227 - h->access.submit_command(h, c);
29228 + h->access->submit_command(h, c);
29229
29230 /* Put job onto the completed Q */
29231 addQ(&h->cmpQ, c);
29232 @@ -3443,17 +3445,17 @@ startio:
29233
29234 static inline unsigned long get_next_completion(ctlr_info_t *h)
29235 {
29236 - return h->access.command_completed(h);
29237 + return h->access->command_completed(h);
29238 }
29239
29240 static inline int interrupt_pending(ctlr_info_t *h)
29241 {
29242 - return h->access.intr_pending(h);
29243 + return h->access->intr_pending(h);
29244 }
29245
29246 static inline long interrupt_not_for_us(ctlr_info_t *h)
29247 {
29248 - return ((h->access.intr_pending(h) == 0) ||
29249 + return ((h->access->intr_pending(h) == 0) ||
29250 (h->interrupts_enabled == 0));
29251 }
29252
29253 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29254 u32 a;
29255
29256 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29257 - return h->access.command_completed(h);
29258 + return h->access->command_completed(h);
29259
29260 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29261 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29262 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29263 trans_support & CFGTBL_Trans_use_short_tags);
29264
29265 /* Change the access methods to the performant access methods */
29266 - h->access = SA5_performant_access;
29267 + h->access = &SA5_performant_access;
29268 h->transMethod = CFGTBL_Trans_Performant;
29269
29270 return;
29271 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29272 if (prod_index < 0)
29273 return -ENODEV;
29274 h->product_name = products[prod_index].product_name;
29275 - h->access = *(products[prod_index].access);
29276 + h->access = products[prod_index].access;
29277
29278 if (cciss_board_disabled(h)) {
29279 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29280 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29281 }
29282
29283 /* make sure the board interrupts are off */
29284 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29285 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29286 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29287 if (rc)
29288 goto clean2;
29289 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29290 * fake ones to scoop up any residual completions.
29291 */
29292 spin_lock_irqsave(&h->lock, flags);
29293 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29294 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29295 spin_unlock_irqrestore(&h->lock, flags);
29296 free_irq(h->intr[h->intr_mode], h);
29297 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29298 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29299 dev_info(&h->pdev->dev, "Board READY.\n");
29300 dev_info(&h->pdev->dev,
29301 "Waiting for stale completions to drain.\n");
29302 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29303 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29304 msleep(10000);
29305 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29306 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29307
29308 rc = controller_reset_failed(h->cfgtable);
29309 if (rc)
29310 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29311 cciss_scsi_setup(h);
29312
29313 /* Turn the interrupts on so we can service requests */
29314 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29315 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29316
29317 /* Get the firmware version */
29318 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29319 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29320 kfree(flush_buf);
29321 if (return_code != IO_OK)
29322 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29323 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29324 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29325 free_irq(h->intr[h->intr_mode], h);
29326 }
29327
29328 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29329 index 7fda30e..eb5dfe0 100644
29330 --- a/drivers/block/cciss.h
29331 +++ b/drivers/block/cciss.h
29332 @@ -101,7 +101,7 @@ struct ctlr_info
29333 /* information about each logical volume */
29334 drive_info_struct *drv[CISS_MAX_LUN];
29335
29336 - struct access_method access;
29337 + struct access_method *access;
29338
29339 /* queue and queue Info */
29340 struct list_head reqQ;
29341 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29342 index 9125bbe..eede5c8 100644
29343 --- a/drivers/block/cpqarray.c
29344 +++ b/drivers/block/cpqarray.c
29345 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29346 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29347 goto Enomem4;
29348 }
29349 - hba[i]->access.set_intr_mask(hba[i], 0);
29350 + hba[i]->access->set_intr_mask(hba[i], 0);
29351 if (request_irq(hba[i]->intr, do_ida_intr,
29352 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29353 {
29354 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29355 add_timer(&hba[i]->timer);
29356
29357 /* Enable IRQ now that spinlock and rate limit timer are set up */
29358 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29359 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29360
29361 for(j=0; j<NWD; j++) {
29362 struct gendisk *disk = ida_gendisk[i][j];
29363 @@ -694,7 +694,7 @@ DBGINFO(
29364 for(i=0; i<NR_PRODUCTS; i++) {
29365 if (board_id == products[i].board_id) {
29366 c->product_name = products[i].product_name;
29367 - c->access = *(products[i].access);
29368 + c->access = products[i].access;
29369 break;
29370 }
29371 }
29372 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29373 hba[ctlr]->intr = intr;
29374 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29375 hba[ctlr]->product_name = products[j].product_name;
29376 - hba[ctlr]->access = *(products[j].access);
29377 + hba[ctlr]->access = products[j].access;
29378 hba[ctlr]->ctlr = ctlr;
29379 hba[ctlr]->board_id = board_id;
29380 hba[ctlr]->pci_dev = NULL; /* not PCI */
29381 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29382
29383 while((c = h->reqQ) != NULL) {
29384 /* Can't do anything if we're busy */
29385 - if (h->access.fifo_full(h) == 0)
29386 + if (h->access->fifo_full(h) == 0)
29387 return;
29388
29389 /* Get the first entry from the request Q */
29390 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29391 h->Qdepth--;
29392
29393 /* Tell the controller to do our bidding */
29394 - h->access.submit_command(h, c);
29395 + h->access->submit_command(h, c);
29396
29397 /* Get onto the completion Q */
29398 addQ(&h->cmpQ, c);
29399 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29400 unsigned long flags;
29401 __u32 a,a1;
29402
29403 - istat = h->access.intr_pending(h);
29404 + istat = h->access->intr_pending(h);
29405 /* Is this interrupt for us? */
29406 if (istat == 0)
29407 return IRQ_NONE;
29408 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29409 */
29410 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29411 if (istat & FIFO_NOT_EMPTY) {
29412 - while((a = h->access.command_completed(h))) {
29413 + while((a = h->access->command_completed(h))) {
29414 a1 = a; a &= ~3;
29415 if ((c = h->cmpQ) == NULL)
29416 {
29417 @@ -1449,11 +1449,11 @@ static int sendcmd(
29418 /*
29419 * Disable interrupt
29420 */
29421 - info_p->access.set_intr_mask(info_p, 0);
29422 + info_p->access->set_intr_mask(info_p, 0);
29423 /* Make sure there is room in the command FIFO */
29424 /* Actually it should be completely empty at this time. */
29425 for (i = 200000; i > 0; i--) {
29426 - temp = info_p->access.fifo_full(info_p);
29427 + temp = info_p->access->fifo_full(info_p);
29428 if (temp != 0) {
29429 break;
29430 }
29431 @@ -1466,7 +1466,7 @@ DBG(
29432 /*
29433 * Send the cmd
29434 */
29435 - info_p->access.submit_command(info_p, c);
29436 + info_p->access->submit_command(info_p, c);
29437 complete = pollcomplete(ctlr);
29438
29439 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29440 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29441 * we check the new geometry. Then turn interrupts back on when
29442 * we're done.
29443 */
29444 - host->access.set_intr_mask(host, 0);
29445 + host->access->set_intr_mask(host, 0);
29446 getgeometry(ctlr);
29447 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29448 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29449
29450 for(i=0; i<NWD; i++) {
29451 struct gendisk *disk = ida_gendisk[ctlr][i];
29452 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29453 /* Wait (up to 2 seconds) for a command to complete */
29454
29455 for (i = 200000; i > 0; i--) {
29456 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29457 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29458 if (done == 0) {
29459 udelay(10); /* a short fixed delay */
29460 } else
29461 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29462 index be73e9d..7fbf140 100644
29463 --- a/drivers/block/cpqarray.h
29464 +++ b/drivers/block/cpqarray.h
29465 @@ -99,7 +99,7 @@ struct ctlr_info {
29466 drv_info_t drv[NWD];
29467 struct proc_dir_entry *proc;
29468
29469 - struct access_method access;
29470 + struct access_method *access;
29471
29472 cmdlist_t *reqQ;
29473 cmdlist_t *cmpQ;
29474 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29475 index 8d68056..e67050f 100644
29476 --- a/drivers/block/drbd/drbd_int.h
29477 +++ b/drivers/block/drbd/drbd_int.h
29478 @@ -736,7 +736,7 @@ struct drbd_request;
29479 struct drbd_epoch {
29480 struct list_head list;
29481 unsigned int barrier_nr;
29482 - atomic_t epoch_size; /* increased on every request added. */
29483 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29484 atomic_t active; /* increased on every req. added, and dec on every finished. */
29485 unsigned long flags;
29486 };
29487 @@ -1108,7 +1108,7 @@ struct drbd_conf {
29488 void *int_dig_in;
29489 void *int_dig_vv;
29490 wait_queue_head_t seq_wait;
29491 - atomic_t packet_seq;
29492 + atomic_unchecked_t packet_seq;
29493 unsigned int peer_seq;
29494 spinlock_t peer_seq_lock;
29495 unsigned int minor;
29496 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29497
29498 static inline void drbd_tcp_cork(struct socket *sock)
29499 {
29500 - int __user val = 1;
29501 + int val = 1;
29502 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29503 - (char __user *)&val, sizeof(val));
29504 + (char __force_user *)&val, sizeof(val));
29505 }
29506
29507 static inline void drbd_tcp_uncork(struct socket *sock)
29508 {
29509 - int __user val = 0;
29510 + int val = 0;
29511 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29512 - (char __user *)&val, sizeof(val));
29513 + (char __force_user *)&val, sizeof(val));
29514 }
29515
29516 static inline void drbd_tcp_nodelay(struct socket *sock)
29517 {
29518 - int __user val = 1;
29519 + int val = 1;
29520 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29521 - (char __user *)&val, sizeof(val));
29522 + (char __force_user *)&val, sizeof(val));
29523 }
29524
29525 static inline void drbd_tcp_quickack(struct socket *sock)
29526 {
29527 - int __user val = 2;
29528 + int val = 2;
29529 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29530 - (char __user *)&val, sizeof(val));
29531 + (char __force_user *)&val, sizeof(val));
29532 }
29533
29534 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29535 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29536 index 211fc44..c5116f1 100644
29537 --- a/drivers/block/drbd/drbd_main.c
29538 +++ b/drivers/block/drbd/drbd_main.c
29539 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29540 p.sector = sector;
29541 p.block_id = block_id;
29542 p.blksize = blksize;
29543 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29544 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29545
29546 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29547 return false;
29548 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29549 p.sector = cpu_to_be64(req->sector);
29550 p.block_id = (unsigned long)req;
29551 p.seq_num = cpu_to_be32(req->seq_num =
29552 - atomic_add_return(1, &mdev->packet_seq));
29553 + atomic_add_return_unchecked(1, &mdev->packet_seq));
29554
29555 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29556
29557 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29558 atomic_set(&mdev->unacked_cnt, 0);
29559 atomic_set(&mdev->local_cnt, 0);
29560 atomic_set(&mdev->net_cnt, 0);
29561 - atomic_set(&mdev->packet_seq, 0);
29562 + atomic_set_unchecked(&mdev->packet_seq, 0);
29563 atomic_set(&mdev->pp_in_use, 0);
29564 atomic_set(&mdev->pp_in_use_by_net, 0);
29565 atomic_set(&mdev->rs_sect_in, 0);
29566 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29567 mdev->receiver.t_state);
29568
29569 /* no need to lock it, I'm the only thread alive */
29570 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29571 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29572 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29573 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29574 mdev->al_writ_cnt =
29575 mdev->bm_writ_cnt =
29576 mdev->read_cnt =
29577 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29578 index af2a250..0fdeb75 100644
29579 --- a/drivers/block/drbd/drbd_nl.c
29580 +++ b/drivers/block/drbd/drbd_nl.c
29581 @@ -2297,7 +2297,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29582 return;
29583 }
29584
29585 - if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) {
29586 + if (!capable(CAP_SYS_ADMIN)) {
29587 retcode = ERR_PERM;
29588 goto fail;
29589 }
29590 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29591 module_put(THIS_MODULE);
29592 }
29593
29594 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29595 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29596
29597 static unsigned short *
29598 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29599 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29600 cn_reply->id.idx = CN_IDX_DRBD;
29601 cn_reply->id.val = CN_VAL_DRBD;
29602
29603 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29604 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29605 cn_reply->ack = 0; /* not used here. */
29606 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29607 (int)((char *)tl - (char *)reply->tag_list);
29608 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29609 cn_reply->id.idx = CN_IDX_DRBD;
29610 cn_reply->id.val = CN_VAL_DRBD;
29611
29612 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29613 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29614 cn_reply->ack = 0; /* not used here. */
29615 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29616 (int)((char *)tl - (char *)reply->tag_list);
29617 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29618 cn_reply->id.idx = CN_IDX_DRBD;
29619 cn_reply->id.val = CN_VAL_DRBD;
29620
29621 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29622 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29623 cn_reply->ack = 0; // not used here.
29624 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29625 (int)((char*)tl - (char*)reply->tag_list);
29626 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29627 cn_reply->id.idx = CN_IDX_DRBD;
29628 cn_reply->id.val = CN_VAL_DRBD;
29629
29630 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29631 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29632 cn_reply->ack = 0; /* not used here. */
29633 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29634 (int)((char *)tl - (char *)reply->tag_list);
29635 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29636 index 43beaca..4a5b1dd 100644
29637 --- a/drivers/block/drbd/drbd_receiver.c
29638 +++ b/drivers/block/drbd/drbd_receiver.c
29639 @@ -894,7 +894,7 @@ retry:
29640 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29641 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29642
29643 - atomic_set(&mdev->packet_seq, 0);
29644 + atomic_set_unchecked(&mdev->packet_seq, 0);
29645 mdev->peer_seq = 0;
29646
29647 drbd_thread_start(&mdev->asender);
29648 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29649 do {
29650 next_epoch = NULL;
29651
29652 - epoch_size = atomic_read(&epoch->epoch_size);
29653 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29654
29655 switch (ev & ~EV_CLEANUP) {
29656 case EV_PUT:
29657 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29658 rv = FE_DESTROYED;
29659 } else {
29660 epoch->flags = 0;
29661 - atomic_set(&epoch->epoch_size, 0);
29662 + atomic_set_unchecked(&epoch->epoch_size, 0);
29663 /* atomic_set(&epoch->active, 0); is already zero */
29664 if (rv == FE_STILL_LIVE)
29665 rv = FE_RECYCLED;
29666 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29667 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29668 drbd_flush(mdev);
29669
29670 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29671 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29672 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29673 if (epoch)
29674 break;
29675 }
29676
29677 epoch = mdev->current_epoch;
29678 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29679 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29680
29681 D_ASSERT(atomic_read(&epoch->active) == 0);
29682 D_ASSERT(epoch->flags == 0);
29683 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29684 }
29685
29686 epoch->flags = 0;
29687 - atomic_set(&epoch->epoch_size, 0);
29688 + atomic_set_unchecked(&epoch->epoch_size, 0);
29689 atomic_set(&epoch->active, 0);
29690
29691 spin_lock(&mdev->epoch_lock);
29692 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29693 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29694 list_add(&epoch->list, &mdev->current_epoch->list);
29695 mdev->current_epoch = epoch;
29696 mdev->epochs++;
29697 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29698 spin_unlock(&mdev->peer_seq_lock);
29699
29700 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29701 - atomic_inc(&mdev->current_epoch->epoch_size);
29702 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29703 return drbd_drain_block(mdev, data_size);
29704 }
29705
29706 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29707
29708 spin_lock(&mdev->epoch_lock);
29709 e->epoch = mdev->current_epoch;
29710 - atomic_inc(&e->epoch->epoch_size);
29711 + atomic_inc_unchecked(&e->epoch->epoch_size);
29712 atomic_inc(&e->epoch->active);
29713 spin_unlock(&mdev->epoch_lock);
29714
29715 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29716 D_ASSERT(list_empty(&mdev->done_ee));
29717
29718 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29719 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29720 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29721 D_ASSERT(list_empty(&mdev->current_epoch->list));
29722 }
29723
29724 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29725 index cd50435..ba1ffb5 100644
29726 --- a/drivers/block/loop.c
29727 +++ b/drivers/block/loop.c
29728 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29729 mm_segment_t old_fs = get_fs();
29730
29731 set_fs(get_ds());
29732 - bw = file->f_op->write(file, buf, len, &pos);
29733 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29734 set_fs(old_fs);
29735 if (likely(bw == len))
29736 return 0;
29737 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29738 index 4364303..9adf4ee 100644
29739 --- a/drivers/char/Kconfig
29740 +++ b/drivers/char/Kconfig
29741 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29742
29743 config DEVKMEM
29744 bool "/dev/kmem virtual device support"
29745 - default y
29746 + default n
29747 + depends on !GRKERNSEC_KMEM
29748 help
29749 Say Y here if you want to support the /dev/kmem device. The
29750 /dev/kmem device is rarely used, but can be used for certain
29751 @@ -596,6 +597,7 @@ config DEVPORT
29752 bool
29753 depends on !M68K
29754 depends on ISA || PCI
29755 + depends on !GRKERNSEC_KMEM
29756 default y
29757
29758 source "drivers/s390/char/Kconfig"
29759 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29760 index 2e04433..22afc64 100644
29761 --- a/drivers/char/agp/frontend.c
29762 +++ b/drivers/char/agp/frontend.c
29763 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29764 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29765 return -EFAULT;
29766
29767 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29768 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29769 return -EFAULT;
29770
29771 client = agp_find_client_by_pid(reserve.pid);
29772 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
29773 index 095ab90..afad0a4 100644
29774 --- a/drivers/char/briq_panel.c
29775 +++ b/drivers/char/briq_panel.c
29776 @@ -9,6 +9,7 @@
29777 #include <linux/types.h>
29778 #include <linux/errno.h>
29779 #include <linux/tty.h>
29780 +#include <linux/mutex.h>
29781 #include <linux/timer.h>
29782 #include <linux/kernel.h>
29783 #include <linux/wait.h>
29784 @@ -34,6 +35,7 @@ static int vfd_is_open;
29785 static unsigned char vfd[40];
29786 static int vfd_cursor;
29787 static unsigned char ledpb, led;
29788 +static DEFINE_MUTEX(vfd_mutex);
29789
29790 static void update_vfd(void)
29791 {
29792 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29793 if (!vfd_is_open)
29794 return -EBUSY;
29795
29796 + mutex_lock(&vfd_mutex);
29797 for (;;) {
29798 char c;
29799 if (!indx)
29800 break;
29801 - if (get_user(c, buf))
29802 + if (get_user(c, buf)) {
29803 + mutex_unlock(&vfd_mutex);
29804 return -EFAULT;
29805 + }
29806 if (esc) {
29807 set_led(c);
29808 esc = 0;
29809 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29810 buf++;
29811 }
29812 update_vfd();
29813 + mutex_unlock(&vfd_mutex);
29814
29815 return len;
29816 }
29817 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29818 index f773a9d..65cd683 100644
29819 --- a/drivers/char/genrtc.c
29820 +++ b/drivers/char/genrtc.c
29821 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
29822 switch (cmd) {
29823
29824 case RTC_PLL_GET:
29825 + memset(&pll, 0, sizeof(pll));
29826 if (get_rtc_pll(&pll))
29827 return -EINVAL;
29828 else
29829 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29830 index 0833896..cccce52 100644
29831 --- a/drivers/char/hpet.c
29832 +++ b/drivers/char/hpet.c
29833 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29834 }
29835
29836 static int
29837 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29838 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29839 struct hpet_info *info)
29840 {
29841 struct hpet_timer __iomem *timer;
29842 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29843 index 58c0e63..46c16bf 100644
29844 --- a/drivers/char/ipmi/ipmi_msghandler.c
29845 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29846 @@ -415,7 +415,7 @@ struct ipmi_smi {
29847 struct proc_dir_entry *proc_dir;
29848 char proc_dir_name[10];
29849
29850 - atomic_t stats[IPMI_NUM_STATS];
29851 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29852
29853 /*
29854 * run_to_completion duplicate of smb_info, smi_info
29855 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29856
29857
29858 #define ipmi_inc_stat(intf, stat) \
29859 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29860 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29861 #define ipmi_get_stat(intf, stat) \
29862 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29863 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29864
29865 static int is_lan_addr(struct ipmi_addr *addr)
29866 {
29867 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29868 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29869 init_waitqueue_head(&intf->waitq);
29870 for (i = 0; i < IPMI_NUM_STATS; i++)
29871 - atomic_set(&intf->stats[i], 0);
29872 + atomic_set_unchecked(&intf->stats[i], 0);
29873
29874 intf->proc_dir = NULL;
29875
29876 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29877 index 50fcf9c..91b5528 100644
29878 --- a/drivers/char/ipmi/ipmi_si_intf.c
29879 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29880 @@ -277,7 +277,7 @@ struct smi_info {
29881 unsigned char slave_addr;
29882
29883 /* Counters and things for the proc filesystem. */
29884 - atomic_t stats[SI_NUM_STATS];
29885 + atomic_unchecked_t stats[SI_NUM_STATS];
29886
29887 struct task_struct *thread;
29888
29889 @@ -286,9 +286,9 @@ struct smi_info {
29890 };
29891
29892 #define smi_inc_stat(smi, stat) \
29893 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29894 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29895 #define smi_get_stat(smi, stat) \
29896 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29897 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29898
29899 #define SI_MAX_PARMS 4
29900
29901 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
29902 atomic_set(&new_smi->req_events, 0);
29903 new_smi->run_to_completion = 0;
29904 for (i = 0; i < SI_NUM_STATS; i++)
29905 - atomic_set(&new_smi->stats[i], 0);
29906 + atomic_set_unchecked(&new_smi->stats[i], 0);
29907
29908 new_smi->interrupt_disabled = 1;
29909 atomic_set(&new_smi->stop_operation, 0);
29910 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29911 index 1aeaaba..e018570 100644
29912 --- a/drivers/char/mbcs.c
29913 +++ b/drivers/char/mbcs.c
29914 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
29915 return 0;
29916 }
29917
29918 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29919 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29920 {
29921 .part_num = MBCS_PART_NUM,
29922 .mfg_num = MBCS_MFG_NUM,
29923 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29924 index d6e9d08..4493e89 100644
29925 --- a/drivers/char/mem.c
29926 +++ b/drivers/char/mem.c
29927 @@ -18,6 +18,7 @@
29928 #include <linux/raw.h>
29929 #include <linux/tty.h>
29930 #include <linux/capability.h>
29931 +#include <linux/security.h>
29932 #include <linux/ptrace.h>
29933 #include <linux/device.h>
29934 #include <linux/highmem.h>
29935 @@ -35,6 +36,10 @@
29936 # include <linux/efi.h>
29937 #endif
29938
29939 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29940 +extern const struct file_operations grsec_fops;
29941 +#endif
29942 +
29943 static inline unsigned long size_inside_page(unsigned long start,
29944 unsigned long size)
29945 {
29946 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29947
29948 while (cursor < to) {
29949 if (!devmem_is_allowed(pfn)) {
29950 +#ifdef CONFIG_GRKERNSEC_KMEM
29951 + gr_handle_mem_readwrite(from, to);
29952 +#else
29953 printk(KERN_INFO
29954 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29955 current->comm, from, to);
29956 +#endif
29957 return 0;
29958 }
29959 cursor += PAGE_SIZE;
29960 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29961 }
29962 return 1;
29963 }
29964 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29965 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29966 +{
29967 + return 0;
29968 +}
29969 #else
29970 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29971 {
29972 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29973
29974 while (count > 0) {
29975 unsigned long remaining;
29976 + char *temp;
29977
29978 sz = size_inside_page(p, count);
29979
29980 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29981 if (!ptr)
29982 return -EFAULT;
29983
29984 - remaining = copy_to_user(buf, ptr, sz);
29985 +#ifdef CONFIG_PAX_USERCOPY
29986 + temp = kmalloc(sz, GFP_KERNEL);
29987 + if (!temp) {
29988 + unxlate_dev_mem_ptr(p, ptr);
29989 + return -ENOMEM;
29990 + }
29991 + memcpy(temp, ptr, sz);
29992 +#else
29993 + temp = ptr;
29994 +#endif
29995 +
29996 + remaining = copy_to_user(buf, temp, sz);
29997 +
29998 +#ifdef CONFIG_PAX_USERCOPY
29999 + kfree(temp);
30000 +#endif
30001 +
30002 unxlate_dev_mem_ptr(p, ptr);
30003 if (remaining)
30004 return -EFAULT;
30005 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30006 size_t count, loff_t *ppos)
30007 {
30008 unsigned long p = *ppos;
30009 - ssize_t low_count, read, sz;
30010 + ssize_t low_count, read, sz, err = 0;
30011 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
30012 - int err = 0;
30013
30014 read = 0;
30015 if (p < (unsigned long) high_memory) {
30016 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30017 }
30018 #endif
30019 while (low_count > 0) {
30020 + char *temp;
30021 +
30022 sz = size_inside_page(p, low_count);
30023
30024 /*
30025 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
30026 */
30027 kbuf = xlate_dev_kmem_ptr((char *)p);
30028
30029 - if (copy_to_user(buf, kbuf, sz))
30030 +#ifdef CONFIG_PAX_USERCOPY
30031 + temp = kmalloc(sz, GFP_KERNEL);
30032 + if (!temp)
30033 + return -ENOMEM;
30034 + memcpy(temp, kbuf, sz);
30035 +#else
30036 + temp = kbuf;
30037 +#endif
30038 +
30039 + err = copy_to_user(buf, temp, sz);
30040 +
30041 +#ifdef CONFIG_PAX_USERCOPY
30042 + kfree(temp);
30043 +#endif
30044 +
30045 + if (err)
30046 return -EFAULT;
30047 buf += sz;
30048 p += sz;
30049 @@ -867,6 +914,9 @@ static const struct memdev {
30050 #ifdef CONFIG_CRASH_DUMP
30051 [12] = { "oldmem", 0, &oldmem_fops, NULL },
30052 #endif
30053 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
30054 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
30055 +#endif
30056 };
30057
30058 static int memory_open(struct inode *inode, struct file *filp)
30059 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
30060 index da3cfee..a5a6606 100644
30061 --- a/drivers/char/nvram.c
30062 +++ b/drivers/char/nvram.c
30063 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
30064
30065 spin_unlock_irq(&rtc_lock);
30066
30067 - if (copy_to_user(buf, contents, tmp - contents))
30068 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
30069 return -EFAULT;
30070
30071 *ppos = i;
30072 diff --git a/drivers/char/random.c b/drivers/char/random.c
30073 index 54ca8b2..4a092ed 100644
30074 --- a/drivers/char/random.c
30075 +++ b/drivers/char/random.c
30076 @@ -261,8 +261,13 @@
30077 /*
30078 * Configuration information
30079 */
30080 +#ifdef CONFIG_GRKERNSEC_RANDNET
30081 +#define INPUT_POOL_WORDS 512
30082 +#define OUTPUT_POOL_WORDS 128
30083 +#else
30084 #define INPUT_POOL_WORDS 128
30085 #define OUTPUT_POOL_WORDS 32
30086 +#endif
30087 #define SEC_XFER_SIZE 512
30088 #define EXTRACT_SIZE 10
30089
30090 @@ -300,10 +305,17 @@ static struct poolinfo {
30091 int poolwords;
30092 int tap1, tap2, tap3, tap4, tap5;
30093 } poolinfo_table[] = {
30094 +#ifdef CONFIG_GRKERNSEC_RANDNET
30095 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
30096 + { 512, 411, 308, 208, 104, 1 },
30097 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
30098 + { 128, 103, 76, 51, 25, 1 },
30099 +#else
30100 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
30101 { 128, 103, 76, 51, 25, 1 },
30102 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
30103 { 32, 26, 20, 14, 7, 1 },
30104 +#endif
30105 #if 0
30106 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
30107 { 2048, 1638, 1231, 819, 411, 1 },
30108 @@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30109
30110 extract_buf(r, tmp);
30111 i = min_t(int, nbytes, EXTRACT_SIZE);
30112 - if (copy_to_user(buf, tmp, i)) {
30113 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30114 ret = -EFAULT;
30115 break;
30116 }
30117 @@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30118 #include <linux/sysctl.h>
30119
30120 static int min_read_thresh = 8, min_write_thresh;
30121 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
30122 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30123 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30124 static char sysctl_bootid[16];
30125
30126 @@ -1260,10 +1272,15 @@ static int proc_do_uuid(ctl_table *table, int write,
30127 uuid = table->data;
30128 if (!uuid) {
30129 uuid = tmp_uuid;
30130 - uuid[8] = 0;
30131 - }
30132 - if (uuid[8] == 0)
30133 generate_random_uuid(uuid);
30134 + } else {
30135 + static DEFINE_SPINLOCK(bootid_spinlock);
30136 +
30137 + spin_lock(&bootid_spinlock);
30138 + if (!uuid[8])
30139 + generate_random_uuid(uuid);
30140 + spin_unlock(&bootid_spinlock);
30141 + }
30142
30143 sprintf(buf, "%pU", uuid);
30144
30145 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30146 index 1ee8ce7..b778bef 100644
30147 --- a/drivers/char/sonypi.c
30148 +++ b/drivers/char/sonypi.c
30149 @@ -55,6 +55,7 @@
30150 #include <asm/uaccess.h>
30151 #include <asm/io.h>
30152 #include <asm/system.h>
30153 +#include <asm/local.h>
30154
30155 #include <linux/sonypi.h>
30156
30157 @@ -491,7 +492,7 @@ static struct sonypi_device {
30158 spinlock_t fifo_lock;
30159 wait_queue_head_t fifo_proc_list;
30160 struct fasync_struct *fifo_async;
30161 - int open_count;
30162 + local_t open_count;
30163 int model;
30164 struct input_dev *input_jog_dev;
30165 struct input_dev *input_key_dev;
30166 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30167 static int sonypi_misc_release(struct inode *inode, struct file *file)
30168 {
30169 mutex_lock(&sonypi_device.lock);
30170 - sonypi_device.open_count--;
30171 + local_dec(&sonypi_device.open_count);
30172 mutex_unlock(&sonypi_device.lock);
30173 return 0;
30174 }
30175 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30176 {
30177 mutex_lock(&sonypi_device.lock);
30178 /* Flush input queue on first open */
30179 - if (!sonypi_device.open_count)
30180 + if (!local_read(&sonypi_device.open_count))
30181 kfifo_reset(&sonypi_device.fifo);
30182 - sonypi_device.open_count++;
30183 + local_inc(&sonypi_device.open_count);
30184 mutex_unlock(&sonypi_device.lock);
30185
30186 return 0;
30187 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30188 index ad7c732..5aa8054 100644
30189 --- a/drivers/char/tpm/tpm.c
30190 +++ b/drivers/char/tpm/tpm.c
30191 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30192 chip->vendor.req_complete_val)
30193 goto out_recv;
30194
30195 - if ((status == chip->vendor.req_canceled)) {
30196 + if (status == chip->vendor.req_canceled) {
30197 dev_err(chip->dev, "Operation Canceled\n");
30198 rc = -ECANCELED;
30199 goto out;
30200 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30201 index 0636520..169c1d0 100644
30202 --- a/drivers/char/tpm/tpm_bios.c
30203 +++ b/drivers/char/tpm/tpm_bios.c
30204 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30205 event = addr;
30206
30207 if ((event->event_type == 0 && event->event_size == 0) ||
30208 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30209 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30210 return NULL;
30211
30212 return addr;
30213 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30214 return NULL;
30215
30216 if ((event->event_type == 0 && event->event_size == 0) ||
30217 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30218 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30219 return NULL;
30220
30221 (*pos)++;
30222 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30223 int i;
30224
30225 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30226 - seq_putc(m, data[i]);
30227 + if (!seq_putc(m, data[i]))
30228 + return -EFAULT;
30229
30230 return 0;
30231 }
30232 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30233 log->bios_event_log_end = log->bios_event_log + len;
30234
30235 virt = acpi_os_map_memory(start, len);
30236 + if (!virt) {
30237 + kfree(log->bios_event_log);
30238 + log->bios_event_log = NULL;
30239 + return -EFAULT;
30240 + }
30241
30242 - memcpy(log->bios_event_log, virt, len);
30243 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30244
30245 acpi_os_unmap_memory(virt, len);
30246 return 0;
30247 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30248 index b58b561..c9088c8 100644
30249 --- a/drivers/char/virtio_console.c
30250 +++ b/drivers/char/virtio_console.c
30251 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30252 if (to_user) {
30253 ssize_t ret;
30254
30255 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30256 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30257 if (ret)
30258 return -EFAULT;
30259 } else {
30260 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30261 if (!port_has_data(port) && !port->host_connected)
30262 return 0;
30263
30264 - return fill_readbuf(port, ubuf, count, true);
30265 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30266 }
30267
30268 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30269 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
30270 index c9eee6d..f9d5280 100644
30271 --- a/drivers/edac/amd64_edac.c
30272 +++ b/drivers/edac/amd64_edac.c
30273 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
30274 * PCI core identifies what devices are on a system during boot, and then
30275 * inquiry this table to see if this driver is for a given device found.
30276 */
30277 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
30278 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
30279 {
30280 .vendor = PCI_VENDOR_ID_AMD,
30281 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
30282 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
30283 index e47e73b..348e0bd 100644
30284 --- a/drivers/edac/amd76x_edac.c
30285 +++ b/drivers/edac/amd76x_edac.c
30286 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
30287 edac_mc_free(mci);
30288 }
30289
30290 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
30291 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
30292 {
30293 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30294 AMD762},
30295 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
30296 index 1af531a..3a8ff27 100644
30297 --- a/drivers/edac/e752x_edac.c
30298 +++ b/drivers/edac/e752x_edac.c
30299 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
30300 edac_mc_free(mci);
30301 }
30302
30303 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
30304 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
30305 {
30306 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30307 E7520},
30308 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
30309 index 6ffb6d2..383d8d7 100644
30310 --- a/drivers/edac/e7xxx_edac.c
30311 +++ b/drivers/edac/e7xxx_edac.c
30312 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
30313 edac_mc_free(mci);
30314 }
30315
30316 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
30317 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
30318 {
30319 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30320 E7205},
30321 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30322 index 97f5064..202b6e6 100644
30323 --- a/drivers/edac/edac_pci_sysfs.c
30324 +++ b/drivers/edac/edac_pci_sysfs.c
30325 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30326 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30327 static int edac_pci_poll_msec = 1000; /* one second workq period */
30328
30329 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30330 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30331 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30332 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30333
30334 static struct kobject *edac_pci_top_main_kobj;
30335 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30336 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30337 edac_printk(KERN_CRIT, EDAC_PCI,
30338 "Signaled System Error on %s\n",
30339 pci_name(dev));
30340 - atomic_inc(&pci_nonparity_count);
30341 + atomic_inc_unchecked(&pci_nonparity_count);
30342 }
30343
30344 if (status & (PCI_STATUS_PARITY)) {
30345 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30346 "Master Data Parity Error on %s\n",
30347 pci_name(dev));
30348
30349 - atomic_inc(&pci_parity_count);
30350 + atomic_inc_unchecked(&pci_parity_count);
30351 }
30352
30353 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30354 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30355 "Detected Parity Error on %s\n",
30356 pci_name(dev));
30357
30358 - atomic_inc(&pci_parity_count);
30359 + atomic_inc_unchecked(&pci_parity_count);
30360 }
30361 }
30362
30363 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30364 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30365 "Signaled System Error on %s\n",
30366 pci_name(dev));
30367 - atomic_inc(&pci_nonparity_count);
30368 + atomic_inc_unchecked(&pci_nonparity_count);
30369 }
30370
30371 if (status & (PCI_STATUS_PARITY)) {
30372 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30373 "Master Data Parity Error on "
30374 "%s\n", pci_name(dev));
30375
30376 - atomic_inc(&pci_parity_count);
30377 + atomic_inc_unchecked(&pci_parity_count);
30378 }
30379
30380 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30381 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30382 "Detected Parity Error on %s\n",
30383 pci_name(dev));
30384
30385 - atomic_inc(&pci_parity_count);
30386 + atomic_inc_unchecked(&pci_parity_count);
30387 }
30388 }
30389 }
30390 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
30391 if (!check_pci_errors)
30392 return;
30393
30394 - before_count = atomic_read(&pci_parity_count);
30395 + before_count = atomic_read_unchecked(&pci_parity_count);
30396
30397 /* scan all PCI devices looking for a Parity Error on devices and
30398 * bridges.
30399 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
30400 /* Only if operator has selected panic on PCI Error */
30401 if (edac_pci_get_panic_on_pe()) {
30402 /* If the count is different 'after' from 'before' */
30403 - if (before_count != atomic_read(&pci_parity_count))
30404 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30405 panic("EDAC: PCI Parity Error");
30406 }
30407 }
30408 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
30409 index c0510b3..6e2a954 100644
30410 --- a/drivers/edac/i3000_edac.c
30411 +++ b/drivers/edac/i3000_edac.c
30412 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
30413 edac_mc_free(mci);
30414 }
30415
30416 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
30417 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
30418 {
30419 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30420 I3000},
30421 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
30422 index 73f55e200..5faaf59 100644
30423 --- a/drivers/edac/i3200_edac.c
30424 +++ b/drivers/edac/i3200_edac.c
30425 @@ -445,7 +445,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
30426 edac_mc_free(mci);
30427 }
30428
30429 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
30430 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
30431 {
30432 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30433 I3200},
30434 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
30435 index 4dc3ac2..67d05a6 100644
30436 --- a/drivers/edac/i5000_edac.c
30437 +++ b/drivers/edac/i5000_edac.c
30438 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
30439 *
30440 * The "E500P" device is the first device supported.
30441 */
30442 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
30443 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
30444 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
30445 .driver_data = I5000P},
30446
30447 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
30448 index bcbdeec..9886d16 100644
30449 --- a/drivers/edac/i5100_edac.c
30450 +++ b/drivers/edac/i5100_edac.c
30451 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
30452 edac_mc_free(mci);
30453 }
30454
30455 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
30456 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
30457 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
30458 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
30459 { 0, }
30460 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
30461 index 74d6ec34..baff517 100644
30462 --- a/drivers/edac/i5400_edac.c
30463 +++ b/drivers/edac/i5400_edac.c
30464 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
30465 *
30466 * The "E500P" device is the first device supported.
30467 */
30468 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
30469 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
30470 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
30471 {0,} /* 0 terminated list. */
30472 };
30473 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
30474 index 6104dba..e7ea8e1 100644
30475 --- a/drivers/edac/i7300_edac.c
30476 +++ b/drivers/edac/i7300_edac.c
30477 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
30478 *
30479 * Has only 8086:360c PCI ID
30480 */
30481 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
30482 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
30483 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
30484 {0,} /* 0 terminated list. */
30485 };
30486 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
30487 index 8568d9b..42b2fa8 100644
30488 --- a/drivers/edac/i7core_edac.c
30489 +++ b/drivers/edac/i7core_edac.c
30490 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
30491 /*
30492 * pci_device_id table for which devices we are looking for
30493 */
30494 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
30495 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
30496 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
30497 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
30498 {0,} /* 0 terminated list. */
30499 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
30500 index 4329d39..f3022ef 100644
30501 --- a/drivers/edac/i82443bxgx_edac.c
30502 +++ b/drivers/edac/i82443bxgx_edac.c
30503 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
30504
30505 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
30506
30507 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
30508 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
30509 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
30510 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
30511 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
30512 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
30513 index 931a057..fd28340 100644
30514 --- a/drivers/edac/i82860_edac.c
30515 +++ b/drivers/edac/i82860_edac.c
30516 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
30517 edac_mc_free(mci);
30518 }
30519
30520 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
30521 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
30522 {
30523 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30524 I82860},
30525 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
30526 index 33864c6..01edc61 100644
30527 --- a/drivers/edac/i82875p_edac.c
30528 +++ b/drivers/edac/i82875p_edac.c
30529 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
30530 edac_mc_free(mci);
30531 }
30532
30533 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
30534 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
30535 {
30536 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30537 I82875P},
30538 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
30539 index 4184e01..dcb2cd3 100644
30540 --- a/drivers/edac/i82975x_edac.c
30541 +++ b/drivers/edac/i82975x_edac.c
30542 @@ -612,7 +612,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
30543 edac_mc_free(mci);
30544 }
30545
30546 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
30547 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
30548 {
30549 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30550 I82975X
30551 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30552 index 0106747..0b40417 100644
30553 --- a/drivers/edac/mce_amd.h
30554 +++ b/drivers/edac/mce_amd.h
30555 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
30556 bool (*dc_mce)(u16, u8);
30557 bool (*ic_mce)(u16, u8);
30558 bool (*nb_mce)(u16, u8);
30559 -};
30560 +} __no_const;
30561
30562 void amd_report_gart_errors(bool);
30563 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30564 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
30565 index e294e1b..a41b05b 100644
30566 --- a/drivers/edac/r82600_edac.c
30567 +++ b/drivers/edac/r82600_edac.c
30568 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
30569 edac_mc_free(mci);
30570 }
30571
30572 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
30573 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
30574 {
30575 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
30576 },
30577 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
30578 index 1dc118d..8c68af9 100644
30579 --- a/drivers/edac/sb_edac.c
30580 +++ b/drivers/edac/sb_edac.c
30581 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
30582 /*
30583 * pci_device_id table for which devices we are looking for
30584 */
30585 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
30586 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
30587 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
30588 {0,} /* 0 terminated list. */
30589 };
30590 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
30591 index b6f47de..c5acf3a 100644
30592 --- a/drivers/edac/x38_edac.c
30593 +++ b/drivers/edac/x38_edac.c
30594 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
30595 edac_mc_free(mci);
30596 }
30597
30598 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
30599 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
30600 {
30601 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30602 X38},
30603 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30604 index 85661b0..c784559a 100644
30605 --- a/drivers/firewire/core-card.c
30606 +++ b/drivers/firewire/core-card.c
30607 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
30608
30609 void fw_core_remove_card(struct fw_card *card)
30610 {
30611 - struct fw_card_driver dummy_driver = dummy_driver_template;
30612 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30613
30614 card->driver->update_phy_reg(card, 4,
30615 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30616 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30617 index 4799393..37bd3ab 100644
30618 --- a/drivers/firewire/core-cdev.c
30619 +++ b/drivers/firewire/core-cdev.c
30620 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
30621 int ret;
30622
30623 if ((request->channels == 0 && request->bandwidth == 0) ||
30624 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30625 - request->bandwidth < 0)
30626 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30627 return -EINVAL;
30628
30629 r = kmalloc(sizeof(*r), GFP_KERNEL);
30630 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30631 index 855ab3f..11f4bbd 100644
30632 --- a/drivers/firewire/core-transaction.c
30633 +++ b/drivers/firewire/core-transaction.c
30634 @@ -37,6 +37,7 @@
30635 #include <linux/timer.h>
30636 #include <linux/types.h>
30637 #include <linux/workqueue.h>
30638 +#include <linux/sched.h>
30639
30640 #include <asm/byteorder.h>
30641
30642 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30643 index b45be57..5fad18b 100644
30644 --- a/drivers/firewire/core.h
30645 +++ b/drivers/firewire/core.h
30646 @@ -101,6 +101,7 @@ struct fw_card_driver {
30647
30648 int (*stop_iso)(struct fw_iso_context *ctx);
30649 };
30650 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30651
30652 void fw_card_initialize(struct fw_card *card,
30653 const struct fw_card_driver *driver, struct device *device);
30654 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30655 index 153980b..4b4d046 100644
30656 --- a/drivers/firmware/dmi_scan.c
30657 +++ b/drivers/firmware/dmi_scan.c
30658 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
30659 }
30660 }
30661 else {
30662 - /*
30663 - * no iounmap() for that ioremap(); it would be a no-op, but
30664 - * it's so early in setup that sucker gets confused into doing
30665 - * what it shouldn't if we actually call it.
30666 - */
30667 p = dmi_ioremap(0xF0000, 0x10000);
30668 if (p == NULL)
30669 goto error;
30670 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30671 if (buf == NULL)
30672 return -1;
30673
30674 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30675 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30676
30677 iounmap(buf);
30678 return 0;
30679 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30680 index 82d5c20..44a7177 100644
30681 --- a/drivers/gpio/gpio-vr41xx.c
30682 +++ b/drivers/gpio/gpio-vr41xx.c
30683 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30684 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30685 maskl, pendl, maskh, pendh);
30686
30687 - atomic_inc(&irq_err_count);
30688 + atomic_inc_unchecked(&irq_err_count);
30689
30690 return -EINVAL;
30691 }
30692 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30693 index 84a4a80..ce0306e 100644
30694 --- a/drivers/gpu/drm/drm_crtc_helper.c
30695 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30696 @@ -280,7 +280,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30697 struct drm_crtc *tmp;
30698 int crtc_mask = 1;
30699
30700 - WARN(!crtc, "checking null crtc?\n");
30701 + BUG_ON(!crtc);
30702
30703 dev = crtc->dev;
30704
30705 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30706 index ebf7d3f..d64c436 100644
30707 --- a/drivers/gpu/drm/drm_drv.c
30708 +++ b/drivers/gpu/drm/drm_drv.c
30709 @@ -312,7 +312,7 @@ module_exit(drm_core_exit);
30710 /**
30711 * Copy and IOCTL return string to user space
30712 */
30713 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30714 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30715 {
30716 int len;
30717
30718 @@ -391,7 +391,7 @@ long drm_ioctl(struct file *filp,
30719
30720 dev = file_priv->minor->dev;
30721 atomic_inc(&dev->ioctl_count);
30722 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30723 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30724 ++file_priv->ioctl_count;
30725
30726 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30727 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30728 index 6263b01..7987f55 100644
30729 --- a/drivers/gpu/drm/drm_fops.c
30730 +++ b/drivers/gpu/drm/drm_fops.c
30731 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30732 }
30733
30734 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30735 - atomic_set(&dev->counts[i], 0);
30736 + atomic_set_unchecked(&dev->counts[i], 0);
30737
30738 dev->sigdata.lock = NULL;
30739
30740 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
30741
30742 retcode = drm_open_helper(inode, filp, dev);
30743 if (!retcode) {
30744 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30745 - if (!dev->open_count++)
30746 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30747 + if (local_inc_return(&dev->open_count) == 1)
30748 retcode = drm_setup(dev);
30749 }
30750 if (!retcode) {
30751 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
30752
30753 mutex_lock(&drm_global_mutex);
30754
30755 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30756 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30757
30758 if (dev->driver->preclose)
30759 dev->driver->preclose(dev, file_priv);
30760 @@ -482,10 +482,10 @@ int drm_release(struct inode *inode, struct file *filp)
30761 * Begin inline drm_release
30762 */
30763
30764 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30765 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30766 task_pid_nr(current),
30767 (long)old_encode_dev(file_priv->minor->device),
30768 - dev->open_count);
30769 + local_read(&dev->open_count));
30770
30771 /* Release any auth tokens that might point to this file_priv,
30772 (do that under the drm_global_mutex) */
30773 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
30774 * End inline drm_release
30775 */
30776
30777 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30778 - if (!--dev->open_count) {
30779 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30780 + if (local_dec_and_test(&dev->open_count)) {
30781 if (atomic_read(&dev->ioctl_count)) {
30782 DRM_ERROR("Device busy: %d\n",
30783 atomic_read(&dev->ioctl_count));
30784 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30785 index c87dc96..326055d 100644
30786 --- a/drivers/gpu/drm/drm_global.c
30787 +++ b/drivers/gpu/drm/drm_global.c
30788 @@ -36,7 +36,7 @@
30789 struct drm_global_item {
30790 struct mutex mutex;
30791 void *object;
30792 - int refcount;
30793 + atomic_t refcount;
30794 };
30795
30796 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30797 @@ -49,7 +49,7 @@ void drm_global_init(void)
30798 struct drm_global_item *item = &glob[i];
30799 mutex_init(&item->mutex);
30800 item->object = NULL;
30801 - item->refcount = 0;
30802 + atomic_set(&item->refcount, 0);
30803 }
30804 }
30805
30806 @@ -59,7 +59,7 @@ void drm_global_release(void)
30807 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30808 struct drm_global_item *item = &glob[i];
30809 BUG_ON(item->object != NULL);
30810 - BUG_ON(item->refcount != 0);
30811 + BUG_ON(atomic_read(&item->refcount) != 0);
30812 }
30813 }
30814
30815 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30816 void *object;
30817
30818 mutex_lock(&item->mutex);
30819 - if (item->refcount == 0) {
30820 + if (atomic_read(&item->refcount) == 0) {
30821 item->object = kzalloc(ref->size, GFP_KERNEL);
30822 if (unlikely(item->object == NULL)) {
30823 ret = -ENOMEM;
30824 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30825 goto out_err;
30826
30827 }
30828 - ++item->refcount;
30829 + atomic_inc(&item->refcount);
30830 ref->object = item->object;
30831 object = item->object;
30832 mutex_unlock(&item->mutex);
30833 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30834 struct drm_global_item *item = &glob[ref->global_type];
30835
30836 mutex_lock(&item->mutex);
30837 - BUG_ON(item->refcount == 0);
30838 + BUG_ON(atomic_read(&item->refcount) == 0);
30839 BUG_ON(ref->object != item->object);
30840 - if (--item->refcount == 0) {
30841 + if (atomic_dec_and_test(&item->refcount)) {
30842 ref->release(ref);
30843 item->object = NULL;
30844 }
30845 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30846 index ab1162d..42587b2 100644
30847 --- a/drivers/gpu/drm/drm_info.c
30848 +++ b/drivers/gpu/drm/drm_info.c
30849 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30850 struct drm_local_map *map;
30851 struct drm_map_list *r_list;
30852
30853 - /* Hardcoded from _DRM_FRAME_BUFFER,
30854 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30855 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30856 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30857 + static const char * const types[] = {
30858 + [_DRM_FRAME_BUFFER] = "FB",
30859 + [_DRM_REGISTERS] = "REG",
30860 + [_DRM_SHM] = "SHM",
30861 + [_DRM_AGP] = "AGP",
30862 + [_DRM_SCATTER_GATHER] = "SG",
30863 + [_DRM_CONSISTENT] = "PCI",
30864 + [_DRM_GEM] = "GEM" };
30865 const char *type;
30866 int i;
30867
30868 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30869 map = r_list->map;
30870 if (!map)
30871 continue;
30872 - if (map->type < 0 || map->type > 5)
30873 + if (map->type >= ARRAY_SIZE(types))
30874 type = "??";
30875 else
30876 type = types[map->type];
30877 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30878 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30879 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30880 vma->vm_flags & VM_IO ? 'i' : '-',
30881 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30882 + 0);
30883 +#else
30884 vma->vm_pgoff);
30885 +#endif
30886
30887 #if defined(__i386__)
30888 pgprot = pgprot_val(vma->vm_page_prot);
30889 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30890 index 637fcc3..e890b33 100644
30891 --- a/drivers/gpu/drm/drm_ioc32.c
30892 +++ b/drivers/gpu/drm/drm_ioc32.c
30893 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30894 request = compat_alloc_user_space(nbytes);
30895 if (!access_ok(VERIFY_WRITE, request, nbytes))
30896 return -EFAULT;
30897 - list = (struct drm_buf_desc *) (request + 1);
30898 + list = (struct drm_buf_desc __user *) (request + 1);
30899
30900 if (__put_user(count, &request->count)
30901 || __put_user(list, &request->list))
30902 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30903 request = compat_alloc_user_space(nbytes);
30904 if (!access_ok(VERIFY_WRITE, request, nbytes))
30905 return -EFAULT;
30906 - list = (struct drm_buf_pub *) (request + 1);
30907 + list = (struct drm_buf_pub __user *) (request + 1);
30908
30909 if (__put_user(count, &request->count)
30910 || __put_user(list, &request->list))
30911 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30912 index 956fd38..e52167a 100644
30913 --- a/drivers/gpu/drm/drm_ioctl.c
30914 +++ b/drivers/gpu/drm/drm_ioctl.c
30915 @@ -251,7 +251,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30916 stats->data[i].value =
30917 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30918 else
30919 - stats->data[i].value = atomic_read(&dev->counts[i]);
30920 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30921 stats->data[i].type = dev->types[i];
30922 }
30923
30924 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30925 index c79c713..2048588 100644
30926 --- a/drivers/gpu/drm/drm_lock.c
30927 +++ b/drivers/gpu/drm/drm_lock.c
30928 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30929 if (drm_lock_take(&master->lock, lock->context)) {
30930 master->lock.file_priv = file_priv;
30931 master->lock.lock_time = jiffies;
30932 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30933 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30934 break; /* Got lock */
30935 }
30936
30937 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30938 return -EINVAL;
30939 }
30940
30941 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30942 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30943
30944 if (drm_lock_free(&master->lock, lock->context)) {
30945 /* FIXME: Should really bail out here. */
30946 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30947 index 7f4b4e1..bf4def2 100644
30948 --- a/drivers/gpu/drm/i810/i810_dma.c
30949 +++ b/drivers/gpu/drm/i810/i810_dma.c
30950 @@ -948,8 +948,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30951 dma->buflist[vertex->idx],
30952 vertex->discard, vertex->used);
30953
30954 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30955 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30956 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30957 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30958 sarea_priv->last_enqueue = dev_priv->counter - 1;
30959 sarea_priv->last_dispatch = (int)hw_status[5];
30960
30961 @@ -1109,8 +1109,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30962 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30963 mc->last_render);
30964
30965 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30966 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30967 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30968 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30969 sarea_priv->last_enqueue = dev_priv->counter - 1;
30970 sarea_priv->last_dispatch = (int)hw_status[5];
30971
30972 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30973 index c9339f4..f5e1b9d 100644
30974 --- a/drivers/gpu/drm/i810/i810_drv.h
30975 +++ b/drivers/gpu/drm/i810/i810_drv.h
30976 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30977 int page_flipping;
30978
30979 wait_queue_head_t irq_queue;
30980 - atomic_t irq_received;
30981 - atomic_t irq_emitted;
30982 + atomic_unchecked_t irq_received;
30983 + atomic_unchecked_t irq_emitted;
30984
30985 int front_offset;
30986 } drm_i810_private_t;
30987 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30988 index deaa657..e0fd296 100644
30989 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30990 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30991 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30992 I915_READ(GTIMR));
30993 }
30994 seq_printf(m, "Interrupts received: %d\n",
30995 - atomic_read(&dev_priv->irq_received));
30996 + atomic_read_unchecked(&dev_priv->irq_received));
30997 for (i = 0; i < I915_NUM_RINGS; i++) {
30998 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30999 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
31000 @@ -1321,7 +1321,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
31001 return ret;
31002
31003 if (opregion->header)
31004 - seq_write(m, opregion->header, OPREGION_SIZE);
31005 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
31006
31007 mutex_unlock(&dev->struct_mutex);
31008
31009 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
31010 index ddfe3d9..f6e6b21 100644
31011 --- a/drivers/gpu/drm/i915/i915_dma.c
31012 +++ b/drivers/gpu/drm/i915/i915_dma.c
31013 @@ -1175,7 +1175,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
31014 bool can_switch;
31015
31016 spin_lock(&dev->count_lock);
31017 - can_switch = (dev->open_count == 0);
31018 + can_switch = (local_read(&dev->open_count) == 0);
31019 spin_unlock(&dev->count_lock);
31020 return can_switch;
31021 }
31022 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
31023 index 9689ca3..294f9c1 100644
31024 --- a/drivers/gpu/drm/i915/i915_drv.h
31025 +++ b/drivers/gpu/drm/i915/i915_drv.h
31026 @@ -231,7 +231,7 @@ struct drm_i915_display_funcs {
31027 /* render clock increase/decrease */
31028 /* display clock increase/decrease */
31029 /* pll clock increase/decrease */
31030 -};
31031 +} __no_const;
31032
31033 struct intel_device_info {
31034 u8 gen;
31035 @@ -320,7 +320,7 @@ typedef struct drm_i915_private {
31036 int current_page;
31037 int page_flipping;
31038
31039 - atomic_t irq_received;
31040 + atomic_unchecked_t irq_received;
31041
31042 /* protects the irq masks */
31043 spinlock_t irq_lock;
31044 @@ -896,7 +896,7 @@ struct drm_i915_gem_object {
31045 * will be page flipped away on the next vblank. When it
31046 * reaches 0, dev_priv->pending_flip_queue will be woken up.
31047 */
31048 - atomic_t pending_flip;
31049 + atomic_unchecked_t pending_flip;
31050 };
31051
31052 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
31053 @@ -1276,7 +1276,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
31054 extern void intel_teardown_gmbus(struct drm_device *dev);
31055 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
31056 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
31057 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
31058 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
31059 {
31060 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
31061 }
31062 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31063 index e159e33..cdcc663 100644
31064 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31065 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
31066 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
31067 i915_gem_clflush_object(obj);
31068
31069 if (obj->base.pending_write_domain)
31070 - cd->flips |= atomic_read(&obj->pending_flip);
31071 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
31072
31073 /* The actual obj->write_domain will be updated with
31074 * pending_write_domain after we emit the accumulated flush for all
31075 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
31076
31077 static int
31078 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
31079 - int count)
31080 + unsigned int count)
31081 {
31082 - int i;
31083 + unsigned int i;
31084
31085 for (i = 0; i < count; i++) {
31086 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
31087 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
31088 index 5bd4361..0241a42 100644
31089 --- a/drivers/gpu/drm/i915/i915_irq.c
31090 +++ b/drivers/gpu/drm/i915/i915_irq.c
31091 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
31092 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
31093 struct drm_i915_master_private *master_priv;
31094
31095 - atomic_inc(&dev_priv->irq_received);
31096 + atomic_inc_unchecked(&dev_priv->irq_received);
31097
31098 /* disable master interrupt before clearing iir */
31099 de_ier = I915_READ(DEIER);
31100 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
31101 struct drm_i915_master_private *master_priv;
31102 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
31103
31104 - atomic_inc(&dev_priv->irq_received);
31105 + atomic_inc_unchecked(&dev_priv->irq_received);
31106
31107 if (IS_GEN6(dev))
31108 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
31109 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
31110 int ret = IRQ_NONE, pipe;
31111 bool blc_event = false;
31112
31113 - atomic_inc(&dev_priv->irq_received);
31114 + atomic_inc_unchecked(&dev_priv->irq_received);
31115
31116 iir = I915_READ(IIR);
31117
31118 @@ -1743,7 +1743,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
31119 {
31120 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31121
31122 - atomic_set(&dev_priv->irq_received, 0);
31123 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31124
31125 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
31126 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
31127 @@ -1932,7 +1932,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
31128 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
31129 int pipe;
31130
31131 - atomic_set(&dev_priv->irq_received, 0);
31132 + atomic_set_unchecked(&dev_priv->irq_received, 0);
31133
31134 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
31135 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
31136 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
31137 index 2163818..cede019 100644
31138 --- a/drivers/gpu/drm/i915/intel_display.c
31139 +++ b/drivers/gpu/drm/i915/intel_display.c
31140 @@ -2238,7 +2238,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
31141
31142 wait_event(dev_priv->pending_flip_queue,
31143 atomic_read(&dev_priv->mm.wedged) ||
31144 - atomic_read(&obj->pending_flip) == 0);
31145 + atomic_read_unchecked(&obj->pending_flip) == 0);
31146
31147 /* Big Hammer, we also need to ensure that any pending
31148 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
31149 @@ -2859,7 +2859,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
31150 obj = to_intel_framebuffer(crtc->fb)->obj;
31151 dev_priv = crtc->dev->dev_private;
31152 wait_event(dev_priv->pending_flip_queue,
31153 - atomic_read(&obj->pending_flip) == 0);
31154 + atomic_read_unchecked(&obj->pending_flip) == 0);
31155 }
31156
31157 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
31158 @@ -7171,7 +7171,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
31159
31160 atomic_clear_mask(1 << intel_crtc->plane,
31161 &obj->pending_flip.counter);
31162 - if (atomic_read(&obj->pending_flip) == 0)
31163 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
31164 wake_up(&dev_priv->pending_flip_queue);
31165
31166 schedule_work(&work->work);
31167 @@ -7354,7 +7354,13 @@ static int intel_gen6_queue_flip(struct drm_device *dev,
31168 OUT_RING(fb->pitches[0] | obj->tiling_mode);
31169 OUT_RING(obj->gtt_offset);
31170
31171 - pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
31172 + /* Contrary to the suggestions in the documentation,
31173 + * "Enable Panel Fitter" does not seem to be required when page
31174 + * flipping with a non-native mode, and worse causes a normal
31175 + * modeset to fail.
31176 + * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
31177 + */
31178 + pf = 0;
31179 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
31180 OUT_RING(pf | pipesrc);
31181 ADVANCE_LP_RING();
31182 @@ -7461,7 +7467,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31183 /* Block clients from rendering to the new back buffer until
31184 * the flip occurs and the object is no longer visible.
31185 */
31186 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31187 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31188
31189 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
31190 if (ret)
31191 @@ -7475,7 +7481,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
31192 return 0;
31193
31194 cleanup_pending:
31195 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31196 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
31197 drm_gem_object_unreference(&work->old_fb_obj->base);
31198 drm_gem_object_unreference(&obj->base);
31199 mutex_unlock(&dev->struct_mutex);
31200 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
31201 index 54558a0..2d97005 100644
31202 --- a/drivers/gpu/drm/mga/mga_drv.h
31203 +++ b/drivers/gpu/drm/mga/mga_drv.h
31204 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
31205 u32 clear_cmd;
31206 u32 maccess;
31207
31208 - atomic_t vbl_received; /**< Number of vblanks received. */
31209 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
31210 wait_queue_head_t fence_queue;
31211 - atomic_t last_fence_retired;
31212 + atomic_unchecked_t last_fence_retired;
31213 u32 next_fence_to_post;
31214
31215 unsigned int fb_cpp;
31216 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
31217 index 2581202..f230a8d9 100644
31218 --- a/drivers/gpu/drm/mga/mga_irq.c
31219 +++ b/drivers/gpu/drm/mga/mga_irq.c
31220 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
31221 if (crtc != 0)
31222 return 0;
31223
31224 - return atomic_read(&dev_priv->vbl_received);
31225 + return atomic_read_unchecked(&dev_priv->vbl_received);
31226 }
31227
31228
31229 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31230 /* VBLANK interrupt */
31231 if (status & MGA_VLINEPEN) {
31232 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
31233 - atomic_inc(&dev_priv->vbl_received);
31234 + atomic_inc_unchecked(&dev_priv->vbl_received);
31235 drm_handle_vblank(dev, 0);
31236 handled = 1;
31237 }
31238 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
31239 if ((prim_start & ~0x03) != (prim_end & ~0x03))
31240 MGA_WRITE(MGA_PRIMEND, prim_end);
31241
31242 - atomic_inc(&dev_priv->last_fence_retired);
31243 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
31244 DRM_WAKEUP(&dev_priv->fence_queue);
31245 handled = 1;
31246 }
31247 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
31248 * using fences.
31249 */
31250 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
31251 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
31252 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
31253 - *sequence) <= (1 << 23)));
31254
31255 *sequence = cur_fence;
31256 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
31257 index e5cbead..6c354a3 100644
31258 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
31259 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
31260 @@ -199,7 +199,7 @@ struct methods {
31261 const char desc[8];
31262 void (*loadbios)(struct drm_device *, uint8_t *);
31263 const bool rw;
31264 -};
31265 +} __do_const;
31266
31267 static struct methods shadow_methods[] = {
31268 { "PRAMIN", load_vbios_pramin, true },
31269 @@ -5290,7 +5290,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
31270 struct bit_table {
31271 const char id;
31272 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
31273 -};
31274 +} __no_const;
31275
31276 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
31277
31278 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
31279 index b827098..c31a797 100644
31280 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
31281 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
31282 @@ -242,7 +242,7 @@ struct nouveau_channel {
31283 struct list_head pending;
31284 uint32_t sequence;
31285 uint32_t sequence_ack;
31286 - atomic_t last_sequence_irq;
31287 + atomic_unchecked_t last_sequence_irq;
31288 struct nouveau_vma vma;
31289 } fence;
31290
31291 @@ -323,7 +323,7 @@ struct nouveau_exec_engine {
31292 u32 handle, u16 class);
31293 void (*set_tile_region)(struct drm_device *dev, int i);
31294 void (*tlb_flush)(struct drm_device *, int engine);
31295 -};
31296 +} __no_const;
31297
31298 struct nouveau_instmem_engine {
31299 void *priv;
31300 @@ -345,13 +345,13 @@ struct nouveau_instmem_engine {
31301 struct nouveau_mc_engine {
31302 int (*init)(struct drm_device *dev);
31303 void (*takedown)(struct drm_device *dev);
31304 -};
31305 +} __no_const;
31306
31307 struct nouveau_timer_engine {
31308 int (*init)(struct drm_device *dev);
31309 void (*takedown)(struct drm_device *dev);
31310 uint64_t (*read)(struct drm_device *dev);
31311 -};
31312 +} __no_const;
31313
31314 struct nouveau_fb_engine {
31315 int num_tiles;
31316 @@ -566,7 +566,7 @@ struct nouveau_vram_engine {
31317 void (*put)(struct drm_device *, struct nouveau_mem **);
31318
31319 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
31320 -};
31321 +} __no_const;
31322
31323 struct nouveau_engine {
31324 struct nouveau_instmem_engine instmem;
31325 @@ -714,7 +714,7 @@ struct drm_nouveau_private {
31326 struct drm_global_reference mem_global_ref;
31327 struct ttm_bo_global_ref bo_global_ref;
31328 struct ttm_bo_device bdev;
31329 - atomic_t validate_sequence;
31330 + atomic_unchecked_t validate_sequence;
31331 } ttm;
31332
31333 struct {
31334 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
31335 index 2f6daae..c9d7b9e 100644
31336 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
31337 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
31338 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
31339 if (USE_REFCNT(dev))
31340 sequence = nvchan_rd32(chan, 0x48);
31341 else
31342 - sequence = atomic_read(&chan->fence.last_sequence_irq);
31343 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
31344
31345 if (chan->fence.sequence_ack == sequence)
31346 goto out;
31347 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
31348 return ret;
31349 }
31350
31351 - atomic_set(&chan->fence.last_sequence_irq, 0);
31352 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
31353 return 0;
31354 }
31355
31356 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31357 index 7ce3fde..cb3ea04 100644
31358 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31359 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31360 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31361 int trycnt = 0;
31362 int ret, i;
31363
31364 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
31365 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
31366 retry:
31367 if (++trycnt > 100000) {
31368 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
31369 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
31370 index f80c5e0..936baa7 100644
31371 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
31372 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
31373 @@ -543,7 +543,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31374 bool can_switch;
31375
31376 spin_lock(&dev->count_lock);
31377 - can_switch = (dev->open_count == 0);
31378 + can_switch = (local_read(&dev->open_count) == 0);
31379 spin_unlock(&dev->count_lock);
31380 return can_switch;
31381 }
31382 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
31383 index dbdea8e..cd6eeeb 100644
31384 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
31385 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
31386 @@ -554,7 +554,7 @@ static int
31387 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
31388 u32 class, u32 mthd, u32 data)
31389 {
31390 - atomic_set(&chan->fence.last_sequence_irq, data);
31391 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
31392 return 0;
31393 }
31394
31395 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31396 index bcac90b..53bfc76 100644
31397 --- a/drivers/gpu/drm/r128/r128_cce.c
31398 +++ b/drivers/gpu/drm/r128/r128_cce.c
31399 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31400
31401 /* GH: Simple idle check.
31402 */
31403 - atomic_set(&dev_priv->idle_count, 0);
31404 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31405
31406 /* We don't support anything other than bus-mastering ring mode,
31407 * but the ring can be in either AGP or PCI space for the ring
31408 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31409 index 930c71b..499aded 100644
31410 --- a/drivers/gpu/drm/r128/r128_drv.h
31411 +++ b/drivers/gpu/drm/r128/r128_drv.h
31412 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31413 int is_pci;
31414 unsigned long cce_buffers_offset;
31415
31416 - atomic_t idle_count;
31417 + atomic_unchecked_t idle_count;
31418
31419 int page_flipping;
31420 int current_page;
31421 u32 crtc_offset;
31422 u32 crtc_offset_cntl;
31423
31424 - atomic_t vbl_received;
31425 + atomic_unchecked_t vbl_received;
31426
31427 u32 color_fmt;
31428 unsigned int front_offset;
31429 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31430 index 429d5a0..7e899ed 100644
31431 --- a/drivers/gpu/drm/r128/r128_irq.c
31432 +++ b/drivers/gpu/drm/r128/r128_irq.c
31433 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31434 if (crtc != 0)
31435 return 0;
31436
31437 - return atomic_read(&dev_priv->vbl_received);
31438 + return atomic_read_unchecked(&dev_priv->vbl_received);
31439 }
31440
31441 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31442 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31443 /* VBLANK interrupt */
31444 if (status & R128_CRTC_VBLANK_INT) {
31445 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31446 - atomic_inc(&dev_priv->vbl_received);
31447 + atomic_inc_unchecked(&dev_priv->vbl_received);
31448 drm_handle_vblank(dev, 0);
31449 return IRQ_HANDLED;
31450 }
31451 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31452 index a9e33ce..09edd4b 100644
31453 --- a/drivers/gpu/drm/r128/r128_state.c
31454 +++ b/drivers/gpu/drm/r128/r128_state.c
31455 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31456
31457 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31458 {
31459 - if (atomic_read(&dev_priv->idle_count) == 0)
31460 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31461 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31462 else
31463 - atomic_set(&dev_priv->idle_count, 0);
31464 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31465 }
31466
31467 #endif
31468 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31469 index 5a82b6b..9e69c73 100644
31470 --- a/drivers/gpu/drm/radeon/mkregtable.c
31471 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31472 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31473 regex_t mask_rex;
31474 regmatch_t match[4];
31475 char buf[1024];
31476 - size_t end;
31477 + long end;
31478 int len;
31479 int done = 0;
31480 int r;
31481 unsigned o;
31482 struct offset *offset;
31483 char last_reg_s[10];
31484 - int last_reg;
31485 + unsigned long last_reg;
31486
31487 if (regcomp
31488 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31489 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31490 index 1668ec1..30ebdab 100644
31491 --- a/drivers/gpu/drm/radeon/radeon.h
31492 +++ b/drivers/gpu/drm/radeon/radeon.h
31493 @@ -250,7 +250,7 @@ struct radeon_fence_driver {
31494 uint32_t scratch_reg;
31495 uint64_t gpu_addr;
31496 volatile uint32_t *cpu_addr;
31497 - atomic_t seq;
31498 + atomic_unchecked_t seq;
31499 uint32_t last_seq;
31500 unsigned long last_jiffies;
31501 unsigned long last_timeout;
31502 @@ -752,7 +752,7 @@ struct r600_blit_cp_primitives {
31503 int x2, int y2);
31504 void (*draw_auto)(struct radeon_device *rdev);
31505 void (*set_default_state)(struct radeon_device *rdev);
31506 -};
31507 +} __no_const;
31508
31509 struct r600_blit {
31510 struct mutex mutex;
31511 @@ -1201,7 +1201,7 @@ struct radeon_asic {
31512 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
31513 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31514 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31515 -};
31516 +} __no_const;
31517
31518 /*
31519 * Asic structures
31520 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31521 index 49f7cb7..2fcb48f 100644
31522 --- a/drivers/gpu/drm/radeon/radeon_device.c
31523 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31524 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31525 bool can_switch;
31526
31527 spin_lock(&dev->count_lock);
31528 - can_switch = (dev->open_count == 0);
31529 + can_switch = (local_read(&dev->open_count) == 0);
31530 spin_unlock(&dev->count_lock);
31531 return can_switch;
31532 }
31533 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31534 index a1b59ca..86f2d44 100644
31535 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31536 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31537 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31538
31539 /* SW interrupt */
31540 wait_queue_head_t swi_queue;
31541 - atomic_t swi_emitted;
31542 + atomic_unchecked_t swi_emitted;
31543 int vblank_crtc;
31544 uint32_t irq_enable_reg;
31545 uint32_t r500_disp_irq_reg;
31546 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
31547 index 4bd36a3..e66fe9c 100644
31548 --- a/drivers/gpu/drm/radeon/radeon_fence.c
31549 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
31550 @@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
31551 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
31552 return 0;
31553 }
31554 - fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
31555 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
31556 if (!rdev->ring[fence->ring].ready)
31557 /* FIXME: cp is not running assume everythings is done right
31558 * away
31559 @@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
31560 }
31561 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
31562 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
31563 - radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
31564 + radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
31565 rdev->fence_drv[ring].initialized = true;
31566 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
31567 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
31568 @@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
31569 rdev->fence_drv[ring].scratch_reg = -1;
31570 rdev->fence_drv[ring].cpu_addr = NULL;
31571 rdev->fence_drv[ring].gpu_addr = 0;
31572 - atomic_set(&rdev->fence_drv[ring].seq, 0);
31573 + atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
31574 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
31575 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
31576 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
31577 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31578 index 48b7cea..342236f 100644
31579 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31580 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31581 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31582 request = compat_alloc_user_space(sizeof(*request));
31583 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31584 || __put_user(req32.param, &request->param)
31585 - || __put_user((void __user *)(unsigned long)req32.value,
31586 + || __put_user((unsigned long)req32.value,
31587 &request->value))
31588 return -EFAULT;
31589
31590 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31591 index 00da384..32f972d 100644
31592 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31593 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31594 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31595 unsigned int ret;
31596 RING_LOCALS;
31597
31598 - atomic_inc(&dev_priv->swi_emitted);
31599 - ret = atomic_read(&dev_priv->swi_emitted);
31600 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31601 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31602
31603 BEGIN_RING(4);
31604 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31605 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31606 drm_radeon_private_t *dev_priv =
31607 (drm_radeon_private_t *) dev->dev_private;
31608
31609 - atomic_set(&dev_priv->swi_emitted, 0);
31610 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31611 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31612
31613 dev->max_vblank_count = 0x001fffff;
31614 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31615 index e8422ae..d22d4a8 100644
31616 --- a/drivers/gpu/drm/radeon/radeon_state.c
31617 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31618 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31619 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31620 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31621
31622 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31623 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31624 sarea_priv->nbox * sizeof(depth_boxes[0])))
31625 return -EFAULT;
31626
31627 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31628 {
31629 drm_radeon_private_t *dev_priv = dev->dev_private;
31630 drm_radeon_getparam_t *param = data;
31631 - int value;
31632 + int value = 0;
31633
31634 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31635
31636 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31637 index c421e77..e6bf2e8 100644
31638 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31639 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31640 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31641 }
31642 if (unlikely(ttm_vm_ops == NULL)) {
31643 ttm_vm_ops = vma->vm_ops;
31644 - radeon_ttm_vm_ops = *ttm_vm_ops;
31645 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31646 + pax_open_kernel();
31647 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31648 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31649 + pax_close_kernel();
31650 }
31651 vma->vm_ops = &radeon_ttm_vm_ops;
31652 return 0;
31653 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31654 index f68dff2..8df955c 100644
31655 --- a/drivers/gpu/drm/radeon/rs690.c
31656 +++ b/drivers/gpu/drm/radeon/rs690.c
31657 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31658 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31659 rdev->pm.sideport_bandwidth.full)
31660 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31661 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31662 + read_delay_latency.full = dfixed_const(800 * 1000);
31663 read_delay_latency.full = dfixed_div(read_delay_latency,
31664 rdev->pm.igp_sideport_mclk);
31665 + a.full = dfixed_const(370);
31666 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31667 } else {
31668 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31669 rdev->pm.k8_bandwidth.full)
31670 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31671 index 499debd..66fce72 100644
31672 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31673 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31674 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
31675 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31676 struct shrink_control *sc)
31677 {
31678 - static atomic_t start_pool = ATOMIC_INIT(0);
31679 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31680 unsigned i;
31681 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31682 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31683 struct ttm_page_pool *pool;
31684 int shrink_pages = sc->nr_to_scan;
31685
31686 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31687 index 88edacc..1e5412b 100644
31688 --- a/drivers/gpu/drm/via/via_drv.h
31689 +++ b/drivers/gpu/drm/via/via_drv.h
31690 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31691 typedef uint32_t maskarray_t[5];
31692
31693 typedef struct drm_via_irq {
31694 - atomic_t irq_received;
31695 + atomic_unchecked_t irq_received;
31696 uint32_t pending_mask;
31697 uint32_t enable_mask;
31698 wait_queue_head_t irq_queue;
31699 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31700 struct timeval last_vblank;
31701 int last_vblank_valid;
31702 unsigned usec_per_vblank;
31703 - atomic_t vbl_received;
31704 + atomic_unchecked_t vbl_received;
31705 drm_via_state_t hc_state;
31706 char pci_buf[VIA_PCI_BUF_SIZE];
31707 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31708 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31709 index d391f48..10c8ca3 100644
31710 --- a/drivers/gpu/drm/via/via_irq.c
31711 +++ b/drivers/gpu/drm/via/via_irq.c
31712 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31713 if (crtc != 0)
31714 return 0;
31715
31716 - return atomic_read(&dev_priv->vbl_received);
31717 + return atomic_read_unchecked(&dev_priv->vbl_received);
31718 }
31719
31720 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31721 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31722
31723 status = VIA_READ(VIA_REG_INTERRUPT);
31724 if (status & VIA_IRQ_VBLANK_PENDING) {
31725 - atomic_inc(&dev_priv->vbl_received);
31726 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31727 + atomic_inc_unchecked(&dev_priv->vbl_received);
31728 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31729 do_gettimeofday(&cur_vblank);
31730 if (dev_priv->last_vblank_valid) {
31731 dev_priv->usec_per_vblank =
31732 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31733 dev_priv->last_vblank = cur_vblank;
31734 dev_priv->last_vblank_valid = 1;
31735 }
31736 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31737 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31738 DRM_DEBUG("US per vblank is: %u\n",
31739 dev_priv->usec_per_vblank);
31740 }
31741 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31742
31743 for (i = 0; i < dev_priv->num_irqs; ++i) {
31744 if (status & cur_irq->pending_mask) {
31745 - atomic_inc(&cur_irq->irq_received);
31746 + atomic_inc_unchecked(&cur_irq->irq_received);
31747 DRM_WAKEUP(&cur_irq->irq_queue);
31748 handled = 1;
31749 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31750 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31751 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31752 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31753 masks[irq][4]));
31754 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31755 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31756 } else {
31757 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31758 (((cur_irq_sequence =
31759 - atomic_read(&cur_irq->irq_received)) -
31760 + atomic_read_unchecked(&cur_irq->irq_received)) -
31761 *sequence) <= (1 << 23)));
31762 }
31763 *sequence = cur_irq_sequence;
31764 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31765 }
31766
31767 for (i = 0; i < dev_priv->num_irqs; ++i) {
31768 - atomic_set(&cur_irq->irq_received, 0);
31769 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31770 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31771 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31772 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31773 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31774 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31775 case VIA_IRQ_RELATIVE:
31776 irqwait->request.sequence +=
31777 - atomic_read(&cur_irq->irq_received);
31778 + atomic_read_unchecked(&cur_irq->irq_received);
31779 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31780 case VIA_IRQ_ABSOLUTE:
31781 break;
31782 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31783 index dc27970..f18b008 100644
31784 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31785 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31786 @@ -260,7 +260,7 @@ struct vmw_private {
31787 * Fencing and IRQs.
31788 */
31789
31790 - atomic_t marker_seq;
31791 + atomic_unchecked_t marker_seq;
31792 wait_queue_head_t fence_queue;
31793 wait_queue_head_t fifo_queue;
31794 int fence_queue_waiters; /* Protected by hw_mutex */
31795 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31796 index a0c2f12..68ae6cb 100644
31797 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31798 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31799 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31800 (unsigned int) min,
31801 (unsigned int) fifo->capabilities);
31802
31803 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31804 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31805 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31806 vmw_marker_queue_init(&fifo->marker_queue);
31807 return vmw_fifo_send_fence(dev_priv, &dummy);
31808 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31809 if (reserveable)
31810 iowrite32(bytes, fifo_mem +
31811 SVGA_FIFO_RESERVED);
31812 - return fifo_mem + (next_cmd >> 2);
31813 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31814 } else {
31815 need_bounce = true;
31816 }
31817 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31818
31819 fm = vmw_fifo_reserve(dev_priv, bytes);
31820 if (unlikely(fm == NULL)) {
31821 - *seqno = atomic_read(&dev_priv->marker_seq);
31822 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31823 ret = -ENOMEM;
31824 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31825 false, 3*HZ);
31826 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31827 }
31828
31829 do {
31830 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31831 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31832 } while (*seqno == 0);
31833
31834 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31835 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31836 index cabc95f..14b3d77 100644
31837 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31838 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31839 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31840 * emitted. Then the fence is stale and signaled.
31841 */
31842
31843 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31844 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31845 > VMW_FENCE_WRAP);
31846
31847 return ret;
31848 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31849
31850 if (fifo_idle)
31851 down_read(&fifo_state->rwsem);
31852 - signal_seq = atomic_read(&dev_priv->marker_seq);
31853 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31854 ret = 0;
31855
31856 for (;;) {
31857 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31858 index 8a8725c..afed796 100644
31859 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31860 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31861 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31862 while (!vmw_lag_lt(queue, us)) {
31863 spin_lock(&queue->lock);
31864 if (list_empty(&queue->head))
31865 - seqno = atomic_read(&dev_priv->marker_seq);
31866 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31867 else {
31868 marker = list_first_entry(&queue->head,
31869 struct vmw_marker, head);
31870 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31871 index 75dbe34..f9204a8 100644
31872 --- a/drivers/hid/hid-core.c
31873 +++ b/drivers/hid/hid-core.c
31874 @@ -2021,7 +2021,7 @@ static bool hid_ignore(struct hid_device *hdev)
31875
31876 int hid_add_device(struct hid_device *hdev)
31877 {
31878 - static atomic_t id = ATOMIC_INIT(0);
31879 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31880 int ret;
31881
31882 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31883 @@ -2036,7 +2036,7 @@ int hid_add_device(struct hid_device *hdev)
31884 /* XXX hack, any other cleaner solution after the driver core
31885 * is converted to allow more than 20 bytes as the device name? */
31886 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31887 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31888 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31889
31890 hid_debug_register(hdev, dev_name(&hdev->dev));
31891 ret = device_add(&hdev->dev);
31892 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31893 index b1ec0e2..c295a61 100644
31894 --- a/drivers/hid/usbhid/hiddev.c
31895 +++ b/drivers/hid/usbhid/hiddev.c
31896 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31897 break;
31898
31899 case HIDIOCAPPLICATION:
31900 - if (arg < 0 || arg >= hid->maxapplication)
31901 + if (arg >= hid->maxapplication)
31902 break;
31903
31904 for (i = 0; i < hid->maxcollection; i++)
31905 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31906 index 4065374..10ed7dc 100644
31907 --- a/drivers/hv/channel.c
31908 +++ b/drivers/hv/channel.c
31909 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31910 int ret = 0;
31911 int t;
31912
31913 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31914 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31915 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31916 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31917
31918 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31919 if (ret)
31920 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31921 index 12aa97f..c0679f7 100644
31922 --- a/drivers/hv/hv.c
31923 +++ b/drivers/hv/hv.c
31924 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31925 u64 output_address = (output) ? virt_to_phys(output) : 0;
31926 u32 output_address_hi = output_address >> 32;
31927 u32 output_address_lo = output_address & 0xFFFFFFFF;
31928 - void *hypercall_page = hv_context.hypercall_page;
31929 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31930
31931 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31932 "=a"(hv_status_lo) : "d" (control_hi),
31933 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31934 index 6d7d286..92b0873 100644
31935 --- a/drivers/hv/hyperv_vmbus.h
31936 +++ b/drivers/hv/hyperv_vmbus.h
31937 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
31938 struct vmbus_connection {
31939 enum vmbus_connect_state conn_state;
31940
31941 - atomic_t next_gpadl_handle;
31942 + atomic_unchecked_t next_gpadl_handle;
31943
31944 /*
31945 * Represents channel interrupts. Each bit position represents a
31946 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31947 index a220e57..428f54d 100644
31948 --- a/drivers/hv/vmbus_drv.c
31949 +++ b/drivers/hv/vmbus_drv.c
31950 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31951 {
31952 int ret = 0;
31953
31954 - static atomic_t device_num = ATOMIC_INIT(0);
31955 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31956
31957 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31958 - atomic_inc_return(&device_num));
31959 + atomic_inc_return_unchecked(&device_num));
31960
31961 child_device_obj->device.bus = &hv_bus;
31962 child_device_obj->device.parent = &hv_acpi_dev->dev;
31963 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31964 index 554f046..f8b4729 100644
31965 --- a/drivers/hwmon/acpi_power_meter.c
31966 +++ b/drivers/hwmon/acpi_power_meter.c
31967 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31968 return res;
31969
31970 temp /= 1000;
31971 - if (temp < 0)
31972 - return -EINVAL;
31973
31974 mutex_lock(&resource->lock);
31975 resource->trip[attr->index - 7] = temp;
31976 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31977 index 91fdd1f..b66a686 100644
31978 --- a/drivers/hwmon/sht15.c
31979 +++ b/drivers/hwmon/sht15.c
31980 @@ -166,7 +166,7 @@ struct sht15_data {
31981 int supply_uV;
31982 bool supply_uV_valid;
31983 struct work_struct update_supply_work;
31984 - atomic_t interrupt_handled;
31985 + atomic_unchecked_t interrupt_handled;
31986 };
31987
31988 /**
31989 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31990 return ret;
31991
31992 gpio_direction_input(data->pdata->gpio_data);
31993 - atomic_set(&data->interrupt_handled, 0);
31994 + atomic_set_unchecked(&data->interrupt_handled, 0);
31995
31996 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31997 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31998 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31999 /* Only relevant if the interrupt hasn't occurred. */
32000 - if (!atomic_read(&data->interrupt_handled))
32001 + if (!atomic_read_unchecked(&data->interrupt_handled))
32002 schedule_work(&data->read_work);
32003 }
32004 ret = wait_event_timeout(data->wait_queue,
32005 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
32006
32007 /* First disable the interrupt */
32008 disable_irq_nosync(irq);
32009 - atomic_inc(&data->interrupt_handled);
32010 + atomic_inc_unchecked(&data->interrupt_handled);
32011 /* Then schedule a reading work struct */
32012 if (data->state != SHT15_READING_NOTHING)
32013 schedule_work(&data->read_work);
32014 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
32015 * If not, then start the interrupt again - care here as could
32016 * have gone low in meantime so verify it hasn't!
32017 */
32018 - atomic_set(&data->interrupt_handled, 0);
32019 + atomic_set_unchecked(&data->interrupt_handled, 0);
32020 enable_irq(gpio_to_irq(data->pdata->gpio_data));
32021 /* If still not occurred or another handler has been scheduled */
32022 if (gpio_get_value(data->pdata->gpio_data)
32023 - || atomic_read(&data->interrupt_handled))
32024 + || atomic_read_unchecked(&data->interrupt_handled))
32025 return;
32026 }
32027
32028 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
32029 index 378fcb5..5e91fa8 100644
32030 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
32031 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
32032 @@ -43,7 +43,7 @@
32033 extern struct i2c_adapter amd756_smbus;
32034
32035 static struct i2c_adapter *s4882_adapter;
32036 -static struct i2c_algorithm *s4882_algo;
32037 +static i2c_algorithm_no_const *s4882_algo;
32038
32039 /* Wrapper access functions for multiplexed SMBus */
32040 static DEFINE_MUTEX(amd756_lock);
32041 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
32042 index 29015eb..af2d8e9 100644
32043 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
32044 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
32045 @@ -41,7 +41,7 @@
32046 extern struct i2c_adapter *nforce2_smbus;
32047
32048 static struct i2c_adapter *s4985_adapter;
32049 -static struct i2c_algorithm *s4985_algo;
32050 +static i2c_algorithm_no_const *s4985_algo;
32051
32052 /* Wrapper access functions for multiplexed SMBus */
32053 static DEFINE_MUTEX(nforce2_lock);
32054 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
32055 index d7a4833..7fae376 100644
32056 --- a/drivers/i2c/i2c-mux.c
32057 +++ b/drivers/i2c/i2c-mux.c
32058 @@ -28,7 +28,7 @@
32059 /* multiplexer per channel data */
32060 struct i2c_mux_priv {
32061 struct i2c_adapter adap;
32062 - struct i2c_algorithm algo;
32063 + i2c_algorithm_no_const algo;
32064
32065 struct i2c_adapter *parent;
32066 void *mux_dev; /* the mux chip/device */
32067 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
32068 index 57d00ca..0145194 100644
32069 --- a/drivers/ide/aec62xx.c
32070 +++ b/drivers/ide/aec62xx.c
32071 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
32072 .cable_detect = atp86x_cable_detect,
32073 };
32074
32075 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
32076 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
32077 { /* 0: AEC6210 */
32078 .name = DRV_NAME,
32079 .init_chipset = init_chipset_aec62xx,
32080 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
32081 index 2c8016a..911a27c 100644
32082 --- a/drivers/ide/alim15x3.c
32083 +++ b/drivers/ide/alim15x3.c
32084 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
32085 .dma_sff_read_status = ide_dma_sff_read_status,
32086 };
32087
32088 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
32089 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
32090 .name = DRV_NAME,
32091 .init_chipset = init_chipset_ali15x3,
32092 .init_hwif = init_hwif_ali15x3,
32093 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
32094 index 3747b25..56fc995 100644
32095 --- a/drivers/ide/amd74xx.c
32096 +++ b/drivers/ide/amd74xx.c
32097 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
32098 .udma_mask = udma, \
32099 }
32100
32101 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
32102 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
32103 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
32104 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
32105 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
32106 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
32107 index 15f0ead..cb43480 100644
32108 --- a/drivers/ide/atiixp.c
32109 +++ b/drivers/ide/atiixp.c
32110 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
32111 .cable_detect = atiixp_cable_detect,
32112 };
32113
32114 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
32115 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
32116 { /* 0: IXP200/300/400/700 */
32117 .name = DRV_NAME,
32118 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
32119 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
32120 index 5f80312..d1fc438 100644
32121 --- a/drivers/ide/cmd64x.c
32122 +++ b/drivers/ide/cmd64x.c
32123 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
32124 .dma_sff_read_status = ide_dma_sff_read_status,
32125 };
32126
32127 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
32128 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
32129 { /* 0: CMD643 */
32130 .name = DRV_NAME,
32131 .init_chipset = init_chipset_cmd64x,
32132 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
32133 index 2c1e5f7..1444762 100644
32134 --- a/drivers/ide/cs5520.c
32135 +++ b/drivers/ide/cs5520.c
32136 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
32137 .set_dma_mode = cs5520_set_dma_mode,
32138 };
32139
32140 -static const struct ide_port_info cyrix_chipset __devinitdata = {
32141 +static const struct ide_port_info cyrix_chipset __devinitconst = {
32142 .name = DRV_NAME,
32143 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
32144 .port_ops = &cs5520_port_ops,
32145 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
32146 index 4dc4eb9..49b40ad 100644
32147 --- a/drivers/ide/cs5530.c
32148 +++ b/drivers/ide/cs5530.c
32149 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
32150 .udma_filter = cs5530_udma_filter,
32151 };
32152
32153 -static const struct ide_port_info cs5530_chipset __devinitdata = {
32154 +static const struct ide_port_info cs5530_chipset __devinitconst = {
32155 .name = DRV_NAME,
32156 .init_chipset = init_chipset_cs5530,
32157 .init_hwif = init_hwif_cs5530,
32158 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
32159 index 5059faf..18d4c85 100644
32160 --- a/drivers/ide/cs5535.c
32161 +++ b/drivers/ide/cs5535.c
32162 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
32163 .cable_detect = cs5535_cable_detect,
32164 };
32165
32166 -static const struct ide_port_info cs5535_chipset __devinitdata = {
32167 +static const struct ide_port_info cs5535_chipset __devinitconst = {
32168 .name = DRV_NAME,
32169 .port_ops = &cs5535_port_ops,
32170 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
32171 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
32172 index 847553f..3ffb49d 100644
32173 --- a/drivers/ide/cy82c693.c
32174 +++ b/drivers/ide/cy82c693.c
32175 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
32176 .set_dma_mode = cy82c693_set_dma_mode,
32177 };
32178
32179 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
32180 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
32181 .name = DRV_NAME,
32182 .init_iops = init_iops_cy82c693,
32183 .port_ops = &cy82c693_port_ops,
32184 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
32185 index 58c51cd..4aec3b8 100644
32186 --- a/drivers/ide/hpt366.c
32187 +++ b/drivers/ide/hpt366.c
32188 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
32189 }
32190 };
32191
32192 -static const struct hpt_info hpt36x __devinitdata = {
32193 +static const struct hpt_info hpt36x __devinitconst = {
32194 .chip_name = "HPT36x",
32195 .chip_type = HPT36x,
32196 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
32197 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
32198 .timings = &hpt36x_timings
32199 };
32200
32201 -static const struct hpt_info hpt370 __devinitdata = {
32202 +static const struct hpt_info hpt370 __devinitconst = {
32203 .chip_name = "HPT370",
32204 .chip_type = HPT370,
32205 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32206 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
32207 .timings = &hpt37x_timings
32208 };
32209
32210 -static const struct hpt_info hpt370a __devinitdata = {
32211 +static const struct hpt_info hpt370a __devinitconst = {
32212 .chip_name = "HPT370A",
32213 .chip_type = HPT370A,
32214 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
32215 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
32216 .timings = &hpt37x_timings
32217 };
32218
32219 -static const struct hpt_info hpt374 __devinitdata = {
32220 +static const struct hpt_info hpt374 __devinitconst = {
32221 .chip_name = "HPT374",
32222 .chip_type = HPT374,
32223 .udma_mask = ATA_UDMA5,
32224 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
32225 .timings = &hpt37x_timings
32226 };
32227
32228 -static const struct hpt_info hpt372 __devinitdata = {
32229 +static const struct hpt_info hpt372 __devinitconst = {
32230 .chip_name = "HPT372",
32231 .chip_type = HPT372,
32232 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32233 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
32234 .timings = &hpt37x_timings
32235 };
32236
32237 -static const struct hpt_info hpt372a __devinitdata = {
32238 +static const struct hpt_info hpt372a __devinitconst = {
32239 .chip_name = "HPT372A",
32240 .chip_type = HPT372A,
32241 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32242 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
32243 .timings = &hpt37x_timings
32244 };
32245
32246 -static const struct hpt_info hpt302 __devinitdata = {
32247 +static const struct hpt_info hpt302 __devinitconst = {
32248 .chip_name = "HPT302",
32249 .chip_type = HPT302,
32250 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32251 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
32252 .timings = &hpt37x_timings
32253 };
32254
32255 -static const struct hpt_info hpt371 __devinitdata = {
32256 +static const struct hpt_info hpt371 __devinitconst = {
32257 .chip_name = "HPT371",
32258 .chip_type = HPT371,
32259 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32260 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
32261 .timings = &hpt37x_timings
32262 };
32263
32264 -static const struct hpt_info hpt372n __devinitdata = {
32265 +static const struct hpt_info hpt372n __devinitconst = {
32266 .chip_name = "HPT372N",
32267 .chip_type = HPT372N,
32268 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32269 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
32270 .timings = &hpt37x_timings
32271 };
32272
32273 -static const struct hpt_info hpt302n __devinitdata = {
32274 +static const struct hpt_info hpt302n __devinitconst = {
32275 .chip_name = "HPT302N",
32276 .chip_type = HPT302N,
32277 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32278 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
32279 .timings = &hpt37x_timings
32280 };
32281
32282 -static const struct hpt_info hpt371n __devinitdata = {
32283 +static const struct hpt_info hpt371n __devinitconst = {
32284 .chip_name = "HPT371N",
32285 .chip_type = HPT371N,
32286 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
32287 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
32288 .dma_sff_read_status = ide_dma_sff_read_status,
32289 };
32290
32291 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
32292 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
32293 { /* 0: HPT36x */
32294 .name = DRV_NAME,
32295 .init_chipset = init_chipset_hpt366,
32296 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
32297 index 8126824..55a2798 100644
32298 --- a/drivers/ide/ide-cd.c
32299 +++ b/drivers/ide/ide-cd.c
32300 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
32301 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
32302 if ((unsigned long)buf & alignment
32303 || blk_rq_bytes(rq) & q->dma_pad_mask
32304 - || object_is_on_stack(buf))
32305 + || object_starts_on_stack(buf))
32306 drive->dma = 0;
32307 }
32308 }
32309 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
32310 index 7f56b73..dab5b67 100644
32311 --- a/drivers/ide/ide-pci-generic.c
32312 +++ b/drivers/ide/ide-pci-generic.c
32313 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
32314 .udma_mask = ATA_UDMA6, \
32315 }
32316
32317 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
32318 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
32319 /* 0: Unknown */
32320 DECLARE_GENERIC_PCI_DEV(0),
32321
32322 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
32323 index 560e66d..d5dd180 100644
32324 --- a/drivers/ide/it8172.c
32325 +++ b/drivers/ide/it8172.c
32326 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
32327 .set_dma_mode = it8172_set_dma_mode,
32328 };
32329
32330 -static const struct ide_port_info it8172_port_info __devinitdata = {
32331 +static const struct ide_port_info it8172_port_info __devinitconst = {
32332 .name = DRV_NAME,
32333 .port_ops = &it8172_port_ops,
32334 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
32335 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
32336 index 46816ba..1847aeb 100644
32337 --- a/drivers/ide/it8213.c
32338 +++ b/drivers/ide/it8213.c
32339 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
32340 .cable_detect = it8213_cable_detect,
32341 };
32342
32343 -static const struct ide_port_info it8213_chipset __devinitdata = {
32344 +static const struct ide_port_info it8213_chipset __devinitconst = {
32345 .name = DRV_NAME,
32346 .enablebits = { {0x41, 0x80, 0x80} },
32347 .port_ops = &it8213_port_ops,
32348 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
32349 index 2e3169f..c5611db 100644
32350 --- a/drivers/ide/it821x.c
32351 +++ b/drivers/ide/it821x.c
32352 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
32353 .cable_detect = it821x_cable_detect,
32354 };
32355
32356 -static const struct ide_port_info it821x_chipset __devinitdata = {
32357 +static const struct ide_port_info it821x_chipset __devinitconst = {
32358 .name = DRV_NAME,
32359 .init_chipset = init_chipset_it821x,
32360 .init_hwif = init_hwif_it821x,
32361 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
32362 index 74c2c4a..efddd7d 100644
32363 --- a/drivers/ide/jmicron.c
32364 +++ b/drivers/ide/jmicron.c
32365 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
32366 .cable_detect = jmicron_cable_detect,
32367 };
32368
32369 -static const struct ide_port_info jmicron_chipset __devinitdata = {
32370 +static const struct ide_port_info jmicron_chipset __devinitconst = {
32371 .name = DRV_NAME,
32372 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
32373 .port_ops = &jmicron_port_ops,
32374 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
32375 index 95327a2..73f78d8 100644
32376 --- a/drivers/ide/ns87415.c
32377 +++ b/drivers/ide/ns87415.c
32378 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
32379 .dma_sff_read_status = superio_dma_sff_read_status,
32380 };
32381
32382 -static const struct ide_port_info ns87415_chipset __devinitdata = {
32383 +static const struct ide_port_info ns87415_chipset __devinitconst = {
32384 .name = DRV_NAME,
32385 .init_hwif = init_hwif_ns87415,
32386 .tp_ops = &ns87415_tp_ops,
32387 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
32388 index 1a53a4c..39edc66 100644
32389 --- a/drivers/ide/opti621.c
32390 +++ b/drivers/ide/opti621.c
32391 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
32392 .set_pio_mode = opti621_set_pio_mode,
32393 };
32394
32395 -static const struct ide_port_info opti621_chipset __devinitdata = {
32396 +static const struct ide_port_info opti621_chipset __devinitconst = {
32397 .name = DRV_NAME,
32398 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
32399 .port_ops = &opti621_port_ops,
32400 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
32401 index 9546fe2..2e5ceb6 100644
32402 --- a/drivers/ide/pdc202xx_new.c
32403 +++ b/drivers/ide/pdc202xx_new.c
32404 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32405 .udma_mask = udma, \
32406 }
32407
32408 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32409 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32410 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32411 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32412 };
32413 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32414 index 3a35ec6..5634510 100644
32415 --- a/drivers/ide/pdc202xx_old.c
32416 +++ b/drivers/ide/pdc202xx_old.c
32417 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32418 .max_sectors = sectors, \
32419 }
32420
32421 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32422 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32423 { /* 0: PDC20246 */
32424 .name = DRV_NAME,
32425 .init_chipset = init_chipset_pdc202xx,
32426 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32427 index 1892e81..fe0fd60 100644
32428 --- a/drivers/ide/piix.c
32429 +++ b/drivers/ide/piix.c
32430 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32431 .udma_mask = udma, \
32432 }
32433
32434 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32435 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32436 /* 0: MPIIX */
32437 { /*
32438 * MPIIX actually has only a single IDE channel mapped to
32439 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32440 index a6414a8..c04173e 100644
32441 --- a/drivers/ide/rz1000.c
32442 +++ b/drivers/ide/rz1000.c
32443 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32444 }
32445 }
32446
32447 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32448 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32449 .name = DRV_NAME,
32450 .host_flags = IDE_HFLAG_NO_DMA,
32451 };
32452 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32453 index 356b9b5..d4758eb 100644
32454 --- a/drivers/ide/sc1200.c
32455 +++ b/drivers/ide/sc1200.c
32456 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32457 .dma_sff_read_status = ide_dma_sff_read_status,
32458 };
32459
32460 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32461 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32462 .name = DRV_NAME,
32463 .port_ops = &sc1200_port_ops,
32464 .dma_ops = &sc1200_dma_ops,
32465 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32466 index b7f5b0c..9701038 100644
32467 --- a/drivers/ide/scc_pata.c
32468 +++ b/drivers/ide/scc_pata.c
32469 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32470 .dma_sff_read_status = scc_dma_sff_read_status,
32471 };
32472
32473 -static const struct ide_port_info scc_chipset __devinitdata = {
32474 +static const struct ide_port_info scc_chipset __devinitconst = {
32475 .name = "sccIDE",
32476 .init_iops = init_iops_scc,
32477 .init_dma = scc_init_dma,
32478 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32479 index 35fb8da..24d72ef 100644
32480 --- a/drivers/ide/serverworks.c
32481 +++ b/drivers/ide/serverworks.c
32482 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32483 .cable_detect = svwks_cable_detect,
32484 };
32485
32486 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32487 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32488 { /* 0: OSB4 */
32489 .name = DRV_NAME,
32490 .init_chipset = init_chipset_svwks,
32491 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32492 index ddeda44..46f7e30 100644
32493 --- a/drivers/ide/siimage.c
32494 +++ b/drivers/ide/siimage.c
32495 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32496 .udma_mask = ATA_UDMA6, \
32497 }
32498
32499 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32500 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32501 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32502 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32503 };
32504 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32505 index 4a00225..09e61b4 100644
32506 --- a/drivers/ide/sis5513.c
32507 +++ b/drivers/ide/sis5513.c
32508 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32509 .cable_detect = sis_cable_detect,
32510 };
32511
32512 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32513 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32514 .name = DRV_NAME,
32515 .init_chipset = init_chipset_sis5513,
32516 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32517 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32518 index f21dc2a..d051cd2 100644
32519 --- a/drivers/ide/sl82c105.c
32520 +++ b/drivers/ide/sl82c105.c
32521 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32522 .dma_sff_read_status = ide_dma_sff_read_status,
32523 };
32524
32525 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32526 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32527 .name = DRV_NAME,
32528 .init_chipset = init_chipset_sl82c105,
32529 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32530 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32531 index 864ffe0..863a5e9 100644
32532 --- a/drivers/ide/slc90e66.c
32533 +++ b/drivers/ide/slc90e66.c
32534 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32535 .cable_detect = slc90e66_cable_detect,
32536 };
32537
32538 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32539 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32540 .name = DRV_NAME,
32541 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32542 .port_ops = &slc90e66_port_ops,
32543 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32544 index 4799d5c..1794678 100644
32545 --- a/drivers/ide/tc86c001.c
32546 +++ b/drivers/ide/tc86c001.c
32547 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32548 .dma_sff_read_status = ide_dma_sff_read_status,
32549 };
32550
32551 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32552 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32553 .name = DRV_NAME,
32554 .init_hwif = init_hwif_tc86c001,
32555 .port_ops = &tc86c001_port_ops,
32556 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32557 index 281c914..55ce1b8 100644
32558 --- a/drivers/ide/triflex.c
32559 +++ b/drivers/ide/triflex.c
32560 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32561 .set_dma_mode = triflex_set_mode,
32562 };
32563
32564 -static const struct ide_port_info triflex_device __devinitdata = {
32565 +static const struct ide_port_info triflex_device __devinitconst = {
32566 .name = DRV_NAME,
32567 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32568 .port_ops = &triflex_port_ops,
32569 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32570 index 4b42ca0..e494a98 100644
32571 --- a/drivers/ide/trm290.c
32572 +++ b/drivers/ide/trm290.c
32573 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32574 .dma_check = trm290_dma_check,
32575 };
32576
32577 -static const struct ide_port_info trm290_chipset __devinitdata = {
32578 +static const struct ide_port_info trm290_chipset __devinitconst = {
32579 .name = DRV_NAME,
32580 .init_hwif = init_hwif_trm290,
32581 .tp_ops = &trm290_tp_ops,
32582 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32583 index f46f49c..eb77678 100644
32584 --- a/drivers/ide/via82cxxx.c
32585 +++ b/drivers/ide/via82cxxx.c
32586 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32587 .cable_detect = via82cxxx_cable_detect,
32588 };
32589
32590 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32591 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32592 .name = DRV_NAME,
32593 .init_chipset = init_chipset_via82cxxx,
32594 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32595 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32596 index 73d4531..c90cd2d 100644
32597 --- a/drivers/ieee802154/fakehard.c
32598 +++ b/drivers/ieee802154/fakehard.c
32599 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32600 phy->transmit_power = 0xbf;
32601
32602 dev->netdev_ops = &fake_ops;
32603 - dev->ml_priv = &fake_mlme;
32604 + dev->ml_priv = (void *)&fake_mlme;
32605
32606 priv = netdev_priv(dev);
32607 priv->phy = phy;
32608 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32609 index c889aae..6cf5aa7 100644
32610 --- a/drivers/infiniband/core/cm.c
32611 +++ b/drivers/infiniband/core/cm.c
32612 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32613
32614 struct cm_counter_group {
32615 struct kobject obj;
32616 - atomic_long_t counter[CM_ATTR_COUNT];
32617 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32618 };
32619
32620 struct cm_counter_attribute {
32621 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32622 struct ib_mad_send_buf *msg = NULL;
32623 int ret;
32624
32625 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32626 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32627 counter[CM_REQ_COUNTER]);
32628
32629 /* Quick state check to discard duplicate REQs. */
32630 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32631 if (!cm_id_priv)
32632 return;
32633
32634 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32635 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32636 counter[CM_REP_COUNTER]);
32637 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32638 if (ret)
32639 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32640 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32641 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32642 spin_unlock_irq(&cm_id_priv->lock);
32643 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32644 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32645 counter[CM_RTU_COUNTER]);
32646 goto out;
32647 }
32648 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32649 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32650 dreq_msg->local_comm_id);
32651 if (!cm_id_priv) {
32652 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32653 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32654 counter[CM_DREQ_COUNTER]);
32655 cm_issue_drep(work->port, work->mad_recv_wc);
32656 return -EINVAL;
32657 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32658 case IB_CM_MRA_REP_RCVD:
32659 break;
32660 case IB_CM_TIMEWAIT:
32661 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32662 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32663 counter[CM_DREQ_COUNTER]);
32664 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32665 goto unlock;
32666 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32667 cm_free_msg(msg);
32668 goto deref;
32669 case IB_CM_DREQ_RCVD:
32670 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32671 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32672 counter[CM_DREQ_COUNTER]);
32673 goto unlock;
32674 default:
32675 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32676 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32677 cm_id_priv->msg, timeout)) {
32678 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32679 - atomic_long_inc(&work->port->
32680 + atomic_long_inc_unchecked(&work->port->
32681 counter_group[CM_RECV_DUPLICATES].
32682 counter[CM_MRA_COUNTER]);
32683 goto out;
32684 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32685 break;
32686 case IB_CM_MRA_REQ_RCVD:
32687 case IB_CM_MRA_REP_RCVD:
32688 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32689 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32690 counter[CM_MRA_COUNTER]);
32691 /* fall through */
32692 default:
32693 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32694 case IB_CM_LAP_IDLE:
32695 break;
32696 case IB_CM_MRA_LAP_SENT:
32697 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32698 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32699 counter[CM_LAP_COUNTER]);
32700 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32701 goto unlock;
32702 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32703 cm_free_msg(msg);
32704 goto deref;
32705 case IB_CM_LAP_RCVD:
32706 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32707 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32708 counter[CM_LAP_COUNTER]);
32709 goto unlock;
32710 default:
32711 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32712 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32713 if (cur_cm_id_priv) {
32714 spin_unlock_irq(&cm.lock);
32715 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32716 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32717 counter[CM_SIDR_REQ_COUNTER]);
32718 goto out; /* Duplicate message. */
32719 }
32720 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32721 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32722 msg->retries = 1;
32723
32724 - atomic_long_add(1 + msg->retries,
32725 + atomic_long_add_unchecked(1 + msg->retries,
32726 &port->counter_group[CM_XMIT].counter[attr_index]);
32727 if (msg->retries)
32728 - atomic_long_add(msg->retries,
32729 + atomic_long_add_unchecked(msg->retries,
32730 &port->counter_group[CM_XMIT_RETRIES].
32731 counter[attr_index]);
32732
32733 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32734 }
32735
32736 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32737 - atomic_long_inc(&port->counter_group[CM_RECV].
32738 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32739 counter[attr_id - CM_ATTR_ID_OFFSET]);
32740
32741 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32742 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32743 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32744
32745 return sprintf(buf, "%ld\n",
32746 - atomic_long_read(&group->counter[cm_attr->index]));
32747 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32748 }
32749
32750 static const struct sysfs_ops cm_counter_ops = {
32751 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32752 index 176c8f9..2627b62 100644
32753 --- a/drivers/infiniband/core/fmr_pool.c
32754 +++ b/drivers/infiniband/core/fmr_pool.c
32755 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32756
32757 struct task_struct *thread;
32758
32759 - atomic_t req_ser;
32760 - atomic_t flush_ser;
32761 + atomic_unchecked_t req_ser;
32762 + atomic_unchecked_t flush_ser;
32763
32764 wait_queue_head_t force_wait;
32765 };
32766 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32767 struct ib_fmr_pool *pool = pool_ptr;
32768
32769 do {
32770 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32771 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32772 ib_fmr_batch_release(pool);
32773
32774 - atomic_inc(&pool->flush_ser);
32775 + atomic_inc_unchecked(&pool->flush_ser);
32776 wake_up_interruptible(&pool->force_wait);
32777
32778 if (pool->flush_function)
32779 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32780 }
32781
32782 set_current_state(TASK_INTERRUPTIBLE);
32783 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32784 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32785 !kthread_should_stop())
32786 schedule();
32787 __set_current_state(TASK_RUNNING);
32788 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32789 pool->dirty_watermark = params->dirty_watermark;
32790 pool->dirty_len = 0;
32791 spin_lock_init(&pool->pool_lock);
32792 - atomic_set(&pool->req_ser, 0);
32793 - atomic_set(&pool->flush_ser, 0);
32794 + atomic_set_unchecked(&pool->req_ser, 0);
32795 + atomic_set_unchecked(&pool->flush_ser, 0);
32796 init_waitqueue_head(&pool->force_wait);
32797
32798 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32799 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32800 }
32801 spin_unlock_irq(&pool->pool_lock);
32802
32803 - serial = atomic_inc_return(&pool->req_ser);
32804 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32805 wake_up_process(pool->thread);
32806
32807 if (wait_event_interruptible(pool->force_wait,
32808 - atomic_read(&pool->flush_ser) - serial >= 0))
32809 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32810 return -EINTR;
32811
32812 return 0;
32813 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32814 } else {
32815 list_add_tail(&fmr->list, &pool->dirty_list);
32816 if (++pool->dirty_len >= pool->dirty_watermark) {
32817 - atomic_inc(&pool->req_ser);
32818 + atomic_inc_unchecked(&pool->req_ser);
32819 wake_up_process(pool->thread);
32820 }
32821 }
32822 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32823 index 40c8353..946b0e4 100644
32824 --- a/drivers/infiniband/hw/cxgb4/mem.c
32825 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32826 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32827 int err;
32828 struct fw_ri_tpte tpt;
32829 u32 stag_idx;
32830 - static atomic_t key;
32831 + static atomic_unchecked_t key;
32832
32833 if (c4iw_fatal_error(rdev))
32834 return -EIO;
32835 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32836 &rdev->resource.tpt_fifo_lock);
32837 if (!stag_idx)
32838 return -ENOMEM;
32839 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32840 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32841 }
32842 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32843 __func__, stag_state, type, pdid, stag_idx);
32844 diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
32845 index a4de9d5..5fa20c3 100644
32846 --- a/drivers/infiniband/hw/ipath/ipath_fs.c
32847 +++ b/drivers/infiniband/hw/ipath/ipath_fs.c
32848 @@ -126,6 +126,8 @@ static const struct file_operations atomic_counters_ops = {
32849 };
32850
32851 static ssize_t flash_read(struct file *file, char __user *buf,
32852 + size_t count, loff_t *ppos) __size_overflow(3);
32853 +static ssize_t flash_read(struct file *file, char __user *buf,
32854 size_t count, loff_t *ppos)
32855 {
32856 struct ipath_devdata *dd;
32857 @@ -177,6 +179,8 @@ bail:
32858 }
32859
32860 static ssize_t flash_write(struct file *file, const char __user *buf,
32861 + size_t count, loff_t *ppos) __size_overflow(3);
32862 +static ssize_t flash_write(struct file *file, const char __user *buf,
32863 size_t count, loff_t *ppos)
32864 {
32865 struct ipath_devdata *dd;
32866 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32867 index 79b3dbc..96e5fcc 100644
32868 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32869 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32870 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32871 struct ib_atomic_eth *ateth;
32872 struct ipath_ack_entry *e;
32873 u64 vaddr;
32874 - atomic64_t *maddr;
32875 + atomic64_unchecked_t *maddr;
32876 u64 sdata;
32877 u32 rkey;
32878 u8 next;
32879 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32880 IB_ACCESS_REMOTE_ATOMIC)))
32881 goto nack_acc_unlck;
32882 /* Perform atomic OP and save result. */
32883 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32884 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32885 sdata = be64_to_cpu(ateth->swap_data);
32886 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32887 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32888 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32889 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32890 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32891 be64_to_cpu(ateth->compare_data),
32892 sdata);
32893 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32894 index 1f95bba..9530f87 100644
32895 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32896 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32897 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32898 unsigned long flags;
32899 struct ib_wc wc;
32900 u64 sdata;
32901 - atomic64_t *maddr;
32902 + atomic64_unchecked_t *maddr;
32903 enum ib_wc_status send_status;
32904
32905 /*
32906 @@ -382,11 +382,11 @@ again:
32907 IB_ACCESS_REMOTE_ATOMIC)))
32908 goto acc_err;
32909 /* Perform atomic OP and save result. */
32910 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32911 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32912 sdata = wqe->wr.wr.atomic.compare_add;
32913 *(u64 *) sqp->s_sge.sge.vaddr =
32914 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32915 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32916 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32917 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32918 sdata, wqe->wr.wr.atomic.swap);
32919 goto send_comp;
32920 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32921 index 7140199..da60063 100644
32922 --- a/drivers/infiniband/hw/nes/nes.c
32923 +++ b/drivers/infiniband/hw/nes/nes.c
32924 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32925 LIST_HEAD(nes_adapter_list);
32926 static LIST_HEAD(nes_dev_list);
32927
32928 -atomic_t qps_destroyed;
32929 +atomic_unchecked_t qps_destroyed;
32930
32931 static unsigned int ee_flsh_adapter;
32932 static unsigned int sysfs_nonidx_addr;
32933 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32934 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32935 struct nes_adapter *nesadapter = nesdev->nesadapter;
32936
32937 - atomic_inc(&qps_destroyed);
32938 + atomic_inc_unchecked(&qps_destroyed);
32939
32940 /* Free the control structures */
32941
32942 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32943 index c438e46..ca30356 100644
32944 --- a/drivers/infiniband/hw/nes/nes.h
32945 +++ b/drivers/infiniband/hw/nes/nes.h
32946 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32947 extern unsigned int wqm_quanta;
32948 extern struct list_head nes_adapter_list;
32949
32950 -extern atomic_t cm_connects;
32951 -extern atomic_t cm_accepts;
32952 -extern atomic_t cm_disconnects;
32953 -extern atomic_t cm_closes;
32954 -extern atomic_t cm_connecteds;
32955 -extern atomic_t cm_connect_reqs;
32956 -extern atomic_t cm_rejects;
32957 -extern atomic_t mod_qp_timouts;
32958 -extern atomic_t qps_created;
32959 -extern atomic_t qps_destroyed;
32960 -extern atomic_t sw_qps_destroyed;
32961 +extern atomic_unchecked_t cm_connects;
32962 +extern atomic_unchecked_t cm_accepts;
32963 +extern atomic_unchecked_t cm_disconnects;
32964 +extern atomic_unchecked_t cm_closes;
32965 +extern atomic_unchecked_t cm_connecteds;
32966 +extern atomic_unchecked_t cm_connect_reqs;
32967 +extern atomic_unchecked_t cm_rejects;
32968 +extern atomic_unchecked_t mod_qp_timouts;
32969 +extern atomic_unchecked_t qps_created;
32970 +extern atomic_unchecked_t qps_destroyed;
32971 +extern atomic_unchecked_t sw_qps_destroyed;
32972 extern u32 mh_detected;
32973 extern u32 mh_pauses_sent;
32974 extern u32 cm_packets_sent;
32975 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32976 extern u32 cm_packets_received;
32977 extern u32 cm_packets_dropped;
32978 extern u32 cm_packets_retrans;
32979 -extern atomic_t cm_listens_created;
32980 -extern atomic_t cm_listens_destroyed;
32981 +extern atomic_unchecked_t cm_listens_created;
32982 +extern atomic_unchecked_t cm_listens_destroyed;
32983 extern u32 cm_backlog_drops;
32984 -extern atomic_t cm_loopbacks;
32985 -extern atomic_t cm_nodes_created;
32986 -extern atomic_t cm_nodes_destroyed;
32987 -extern atomic_t cm_accel_dropped_pkts;
32988 -extern atomic_t cm_resets_recvd;
32989 -extern atomic_t pau_qps_created;
32990 -extern atomic_t pau_qps_destroyed;
32991 +extern atomic_unchecked_t cm_loopbacks;
32992 +extern atomic_unchecked_t cm_nodes_created;
32993 +extern atomic_unchecked_t cm_nodes_destroyed;
32994 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32995 +extern atomic_unchecked_t cm_resets_recvd;
32996 +extern atomic_unchecked_t pau_qps_created;
32997 +extern atomic_unchecked_t pau_qps_destroyed;
32998
32999 extern u32 int_mod_timer_init;
33000 extern u32 int_mod_cq_depth_256;
33001 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
33002 index a4972ab..1bcfc31 100644
33003 --- a/drivers/infiniband/hw/nes/nes_cm.c
33004 +++ b/drivers/infiniband/hw/nes/nes_cm.c
33005 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
33006 u32 cm_packets_retrans;
33007 u32 cm_packets_created;
33008 u32 cm_packets_received;
33009 -atomic_t cm_listens_created;
33010 -atomic_t cm_listens_destroyed;
33011 +atomic_unchecked_t cm_listens_created;
33012 +atomic_unchecked_t cm_listens_destroyed;
33013 u32 cm_backlog_drops;
33014 -atomic_t cm_loopbacks;
33015 -atomic_t cm_nodes_created;
33016 -atomic_t cm_nodes_destroyed;
33017 -atomic_t cm_accel_dropped_pkts;
33018 -atomic_t cm_resets_recvd;
33019 +atomic_unchecked_t cm_loopbacks;
33020 +atomic_unchecked_t cm_nodes_created;
33021 +atomic_unchecked_t cm_nodes_destroyed;
33022 +atomic_unchecked_t cm_accel_dropped_pkts;
33023 +atomic_unchecked_t cm_resets_recvd;
33024
33025 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
33026 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
33027 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
33028
33029 static struct nes_cm_core *g_cm_core;
33030
33031 -atomic_t cm_connects;
33032 -atomic_t cm_accepts;
33033 -atomic_t cm_disconnects;
33034 -atomic_t cm_closes;
33035 -atomic_t cm_connecteds;
33036 -atomic_t cm_connect_reqs;
33037 -atomic_t cm_rejects;
33038 +atomic_unchecked_t cm_connects;
33039 +atomic_unchecked_t cm_accepts;
33040 +atomic_unchecked_t cm_disconnects;
33041 +atomic_unchecked_t cm_closes;
33042 +atomic_unchecked_t cm_connecteds;
33043 +atomic_unchecked_t cm_connect_reqs;
33044 +atomic_unchecked_t cm_rejects;
33045
33046 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
33047 {
33048 @@ -1274,7 +1274,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
33049 kfree(listener);
33050 listener = NULL;
33051 ret = 0;
33052 - atomic_inc(&cm_listens_destroyed);
33053 + atomic_inc_unchecked(&cm_listens_destroyed);
33054 } else {
33055 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
33056 }
33057 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
33058 cm_node->rem_mac);
33059
33060 add_hte_node(cm_core, cm_node);
33061 - atomic_inc(&cm_nodes_created);
33062 + atomic_inc_unchecked(&cm_nodes_created);
33063
33064 return cm_node;
33065 }
33066 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
33067 }
33068
33069 atomic_dec(&cm_core->node_cnt);
33070 - atomic_inc(&cm_nodes_destroyed);
33071 + atomic_inc_unchecked(&cm_nodes_destroyed);
33072 nesqp = cm_node->nesqp;
33073 if (nesqp) {
33074 nesqp->cm_node = NULL;
33075 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
33076
33077 static void drop_packet(struct sk_buff *skb)
33078 {
33079 - atomic_inc(&cm_accel_dropped_pkts);
33080 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
33081 dev_kfree_skb_any(skb);
33082 }
33083
33084 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
33085 {
33086
33087 int reset = 0; /* whether to send reset in case of err.. */
33088 - atomic_inc(&cm_resets_recvd);
33089 + atomic_inc_unchecked(&cm_resets_recvd);
33090 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
33091 " refcnt=%d\n", cm_node, cm_node->state,
33092 atomic_read(&cm_node->ref_count));
33093 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
33094 rem_ref_cm_node(cm_node->cm_core, cm_node);
33095 return NULL;
33096 }
33097 - atomic_inc(&cm_loopbacks);
33098 + atomic_inc_unchecked(&cm_loopbacks);
33099 loopbackremotenode->loopbackpartner = cm_node;
33100 loopbackremotenode->tcp_cntxt.rcv_wscale =
33101 NES_CM_DEFAULT_RCV_WND_SCALE;
33102 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
33103 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
33104 else {
33105 rem_ref_cm_node(cm_core, cm_node);
33106 - atomic_inc(&cm_accel_dropped_pkts);
33107 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
33108 dev_kfree_skb_any(skb);
33109 }
33110 break;
33111 @@ -2881,7 +2881,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
33112
33113 if ((cm_id) && (cm_id->event_handler)) {
33114 if (issue_disconn) {
33115 - atomic_inc(&cm_disconnects);
33116 + atomic_inc_unchecked(&cm_disconnects);
33117 cm_event.event = IW_CM_EVENT_DISCONNECT;
33118 cm_event.status = disconn_status;
33119 cm_event.local_addr = cm_id->local_addr;
33120 @@ -2903,7 +2903,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
33121 }
33122
33123 if (issue_close) {
33124 - atomic_inc(&cm_closes);
33125 + atomic_inc_unchecked(&cm_closes);
33126 nes_disconnect(nesqp, 1);
33127
33128 cm_id->provider_data = nesqp;
33129 @@ -3039,7 +3039,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
33130
33131 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
33132 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
33133 - atomic_inc(&cm_accepts);
33134 + atomic_inc_unchecked(&cm_accepts);
33135
33136 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
33137 netdev_refcnt_read(nesvnic->netdev));
33138 @@ -3241,7 +3241,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
33139 struct nes_cm_core *cm_core;
33140 u8 *start_buff;
33141
33142 - atomic_inc(&cm_rejects);
33143 + atomic_inc_unchecked(&cm_rejects);
33144 cm_node = (struct nes_cm_node *)cm_id->provider_data;
33145 loopback = cm_node->loopbackpartner;
33146 cm_core = cm_node->cm_core;
33147 @@ -3301,7 +3301,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
33148 ntohl(cm_id->local_addr.sin_addr.s_addr),
33149 ntohs(cm_id->local_addr.sin_port));
33150
33151 - atomic_inc(&cm_connects);
33152 + atomic_inc_unchecked(&cm_connects);
33153 nesqp->active_conn = 1;
33154
33155 /* cache the cm_id in the qp */
33156 @@ -3407,7 +3407,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
33157 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
33158 return err;
33159 }
33160 - atomic_inc(&cm_listens_created);
33161 + atomic_inc_unchecked(&cm_listens_created);
33162 }
33163
33164 cm_id->add_ref(cm_id);
33165 @@ -3508,7 +3508,7 @@ static void cm_event_connected(struct nes_cm_event *event)
33166
33167 if (nesqp->destroyed)
33168 return;
33169 - atomic_inc(&cm_connecteds);
33170 + atomic_inc_unchecked(&cm_connecteds);
33171 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
33172 " local port 0x%04X. jiffies = %lu.\n",
33173 nesqp->hwqp.qp_id,
33174 @@ -3695,7 +3695,7 @@ static void cm_event_reset(struct nes_cm_event *event)
33175
33176 cm_id->add_ref(cm_id);
33177 ret = cm_id->event_handler(cm_id, &cm_event);
33178 - atomic_inc(&cm_closes);
33179 + atomic_inc_unchecked(&cm_closes);
33180 cm_event.event = IW_CM_EVENT_CLOSE;
33181 cm_event.status = 0;
33182 cm_event.provider_data = cm_id->provider_data;
33183 @@ -3731,7 +3731,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
33184 return;
33185 cm_id = cm_node->cm_id;
33186
33187 - atomic_inc(&cm_connect_reqs);
33188 + atomic_inc_unchecked(&cm_connect_reqs);
33189 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33190 cm_node, cm_id, jiffies);
33191
33192 @@ -3771,7 +3771,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
33193 return;
33194 cm_id = cm_node->cm_id;
33195
33196 - atomic_inc(&cm_connect_reqs);
33197 + atomic_inc_unchecked(&cm_connect_reqs);
33198 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
33199 cm_node, cm_id, jiffies);
33200
33201 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
33202 index 3ba7be3..c81f6ff 100644
33203 --- a/drivers/infiniband/hw/nes/nes_mgt.c
33204 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
33205 @@ -40,8 +40,8 @@
33206 #include "nes.h"
33207 #include "nes_mgt.h"
33208
33209 -atomic_t pau_qps_created;
33210 -atomic_t pau_qps_destroyed;
33211 +atomic_unchecked_t pau_qps_created;
33212 +atomic_unchecked_t pau_qps_destroyed;
33213
33214 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
33215 {
33216 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
33217 {
33218 struct sk_buff *skb;
33219 unsigned long flags;
33220 - atomic_inc(&pau_qps_destroyed);
33221 + atomic_inc_unchecked(&pau_qps_destroyed);
33222
33223 /* Free packets that have not yet been forwarded */
33224 /* Lock is acquired by skb_dequeue when removing the skb */
33225 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
33226 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
33227 skb_queue_head_init(&nesqp->pau_list);
33228 spin_lock_init(&nesqp->pau_lock);
33229 - atomic_inc(&pau_qps_created);
33230 + atomic_inc_unchecked(&pau_qps_created);
33231 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
33232 }
33233
33234 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
33235 index f3a3ecf..57d311d 100644
33236 --- a/drivers/infiniband/hw/nes/nes_nic.c
33237 +++ b/drivers/infiniband/hw/nes/nes_nic.c
33238 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
33239 target_stat_values[++index] = mh_detected;
33240 target_stat_values[++index] = mh_pauses_sent;
33241 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
33242 - target_stat_values[++index] = atomic_read(&cm_connects);
33243 - target_stat_values[++index] = atomic_read(&cm_accepts);
33244 - target_stat_values[++index] = atomic_read(&cm_disconnects);
33245 - target_stat_values[++index] = atomic_read(&cm_connecteds);
33246 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
33247 - target_stat_values[++index] = atomic_read(&cm_rejects);
33248 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
33249 - target_stat_values[++index] = atomic_read(&qps_created);
33250 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
33251 - target_stat_values[++index] = atomic_read(&qps_destroyed);
33252 - target_stat_values[++index] = atomic_read(&cm_closes);
33253 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
33254 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
33255 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
33256 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
33257 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
33258 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
33259 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
33260 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
33261 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
33262 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
33263 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
33264 target_stat_values[++index] = cm_packets_sent;
33265 target_stat_values[++index] = cm_packets_bounced;
33266 target_stat_values[++index] = cm_packets_created;
33267 target_stat_values[++index] = cm_packets_received;
33268 target_stat_values[++index] = cm_packets_dropped;
33269 target_stat_values[++index] = cm_packets_retrans;
33270 - target_stat_values[++index] = atomic_read(&cm_listens_created);
33271 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
33272 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
33273 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
33274 target_stat_values[++index] = cm_backlog_drops;
33275 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
33276 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
33277 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
33278 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
33279 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
33280 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
33281 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
33282 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
33283 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
33284 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
33285 target_stat_values[++index] = nesadapter->free_4kpbl;
33286 target_stat_values[++index] = nesadapter->free_256pbl;
33287 target_stat_values[++index] = int_mod_timer_init;
33288 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
33289 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
33290 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
33291 - target_stat_values[++index] = atomic_read(&pau_qps_created);
33292 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
33293 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
33294 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
33295 }
33296
33297 /**
33298 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
33299 index 0927b5c..ed67986 100644
33300 --- a/drivers/infiniband/hw/nes/nes_verbs.c
33301 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
33302 @@ -46,9 +46,9 @@
33303
33304 #include <rdma/ib_umem.h>
33305
33306 -atomic_t mod_qp_timouts;
33307 -atomic_t qps_created;
33308 -atomic_t sw_qps_destroyed;
33309 +atomic_unchecked_t mod_qp_timouts;
33310 +atomic_unchecked_t qps_created;
33311 +atomic_unchecked_t sw_qps_destroyed;
33312
33313 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
33314
33315 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
33316 if (init_attr->create_flags)
33317 return ERR_PTR(-EINVAL);
33318
33319 - atomic_inc(&qps_created);
33320 + atomic_inc_unchecked(&qps_created);
33321 switch (init_attr->qp_type) {
33322 case IB_QPT_RC:
33323 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
33324 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
33325 struct iw_cm_event cm_event;
33326 int ret = 0;
33327
33328 - atomic_inc(&sw_qps_destroyed);
33329 + atomic_inc_unchecked(&sw_qps_destroyed);
33330 nesqp->destroyed = 1;
33331
33332 /* Blow away the connection if it exists. */
33333 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
33334 index b881bdc..c2e360c 100644
33335 --- a/drivers/infiniband/hw/qib/qib.h
33336 +++ b/drivers/infiniband/hw/qib/qib.h
33337 @@ -51,6 +51,7 @@
33338 #include <linux/completion.h>
33339 #include <linux/kref.h>
33340 #include <linux/sched.h>
33341 +#include <linux/slab.h>
33342
33343 #include "qib_common.h"
33344 #include "qib_verbs.h"
33345 diff --git a/drivers/infiniband/hw/qib/qib_fs.c b/drivers/infiniband/hw/qib/qib_fs.c
33346 index 05e0f17..0275789 100644
33347 --- a/drivers/infiniband/hw/qib/qib_fs.c
33348 +++ b/drivers/infiniband/hw/qib/qib_fs.c
33349 @@ -267,6 +267,8 @@ static const struct file_operations qsfp_ops[] = {
33350 };
33351
33352 static ssize_t flash_read(struct file *file, char __user *buf,
33353 + size_t count, loff_t *ppos) __size_overflow(3);
33354 +static ssize_t flash_read(struct file *file, char __user *buf,
33355 size_t count, loff_t *ppos)
33356 {
33357 struct qib_devdata *dd;
33358 @@ -318,6 +320,8 @@ bail:
33359 }
33360
33361 static ssize_t flash_write(struct file *file, const char __user *buf,
33362 + size_t count, loff_t *ppos) __size_overflow(3);
33363 +static ssize_t flash_write(struct file *file, const char __user *buf,
33364 size_t count, loff_t *ppos)
33365 {
33366 struct qib_devdata *dd;
33367 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
33368 index c351aa4..e6967c2 100644
33369 --- a/drivers/input/gameport/gameport.c
33370 +++ b/drivers/input/gameport/gameport.c
33371 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
33372 */
33373 static void gameport_init_port(struct gameport *gameport)
33374 {
33375 - static atomic_t gameport_no = ATOMIC_INIT(0);
33376 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
33377
33378 __module_get(THIS_MODULE);
33379
33380 mutex_init(&gameport->drv_mutex);
33381 device_initialize(&gameport->dev);
33382 dev_set_name(&gameport->dev, "gameport%lu",
33383 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
33384 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
33385 gameport->dev.bus = &gameport_bus;
33386 gameport->dev.release = gameport_release_port;
33387 if (gameport->parent)
33388 diff --git a/drivers/input/input.c b/drivers/input/input.c
33389 index 1f78c95..3cddc6c 100644
33390 --- a/drivers/input/input.c
33391 +++ b/drivers/input/input.c
33392 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
33393 */
33394 int input_register_device(struct input_dev *dev)
33395 {
33396 - static atomic_t input_no = ATOMIC_INIT(0);
33397 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
33398 struct input_handler *handler;
33399 const char *path;
33400 int error;
33401 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
33402 dev->setkeycode = input_default_setkeycode;
33403
33404 dev_set_name(&dev->dev, "input%ld",
33405 - (unsigned long) atomic_inc_return(&input_no) - 1);
33406 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
33407
33408 error = device_add(&dev->dev);
33409 if (error)
33410 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
33411 index b8d8611..7a4a04b 100644
33412 --- a/drivers/input/joystick/sidewinder.c
33413 +++ b/drivers/input/joystick/sidewinder.c
33414 @@ -30,6 +30,7 @@
33415 #include <linux/kernel.h>
33416 #include <linux/module.h>
33417 #include <linux/slab.h>
33418 +#include <linux/sched.h>
33419 #include <linux/init.h>
33420 #include <linux/input.h>
33421 #include <linux/gameport.h>
33422 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
33423 index fd7a0d5..a4af10c 100644
33424 --- a/drivers/input/joystick/xpad.c
33425 +++ b/drivers/input/joystick/xpad.c
33426 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
33427
33428 static int xpad_led_probe(struct usb_xpad *xpad)
33429 {
33430 - static atomic_t led_seq = ATOMIC_INIT(0);
33431 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
33432 long led_no;
33433 struct xpad_led *led;
33434 struct led_classdev *led_cdev;
33435 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
33436 if (!led)
33437 return -ENOMEM;
33438
33439 - led_no = (long)atomic_inc_return(&led_seq) - 1;
33440 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33441
33442 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33443 led->xpad = xpad;
33444 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33445 index 0110b5a..d3ad144 100644
33446 --- a/drivers/input/mousedev.c
33447 +++ b/drivers/input/mousedev.c
33448 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33449
33450 spin_unlock_irq(&client->packet_lock);
33451
33452 - if (copy_to_user(buffer, data, count))
33453 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
33454 return -EFAULT;
33455
33456 return count;
33457 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33458 index ba70058..571d25d 100644
33459 --- a/drivers/input/serio/serio.c
33460 +++ b/drivers/input/serio/serio.c
33461 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
33462 */
33463 static void serio_init_port(struct serio *serio)
33464 {
33465 - static atomic_t serio_no = ATOMIC_INIT(0);
33466 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33467
33468 __module_get(THIS_MODULE);
33469
33470 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
33471 mutex_init(&serio->drv_mutex);
33472 device_initialize(&serio->dev);
33473 dev_set_name(&serio->dev, "serio%ld",
33474 - (long)atomic_inc_return(&serio_no) - 1);
33475 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33476 serio->dev.bus = &serio_bus;
33477 serio->dev.release = serio_release_port;
33478 serio->dev.groups = serio_device_attr_groups;
33479 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33480 index e44933d..9ba484a 100644
33481 --- a/drivers/isdn/capi/capi.c
33482 +++ b/drivers/isdn/capi/capi.c
33483 @@ -83,8 +83,8 @@ struct capiminor {
33484
33485 struct capi20_appl *ap;
33486 u32 ncci;
33487 - atomic_t datahandle;
33488 - atomic_t msgid;
33489 + atomic_unchecked_t datahandle;
33490 + atomic_unchecked_t msgid;
33491
33492 struct tty_port port;
33493 int ttyinstop;
33494 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33495 capimsg_setu16(s, 2, mp->ap->applid);
33496 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33497 capimsg_setu8 (s, 5, CAPI_RESP);
33498 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33499 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33500 capimsg_setu32(s, 8, mp->ncci);
33501 capimsg_setu16(s, 12, datahandle);
33502 }
33503 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
33504 mp->outbytes -= len;
33505 spin_unlock_bh(&mp->outlock);
33506
33507 - datahandle = atomic_inc_return(&mp->datahandle);
33508 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33509 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33510 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33511 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33512 capimsg_setu16(skb->data, 2, mp->ap->applid);
33513 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33514 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33515 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33516 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33517 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33518 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33519 capimsg_setu16(skb->data, 16, len); /* Data length */
33520 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
33521 index db621db..825ea1a 100644
33522 --- a/drivers/isdn/gigaset/common.c
33523 +++ b/drivers/isdn/gigaset/common.c
33524 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
33525 cs->commands_pending = 0;
33526 cs->cur_at_seq = 0;
33527 cs->gotfwver = -1;
33528 - cs->open_count = 0;
33529 + local_set(&cs->open_count, 0);
33530 cs->dev = NULL;
33531 cs->tty = NULL;
33532 cs->tty_dev = NULL;
33533 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
33534 index 212efaf..f187c6b 100644
33535 --- a/drivers/isdn/gigaset/gigaset.h
33536 +++ b/drivers/isdn/gigaset/gigaset.h
33537 @@ -35,6 +35,7 @@
33538 #include <linux/tty_driver.h>
33539 #include <linux/list.h>
33540 #include <linux/atomic.h>
33541 +#include <asm/local.h>
33542
33543 #define GIG_VERSION {0, 5, 0, 0}
33544 #define GIG_COMPAT {0, 4, 0, 0}
33545 @@ -433,7 +434,7 @@ struct cardstate {
33546 spinlock_t cmdlock;
33547 unsigned curlen, cmdbytes;
33548
33549 - unsigned open_count;
33550 + local_t open_count;
33551 struct tty_struct *tty;
33552 struct tasklet_struct if_wake_tasklet;
33553 unsigned control_state;
33554 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33555 index ee0a549..a7c9798 100644
33556 --- a/drivers/isdn/gigaset/interface.c
33557 +++ b/drivers/isdn/gigaset/interface.c
33558 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33559 }
33560 tty->driver_data = cs;
33561
33562 - ++cs->open_count;
33563 -
33564 - if (cs->open_count == 1) {
33565 + if (local_inc_return(&cs->open_count) == 1) {
33566 spin_lock_irqsave(&cs->lock, flags);
33567 cs->tty = tty;
33568 spin_unlock_irqrestore(&cs->lock, flags);
33569 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33570
33571 if (!cs->connected)
33572 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33573 - else if (!cs->open_count)
33574 + else if (!local_read(&cs->open_count))
33575 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33576 else {
33577 - if (!--cs->open_count) {
33578 + if (!local_dec_return(&cs->open_count)) {
33579 spin_lock_irqsave(&cs->lock, flags);
33580 cs->tty = NULL;
33581 spin_unlock_irqrestore(&cs->lock, flags);
33582 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
33583 if (!cs->connected) {
33584 gig_dbg(DEBUG_IF, "not connected");
33585 retval = -ENODEV;
33586 - } else if (!cs->open_count)
33587 + } else if (!local_read(&cs->open_count))
33588 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33589 else {
33590 retval = 0;
33591 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
33592 retval = -ENODEV;
33593 goto done;
33594 }
33595 - if (!cs->open_count) {
33596 + if (!local_read(&cs->open_count)) {
33597 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33598 retval = -ENODEV;
33599 goto done;
33600 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
33601 if (!cs->connected) {
33602 gig_dbg(DEBUG_IF, "not connected");
33603 retval = -ENODEV;
33604 - } else if (!cs->open_count)
33605 + } else if (!local_read(&cs->open_count))
33606 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33607 else if (cs->mstate != MS_LOCKED) {
33608 dev_warn(cs->dev, "can't write to unlocked device\n");
33609 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
33610
33611 if (!cs->connected)
33612 gig_dbg(DEBUG_IF, "not connected");
33613 - else if (!cs->open_count)
33614 + else if (!local_read(&cs->open_count))
33615 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33616 else if (cs->mstate != MS_LOCKED)
33617 dev_warn(cs->dev, "can't write to unlocked device\n");
33618 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
33619
33620 if (!cs->connected)
33621 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33622 - else if (!cs->open_count)
33623 + else if (!local_read(&cs->open_count))
33624 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33625 else
33626 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
33627 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
33628
33629 if (!cs->connected)
33630 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33631 - else if (!cs->open_count)
33632 + else if (!local_read(&cs->open_count))
33633 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33634 else
33635 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
33636 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
33637 goto out;
33638 }
33639
33640 - if (!cs->open_count) {
33641 + if (!local_read(&cs->open_count)) {
33642 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33643 goto out;
33644 }
33645 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33646 index 2a57da59..e7a12ed 100644
33647 --- a/drivers/isdn/hardware/avm/b1.c
33648 +++ b/drivers/isdn/hardware/avm/b1.c
33649 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
33650 }
33651 if (left) {
33652 if (t4file->user) {
33653 - if (copy_from_user(buf, dp, left))
33654 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33655 return -EFAULT;
33656 } else {
33657 memcpy(buf, dp, left);
33658 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
33659 }
33660 if (left) {
33661 if (config->user) {
33662 - if (copy_from_user(buf, dp, left))
33663 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33664 return -EFAULT;
33665 } else {
33666 memcpy(buf, dp, left);
33667 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33668 index 85784a7..a19ca98 100644
33669 --- a/drivers/isdn/hardware/eicon/divasync.h
33670 +++ b/drivers/isdn/hardware/eicon/divasync.h
33671 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33672 } diva_didd_add_adapter_t;
33673 typedef struct _diva_didd_remove_adapter {
33674 IDI_CALL p_request;
33675 -} diva_didd_remove_adapter_t;
33676 +} __no_const diva_didd_remove_adapter_t;
33677 typedef struct _diva_didd_read_adapter_array {
33678 void * buffer;
33679 dword length;
33680 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33681 index a3bd163..8956575 100644
33682 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33683 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33684 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33685 typedef struct _diva_os_idi_adapter_interface {
33686 diva_init_card_proc_t cleanup_adapter_proc;
33687 diva_cmd_card_proc_t cmd_proc;
33688 -} diva_os_idi_adapter_interface_t;
33689 +} __no_const diva_os_idi_adapter_interface_t;
33690
33691 typedef struct _diva_os_xdi_adapter {
33692 struct list_head link;
33693 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33694 index 1f355bb..43f1fea 100644
33695 --- a/drivers/isdn/icn/icn.c
33696 +++ b/drivers/isdn/icn/icn.c
33697 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
33698 if (count > len)
33699 count = len;
33700 if (user) {
33701 - if (copy_from_user(msg, buf, count))
33702 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33703 return -EFAULT;
33704 } else
33705 memcpy(msg, buf, count);
33706 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33707 index b5fdcb7..5b6c59f 100644
33708 --- a/drivers/lguest/core.c
33709 +++ b/drivers/lguest/core.c
33710 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33711 * it's worked so far. The end address needs +1 because __get_vm_area
33712 * allocates an extra guard page, so we need space for that.
33713 */
33714 +
33715 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33716 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33717 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33718 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33719 +#else
33720 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33721 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33722 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33723 +#endif
33724 +
33725 if (!switcher_vma) {
33726 err = -ENOMEM;
33727 printk("lguest: could not map switcher pages high\n");
33728 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33729 * Now the Switcher is mapped at the right address, we can't fail!
33730 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33731 */
33732 - memcpy(switcher_vma->addr, start_switcher_text,
33733 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33734 end_switcher_text - start_switcher_text);
33735
33736 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33737 diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
33738 index ff4a0bc..f5fdd9c 100644
33739 --- a/drivers/lguest/lguest_user.c
33740 +++ b/drivers/lguest/lguest_user.c
33741 @@ -198,6 +198,7 @@ static int user_send_irq(struct lg_cpu *cpu, const unsigned long __user *input)
33742 * Once our Guest is initialized, the Launcher makes it run by reading
33743 * from /dev/lguest.
33744 */
33745 +static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o) __size_overflow(3);
33746 static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
33747 {
33748 struct lguest *lg = file->private_data;
33749 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33750 index 3980903..ce25c5e 100644
33751 --- a/drivers/lguest/x86/core.c
33752 +++ b/drivers/lguest/x86/core.c
33753 @@ -59,7 +59,7 @@ static struct {
33754 /* Offset from where switcher.S was compiled to where we've copied it */
33755 static unsigned long switcher_offset(void)
33756 {
33757 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33758 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33759 }
33760
33761 /* This cpu's struct lguest_pages. */
33762 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33763 * These copies are pretty cheap, so we do them unconditionally: */
33764 /* Save the current Host top-level page directory.
33765 */
33766 +
33767 +#ifdef CONFIG_PAX_PER_CPU_PGD
33768 + pages->state.host_cr3 = read_cr3();
33769 +#else
33770 pages->state.host_cr3 = __pa(current->mm->pgd);
33771 +#endif
33772 +
33773 /*
33774 * Set up the Guest's page tables to see this CPU's pages (and no
33775 * other CPU's pages).
33776 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33777 * compiled-in switcher code and the high-mapped copy we just made.
33778 */
33779 for (i = 0; i < IDT_ENTRIES; i++)
33780 - default_idt_entries[i] += switcher_offset();
33781 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33782
33783 /*
33784 * Set up the Switcher's per-cpu areas.
33785 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33786 * it will be undisturbed when we switch. To change %cs and jump we
33787 * need this structure to feed to Intel's "lcall" instruction.
33788 */
33789 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33790 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33791 lguest_entry.segment = LGUEST_CS;
33792
33793 /*
33794 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33795 index 40634b0..4f5855e 100644
33796 --- a/drivers/lguest/x86/switcher_32.S
33797 +++ b/drivers/lguest/x86/switcher_32.S
33798 @@ -87,6 +87,7 @@
33799 #include <asm/page.h>
33800 #include <asm/segment.h>
33801 #include <asm/lguest.h>
33802 +#include <asm/processor-flags.h>
33803
33804 // We mark the start of the code to copy
33805 // It's placed in .text tho it's never run here
33806 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33807 // Changes type when we load it: damn Intel!
33808 // For after we switch over our page tables
33809 // That entry will be read-only: we'd crash.
33810 +
33811 +#ifdef CONFIG_PAX_KERNEXEC
33812 + mov %cr0, %edx
33813 + xor $X86_CR0_WP, %edx
33814 + mov %edx, %cr0
33815 +#endif
33816 +
33817 movl $(GDT_ENTRY_TSS*8), %edx
33818 ltr %dx
33819
33820 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33821 // Let's clear it again for our return.
33822 // The GDT descriptor of the Host
33823 // Points to the table after two "size" bytes
33824 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33825 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33826 // Clear "used" from type field (byte 5, bit 2)
33827 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33828 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33829 +
33830 +#ifdef CONFIG_PAX_KERNEXEC
33831 + mov %cr0, %eax
33832 + xor $X86_CR0_WP, %eax
33833 + mov %eax, %cr0
33834 +#endif
33835
33836 // Once our page table's switched, the Guest is live!
33837 // The Host fades as we run this final step.
33838 @@ -295,13 +309,12 @@ deliver_to_host:
33839 // I consulted gcc, and it gave
33840 // These instructions, which I gladly credit:
33841 leal (%edx,%ebx,8), %eax
33842 - movzwl (%eax),%edx
33843 - movl 4(%eax), %eax
33844 - xorw %ax, %ax
33845 - orl %eax, %edx
33846 + movl 4(%eax), %edx
33847 + movw (%eax), %dx
33848 // Now the address of the handler's in %edx
33849 // We call it now: its "iret" drops us home.
33850 - jmp *%edx
33851 + ljmp $__KERNEL_CS, $1f
33852 +1: jmp *%edx
33853
33854 // Every interrupt can come to us here
33855 // But we must truly tell each apart.
33856 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33857 index 4daf9e5..b8d1d0f 100644
33858 --- a/drivers/macintosh/macio_asic.c
33859 +++ b/drivers/macintosh/macio_asic.c
33860 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33861 * MacIO is matched against any Apple ID, it's probe() function
33862 * will then decide wether it applies or not
33863 */
33864 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33865 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33866 .vendor = PCI_VENDOR_ID_APPLE,
33867 .device = PCI_ANY_ID,
33868 .subvendor = PCI_ANY_ID,
33869 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33870 index 1ce84ed..0fdd40a 100644
33871 --- a/drivers/md/dm-ioctl.c
33872 +++ b/drivers/md/dm-ioctl.c
33873 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33874 cmd == DM_LIST_VERSIONS_CMD)
33875 return 0;
33876
33877 - if ((cmd == DM_DEV_CREATE_CMD)) {
33878 + if (cmd == DM_DEV_CREATE_CMD) {
33879 if (!*param->name) {
33880 DMWARN("name not supplied when creating device");
33881 return -EINVAL;
33882 diff --git a/drivers/md/dm-log-userspace-transfer.c b/drivers/md/dm-log-userspace-transfer.c
33883 index 1f23e04..08d9a20 100644
33884 --- a/drivers/md/dm-log-userspace-transfer.c
33885 +++ b/drivers/md/dm-log-userspace-transfer.c
33886 @@ -134,7 +134,7 @@ static void cn_ulog_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
33887 {
33888 struct dm_ulog_request *tfr = (struct dm_ulog_request *)(msg + 1);
33889
33890 - if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
33891 + if (!capable(CAP_SYS_ADMIN))
33892 return;
33893
33894 spin_lock(&receiving_list_lock);
33895 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33896 index 9bfd057..5373ff3 100644
33897 --- a/drivers/md/dm-raid1.c
33898 +++ b/drivers/md/dm-raid1.c
33899 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33900
33901 struct mirror {
33902 struct mirror_set *ms;
33903 - atomic_t error_count;
33904 + atomic_unchecked_t error_count;
33905 unsigned long error_type;
33906 struct dm_dev *dev;
33907 sector_t offset;
33908 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33909 struct mirror *m;
33910
33911 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33912 - if (!atomic_read(&m->error_count))
33913 + if (!atomic_read_unchecked(&m->error_count))
33914 return m;
33915
33916 return NULL;
33917 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33918 * simple way to tell if a device has encountered
33919 * errors.
33920 */
33921 - atomic_inc(&m->error_count);
33922 + atomic_inc_unchecked(&m->error_count);
33923
33924 if (test_and_set_bit(error_type, &m->error_type))
33925 return;
33926 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33927 struct mirror *m = get_default_mirror(ms);
33928
33929 do {
33930 - if (likely(!atomic_read(&m->error_count)))
33931 + if (likely(!atomic_read_unchecked(&m->error_count)))
33932 return m;
33933
33934 if (m-- == ms->mirror)
33935 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33936 {
33937 struct mirror *default_mirror = get_default_mirror(m->ms);
33938
33939 - return !atomic_read(&default_mirror->error_count);
33940 + return !atomic_read_unchecked(&default_mirror->error_count);
33941 }
33942
33943 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33944 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33945 */
33946 if (likely(region_in_sync(ms, region, 1)))
33947 m = choose_mirror(ms, bio->bi_sector);
33948 - else if (m && atomic_read(&m->error_count))
33949 + else if (m && atomic_read_unchecked(&m->error_count))
33950 m = NULL;
33951
33952 if (likely(m))
33953 @@ -848,6 +848,10 @@ static void do_mirror(struct work_struct *work)
33954 static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33955 uint32_t region_size,
33956 struct dm_target *ti,
33957 + struct dm_dirty_log *dl) __size_overflow(1);
33958 +static struct mirror_set *alloc_context(unsigned int nr_mirrors,
33959 + uint32_t region_size,
33960 + struct dm_target *ti,
33961 struct dm_dirty_log *dl)
33962 {
33963 size_t len;
33964 @@ -937,7 +941,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33965 }
33966
33967 ms->mirror[mirror].ms = ms;
33968 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33969 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33970 ms->mirror[mirror].error_type = 0;
33971 ms->mirror[mirror].offset = offset;
33972
33973 @@ -1347,7 +1351,7 @@ static void mirror_resume(struct dm_target *ti)
33974 */
33975 static char device_status_char(struct mirror *m)
33976 {
33977 - if (!atomic_read(&(m->error_count)))
33978 + if (!atomic_read_unchecked(&(m->error_count)))
33979 return 'A';
33980
33981 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33982 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33983 index 3d80cf0..7d98e1a 100644
33984 --- a/drivers/md/dm-stripe.c
33985 +++ b/drivers/md/dm-stripe.c
33986 @@ -20,7 +20,7 @@ struct stripe {
33987 struct dm_dev *dev;
33988 sector_t physical_start;
33989
33990 - atomic_t error_count;
33991 + atomic_unchecked_t error_count;
33992 };
33993
33994 struct stripe_c {
33995 @@ -55,6 +55,7 @@ static void trigger_event(struct work_struct *work)
33996 dm_table_event(sc->ti->table);
33997 }
33998
33999 +static inline struct stripe_c *alloc_context(unsigned int stripes) __size_overflow(1);
34000 static inline struct stripe_c *alloc_context(unsigned int stripes)
34001 {
34002 size_t len;
34003 @@ -192,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
34004 kfree(sc);
34005 return r;
34006 }
34007 - atomic_set(&(sc->stripe[i].error_count), 0);
34008 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
34009 }
34010
34011 ti->private = sc;
34012 @@ -314,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
34013 DMEMIT("%d ", sc->stripes);
34014 for (i = 0; i < sc->stripes; i++) {
34015 DMEMIT("%s ", sc->stripe[i].dev->name);
34016 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
34017 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
34018 'D' : 'A';
34019 }
34020 buffer[i] = '\0';
34021 @@ -361,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
34022 */
34023 for (i = 0; i < sc->stripes; i++)
34024 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
34025 - atomic_inc(&(sc->stripe[i].error_count));
34026 - if (atomic_read(&(sc->stripe[i].error_count)) <
34027 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
34028 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
34029 DM_IO_ERROR_THRESHOLD)
34030 schedule_work(&sc->trigger_event);
34031 }
34032 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
34033 index 63cc542..8d45caf3 100644
34034 --- a/drivers/md/dm-table.c
34035 +++ b/drivers/md/dm-table.c
34036 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
34037 if (!dev_size)
34038 return 0;
34039
34040 - if ((start >= dev_size) || (start + len > dev_size)) {
34041 + if ((start >= dev_size) || (len > dev_size - start)) {
34042 DMWARN("%s: %s too small for target: "
34043 "start=%llu, len=%llu, dev_size=%llu",
34044 dm_device_name(ti->table->md), bdevname(bdev, b),
34045 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
34046 index 237571a..fb6d19b 100644
34047 --- a/drivers/md/dm-thin-metadata.c
34048 +++ b/drivers/md/dm-thin-metadata.c
34049 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
34050
34051 pmd->info.tm = tm;
34052 pmd->info.levels = 2;
34053 - pmd->info.value_type.context = pmd->data_sm;
34054 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
34055 pmd->info.value_type.size = sizeof(__le64);
34056 pmd->info.value_type.inc = data_block_inc;
34057 pmd->info.value_type.dec = data_block_dec;
34058 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
34059
34060 pmd->bl_info.tm = tm;
34061 pmd->bl_info.levels = 1;
34062 - pmd->bl_info.value_type.context = pmd->data_sm;
34063 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
34064 pmd->bl_info.value_type.size = sizeof(__le64);
34065 pmd->bl_info.value_type.inc = data_block_inc;
34066 pmd->bl_info.value_type.dec = data_block_dec;
34067 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
34068 index b89c548..2af3ce4 100644
34069 --- a/drivers/md/dm.c
34070 +++ b/drivers/md/dm.c
34071 @@ -176,9 +176,9 @@ struct mapped_device {
34072 /*
34073 * Event handling.
34074 */
34075 - atomic_t event_nr;
34076 + atomic_unchecked_t event_nr;
34077 wait_queue_head_t eventq;
34078 - atomic_t uevent_seq;
34079 + atomic_unchecked_t uevent_seq;
34080 struct list_head uevent_list;
34081 spinlock_t uevent_lock; /* Protect access to uevent_list */
34082
34083 @@ -1844,8 +1844,8 @@ static struct mapped_device *alloc_dev(int minor)
34084 rwlock_init(&md->map_lock);
34085 atomic_set(&md->holders, 1);
34086 atomic_set(&md->open_count, 0);
34087 - atomic_set(&md->event_nr, 0);
34088 - atomic_set(&md->uevent_seq, 0);
34089 + atomic_set_unchecked(&md->event_nr, 0);
34090 + atomic_set_unchecked(&md->uevent_seq, 0);
34091 INIT_LIST_HEAD(&md->uevent_list);
34092 spin_lock_init(&md->uevent_lock);
34093
34094 @@ -1979,7 +1979,7 @@ static void event_callback(void *context)
34095
34096 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
34097
34098 - atomic_inc(&md->event_nr);
34099 + atomic_inc_unchecked(&md->event_nr);
34100 wake_up(&md->eventq);
34101 }
34102
34103 @@ -2621,18 +2621,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
34104
34105 uint32_t dm_next_uevent_seq(struct mapped_device *md)
34106 {
34107 - return atomic_add_return(1, &md->uevent_seq);
34108 + return atomic_add_return_unchecked(1, &md->uevent_seq);
34109 }
34110
34111 uint32_t dm_get_event_nr(struct mapped_device *md)
34112 {
34113 - return atomic_read(&md->event_nr);
34114 + return atomic_read_unchecked(&md->event_nr);
34115 }
34116
34117 int dm_wait_event(struct mapped_device *md, int event_nr)
34118 {
34119 return wait_event_interruptible(md->eventq,
34120 - (event_nr != atomic_read(&md->event_nr)));
34121 + (event_nr != atomic_read_unchecked(&md->event_nr)));
34122 }
34123
34124 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
34125 diff --git a/drivers/md/md.c b/drivers/md/md.c
34126 index 58027d8..d9cddcd 100644
34127 --- a/drivers/md/md.c
34128 +++ b/drivers/md/md.c
34129 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
34130 * start build, activate spare
34131 */
34132 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
34133 -static atomic_t md_event_count;
34134 +static atomic_unchecked_t md_event_count;
34135 void md_new_event(struct mddev *mddev)
34136 {
34137 - atomic_inc(&md_event_count);
34138 + atomic_inc_unchecked(&md_event_count);
34139 wake_up(&md_event_waiters);
34140 }
34141 EXPORT_SYMBOL_GPL(md_new_event);
34142 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
34143 */
34144 static void md_new_event_inintr(struct mddev *mddev)
34145 {
34146 - atomic_inc(&md_event_count);
34147 + atomic_inc_unchecked(&md_event_count);
34148 wake_up(&md_event_waiters);
34149 }
34150
34151 @@ -1524,7 +1524,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
34152
34153 rdev->preferred_minor = 0xffff;
34154 rdev->data_offset = le64_to_cpu(sb->data_offset);
34155 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
34156 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
34157
34158 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
34159 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
34160 @@ -1743,7 +1743,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
34161 else
34162 sb->resync_offset = cpu_to_le64(0);
34163
34164 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
34165 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
34166
34167 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
34168 sb->size = cpu_to_le64(mddev->dev_sectors);
34169 @@ -2689,7 +2689,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
34170 static ssize_t
34171 errors_show(struct md_rdev *rdev, char *page)
34172 {
34173 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
34174 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
34175 }
34176
34177 static ssize_t
34178 @@ -2698,7 +2698,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
34179 char *e;
34180 unsigned long n = simple_strtoul(buf, &e, 10);
34181 if (*buf && (*e == 0 || *e == '\n')) {
34182 - atomic_set(&rdev->corrected_errors, n);
34183 + atomic_set_unchecked(&rdev->corrected_errors, n);
34184 return len;
34185 }
34186 return -EINVAL;
34187 @@ -3084,8 +3084,8 @@ int md_rdev_init(struct md_rdev *rdev)
34188 rdev->sb_loaded = 0;
34189 rdev->bb_page = NULL;
34190 atomic_set(&rdev->nr_pending, 0);
34191 - atomic_set(&rdev->read_errors, 0);
34192 - atomic_set(&rdev->corrected_errors, 0);
34193 + atomic_set_unchecked(&rdev->read_errors, 0);
34194 + atomic_set_unchecked(&rdev->corrected_errors, 0);
34195
34196 INIT_LIST_HEAD(&rdev->same_set);
34197 init_waitqueue_head(&rdev->blocked_wait);
34198 @@ -6736,7 +6736,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
34199
34200 spin_unlock(&pers_lock);
34201 seq_printf(seq, "\n");
34202 - seq->poll_event = atomic_read(&md_event_count);
34203 + seq->poll_event = atomic_read_unchecked(&md_event_count);
34204 return 0;
34205 }
34206 if (v == (void*)2) {
34207 @@ -6828,7 +6828,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
34208 chunk_kb ? "KB" : "B");
34209 if (bitmap->file) {
34210 seq_printf(seq, ", file: ");
34211 - seq_path(seq, &bitmap->file->f_path, " \t\n");
34212 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
34213 }
34214
34215 seq_printf(seq, "\n");
34216 @@ -6859,7 +6859,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
34217 return error;
34218
34219 seq = file->private_data;
34220 - seq->poll_event = atomic_read(&md_event_count);
34221 + seq->poll_event = atomic_read_unchecked(&md_event_count);
34222 return error;
34223 }
34224
34225 @@ -6873,7 +6873,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
34226 /* always allow read */
34227 mask = POLLIN | POLLRDNORM;
34228
34229 - if (seq->poll_event != atomic_read(&md_event_count))
34230 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
34231 mask |= POLLERR | POLLPRI;
34232 return mask;
34233 }
34234 @@ -6917,7 +6917,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
34235 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
34236 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
34237 (int)part_stat_read(&disk->part0, sectors[1]) -
34238 - atomic_read(&disk->sync_io);
34239 + atomic_read_unchecked(&disk->sync_io);
34240 /* sync IO will cause sync_io to increase before the disk_stats
34241 * as sync_io is counted when a request starts, and
34242 * disk_stats is counted when it completes.
34243 diff --git a/drivers/md/md.h b/drivers/md/md.h
34244 index 44c63df..b795d1a 100644
34245 --- a/drivers/md/md.h
34246 +++ b/drivers/md/md.h
34247 @@ -93,13 +93,13 @@ struct md_rdev {
34248 * only maintained for arrays that
34249 * support hot removal
34250 */
34251 - atomic_t read_errors; /* number of consecutive read errors that
34252 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
34253 * we have tried to ignore.
34254 */
34255 struct timespec last_read_error; /* monotonic time since our
34256 * last read error
34257 */
34258 - atomic_t corrected_errors; /* number of corrected read errors,
34259 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
34260 * for reporting to userspace and storing
34261 * in superblock.
34262 */
34263 @@ -421,7 +421,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
34264
34265 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
34266 {
34267 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34268 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34269 }
34270
34271 struct md_personality
34272 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
34273 index 50ed53b..4f29d7d 100644
34274 --- a/drivers/md/persistent-data/dm-space-map-checker.c
34275 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
34276 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
34277 /*----------------------------------------------------------------*/
34278
34279 struct sm_checker {
34280 - struct dm_space_map sm;
34281 + dm_space_map_no_const sm;
34282
34283 struct count_array old_counts;
34284 struct count_array counts;
34285 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
34286 index fc469ba..2d91555 100644
34287 --- a/drivers/md/persistent-data/dm-space-map-disk.c
34288 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
34289 @@ -23,7 +23,7 @@
34290 * Space map interface.
34291 */
34292 struct sm_disk {
34293 - struct dm_space_map sm;
34294 + dm_space_map_no_const sm;
34295
34296 struct ll_disk ll;
34297 struct ll_disk old_ll;
34298 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
34299 index e89ae5e..062e4c2 100644
34300 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
34301 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
34302 @@ -43,7 +43,7 @@ struct block_op {
34303 };
34304
34305 struct sm_metadata {
34306 - struct dm_space_map sm;
34307 + dm_space_map_no_const sm;
34308
34309 struct ll_disk ll;
34310 struct ll_disk old_ll;
34311 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
34312 index 1cbfc6b..56e1dbb 100644
34313 --- a/drivers/md/persistent-data/dm-space-map.h
34314 +++ b/drivers/md/persistent-data/dm-space-map.h
34315 @@ -60,6 +60,7 @@ struct dm_space_map {
34316 int (*root_size)(struct dm_space_map *sm, size_t *result);
34317 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
34318 };
34319 +typedef struct dm_space_map __no_const dm_space_map_no_const;
34320
34321 /*----------------------------------------------------------------*/
34322
34323 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
34324 index edc735a..e9b97f1 100644
34325 --- a/drivers/md/raid1.c
34326 +++ b/drivers/md/raid1.c
34327 @@ -1645,7 +1645,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
34328 if (r1_sync_page_io(rdev, sect, s,
34329 bio->bi_io_vec[idx].bv_page,
34330 READ) != 0)
34331 - atomic_add(s, &rdev->corrected_errors);
34332 + atomic_add_unchecked(s, &rdev->corrected_errors);
34333 }
34334 sectors -= s;
34335 sect += s;
34336 @@ -1859,7 +1859,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
34337 test_bit(In_sync, &rdev->flags)) {
34338 if (r1_sync_page_io(rdev, sect, s,
34339 conf->tmppage, READ)) {
34340 - atomic_add(s, &rdev->corrected_errors);
34341 + atomic_add_unchecked(s, &rdev->corrected_errors);
34342 printk(KERN_INFO
34343 "md/raid1:%s: read error corrected "
34344 "(%d sectors at %llu on %s)\n",
34345 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
34346 index 1898389..a3aa617 100644
34347 --- a/drivers/md/raid10.c
34348 +++ b/drivers/md/raid10.c
34349 @@ -1636,7 +1636,7 @@ static void end_sync_read(struct bio *bio, int error)
34350 /* The write handler will notice the lack of
34351 * R10BIO_Uptodate and record any errors etc
34352 */
34353 - atomic_add(r10_bio->sectors,
34354 + atomic_add_unchecked(r10_bio->sectors,
34355 &conf->mirrors[d].rdev->corrected_errors);
34356
34357 /* for reconstruct, we always reschedule after a read.
34358 @@ -1987,7 +1987,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34359 {
34360 struct timespec cur_time_mon;
34361 unsigned long hours_since_last;
34362 - unsigned int read_errors = atomic_read(&rdev->read_errors);
34363 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
34364
34365 ktime_get_ts(&cur_time_mon);
34366
34367 @@ -2009,9 +2009,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
34368 * overflowing the shift of read_errors by hours_since_last.
34369 */
34370 if (hours_since_last >= 8 * sizeof(read_errors))
34371 - atomic_set(&rdev->read_errors, 0);
34372 + atomic_set_unchecked(&rdev->read_errors, 0);
34373 else
34374 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
34375 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
34376 }
34377
34378 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
34379 @@ -2065,8 +2065,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34380 return;
34381
34382 check_decay_read_errors(mddev, rdev);
34383 - atomic_inc(&rdev->read_errors);
34384 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
34385 + atomic_inc_unchecked(&rdev->read_errors);
34386 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
34387 char b[BDEVNAME_SIZE];
34388 bdevname(rdev->bdev, b);
34389
34390 @@ -2074,7 +2074,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34391 "md/raid10:%s: %s: Raid device exceeded "
34392 "read_error threshold [cur %d:max %d]\n",
34393 mdname(mddev), b,
34394 - atomic_read(&rdev->read_errors), max_read_errors);
34395 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
34396 printk(KERN_NOTICE
34397 "md/raid10:%s: %s: Failing raid device\n",
34398 mdname(mddev), b);
34399 @@ -2223,7 +2223,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
34400 (unsigned long long)(
34401 sect + rdev->data_offset),
34402 bdevname(rdev->bdev, b));
34403 - atomic_add(s, &rdev->corrected_errors);
34404 + atomic_add_unchecked(s, &rdev->corrected_errors);
34405 }
34406
34407 rdev_dec_pending(rdev, mddev);
34408 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
34409 index d1162e5..c7cd902 100644
34410 --- a/drivers/md/raid5.c
34411 +++ b/drivers/md/raid5.c
34412 @@ -1687,18 +1687,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
34413 (unsigned long long)(sh->sector
34414 + rdev->data_offset),
34415 bdevname(rdev->bdev, b));
34416 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
34417 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
34418 clear_bit(R5_ReadError, &sh->dev[i].flags);
34419 clear_bit(R5_ReWrite, &sh->dev[i].flags);
34420 }
34421 - if (atomic_read(&rdev->read_errors))
34422 - atomic_set(&rdev->read_errors, 0);
34423 + if (atomic_read_unchecked(&rdev->read_errors))
34424 + atomic_set_unchecked(&rdev->read_errors, 0);
34425 } else {
34426 const char *bdn = bdevname(rdev->bdev, b);
34427 int retry = 0;
34428
34429 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
34430 - atomic_inc(&rdev->read_errors);
34431 + atomic_inc_unchecked(&rdev->read_errors);
34432 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
34433 printk_ratelimited(
34434 KERN_WARNING
34435 @@ -1727,7 +1727,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
34436 (unsigned long long)(sh->sector
34437 + rdev->data_offset),
34438 bdn);
34439 - else if (atomic_read(&rdev->read_errors)
34440 + else if (atomic_read_unchecked(&rdev->read_errors)
34441 > conf->max_nr_stripes)
34442 printk(KERN_WARNING
34443 "md/raid:%s: Too many read errors, failing device %s.\n",
34444 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
34445 index ce4f858..7bcfb46 100644
34446 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
34447 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
34448 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
34449 .subvendor = _subvend, .subdevice = _subdev, \
34450 .driver_data = (unsigned long)&_driverdata }
34451
34452 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
34453 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
34454 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
34455 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
34456 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
34457 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
34458 index a7d876f..8c21b61 100644
34459 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
34460 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
34461 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
34462 union {
34463 dmx_ts_cb ts;
34464 dmx_section_cb sec;
34465 - } cb;
34466 + } __no_const cb;
34467
34468 struct dvb_demux *demux;
34469 void *priv;
34470 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
34471 index 00a6732..70a682e 100644
34472 --- a/drivers/media/dvb/dvb-core/dvbdev.c
34473 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
34474 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
34475 const struct dvb_device *template, void *priv, int type)
34476 {
34477 struct dvb_device *dvbdev;
34478 - struct file_operations *dvbdevfops;
34479 + file_operations_no_const *dvbdevfops;
34480 struct device *clsdev;
34481 int minor;
34482 int id;
34483 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
34484 index 3940bb0..fb3952a 100644
34485 --- a/drivers/media/dvb/dvb-usb/cxusb.c
34486 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
34487 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
34488
34489 struct dib0700_adapter_state {
34490 int (*set_param_save) (struct dvb_frontend *);
34491 -};
34492 +} __no_const;
34493
34494 static int dib7070_set_param_override(struct dvb_frontend *fe)
34495 {
34496 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
34497 index 451c5a7..649f711 100644
34498 --- a/drivers/media/dvb/dvb-usb/dw2102.c
34499 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
34500 @@ -95,7 +95,7 @@ struct su3000_state {
34501
34502 struct s6x0_state {
34503 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
34504 -};
34505 +} __no_const;
34506
34507 /* debug */
34508 static int dvb_usb_dw2102_debug;
34509 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34510 index 404f63a..4796533 100644
34511 --- a/drivers/media/dvb/frontends/dib3000.h
34512 +++ b/drivers/media/dvb/frontends/dib3000.h
34513 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34514 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34515 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34516 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34517 -};
34518 +} __no_const;
34519
34520 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34521 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34522 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34523 index 8418c02..8555013 100644
34524 --- a/drivers/media/dvb/ngene/ngene-cards.c
34525 +++ b/drivers/media/dvb/ngene/ngene-cards.c
34526 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
34527
34528 /****************************************************************************/
34529
34530 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34531 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34532 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34533 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34534 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34535 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34536 index 16a089f..ab1667d 100644
34537 --- a/drivers/media/radio/radio-cadet.c
34538 +++ b/drivers/media/radio/radio-cadet.c
34539 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34540 unsigned char readbuf[RDS_BUFFER];
34541 int i = 0;
34542
34543 + if (count > RDS_BUFFER)
34544 + return -EFAULT;
34545 mutex_lock(&dev->lock);
34546 if (dev->rdsstat == 0) {
34547 dev->rdsstat = 1;
34548 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34549 index 9cde353..8c6a1c3 100644
34550 --- a/drivers/media/video/au0828/au0828.h
34551 +++ b/drivers/media/video/au0828/au0828.h
34552 @@ -191,7 +191,7 @@ struct au0828_dev {
34553
34554 /* I2C */
34555 struct i2c_adapter i2c_adap;
34556 - struct i2c_algorithm i2c_algo;
34557 + i2c_algorithm_no_const i2c_algo;
34558 struct i2c_client i2c_client;
34559 u32 i2c_rc;
34560
34561 diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
34562 index ee91e295..04ad048 100644
34563 --- a/drivers/media/video/cpia2/cpia2_core.c
34564 +++ b/drivers/media/video/cpia2/cpia2_core.c
34565 @@ -86,6 +86,7 @@ static inline unsigned long kvirt_to_pa(unsigned long adr)
34566 return ret;
34567 }
34568
34569 +static void *rvmalloc(unsigned long size) __size_overflow(1);
34570 static void *rvmalloc(unsigned long size)
34571 {
34572 void *mem;
34573 diff --git a/drivers/media/video/cx18/cx18-alsa-pcm.c b/drivers/media/video/cx18/cx18-alsa-pcm.c
34574 index 82d195b..181103c 100644
34575 --- a/drivers/media/video/cx18/cx18-alsa-pcm.c
34576 +++ b/drivers/media/video/cx18/cx18-alsa-pcm.c
34577 @@ -229,6 +229,8 @@ static int snd_cx18_pcm_ioctl(struct snd_pcm_substream *substream,
34578
34579
34580 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34581 + size_t size) __size_overflow(2);
34582 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34583 size_t size)
34584 {
34585 struct snd_pcm_runtime *runtime = subs->runtime;
34586 diff --git a/drivers/media/video/cx231xx/cx231xx-audio.c b/drivers/media/video/cx231xx/cx231xx-audio.c
34587 index a2c2b7d..8f1bec7 100644
34588 --- a/drivers/media/video/cx231xx/cx231xx-audio.c
34589 +++ b/drivers/media/video/cx231xx/cx231xx-audio.c
34590 @@ -389,6 +389,8 @@ static int cx231xx_init_audio_bulk(struct cx231xx *dev)
34591 }
34592
34593 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34594 + size_t size) __size_overflow(2);
34595 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34596 size_t size)
34597 {
34598 struct snd_pcm_runtime *runtime = subs->runtime;
34599 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34600 index 04bf662..e0ac026 100644
34601 --- a/drivers/media/video/cx88/cx88-alsa.c
34602 +++ b/drivers/media/video/cx88/cx88-alsa.c
34603 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34604 * Only boards with eeprom and byte 1 at eeprom=1 have it
34605 */
34606
34607 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34608 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34609 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34610 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34611 {0, }
34612 diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c
34613 index e2a7b77..753d0ee 100644
34614 --- a/drivers/media/video/em28xx/em28xx-audio.c
34615 +++ b/drivers/media/video/em28xx/em28xx-audio.c
34616 @@ -225,6 +225,8 @@ static int em28xx_init_audio_isoc(struct em28xx *dev)
34617 }
34618
34619 static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34620 + size_t size) __size_overflow(2);
34621 +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
34622 size_t size)
34623 {
34624 struct snd_pcm_runtime *runtime = subs->runtime;
34625 diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
34626 index b09a3c8..6dcba0a 100644
34627 --- a/drivers/media/video/meye.c
34628 +++ b/drivers/media/video/meye.c
34629 @@ -72,6 +72,7 @@ static struct meye meye;
34630 /****************************************************************************/
34631 /* Memory allocation routines (stolen from bttv-driver.c) */
34632 /****************************************************************************/
34633 +static void *rvmalloc(unsigned long size) __size_overflow(1);
34634 static void *rvmalloc(unsigned long size)
34635 {
34636 void *mem;
34637 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34638 index 1fb7d5b..3901e77 100644
34639 --- a/drivers/media/video/omap/omap_vout.c
34640 +++ b/drivers/media/video/omap/omap_vout.c
34641 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34642 OMAP_VIDEO2,
34643 };
34644
34645 -static struct videobuf_queue_ops video_vbq_ops;
34646 /* Variables configurable through module params*/
34647 static u32 video1_numbuffers = 3;
34648 static u32 video2_numbuffers = 3;
34649 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34650 {
34651 struct videobuf_queue *q;
34652 struct omap_vout_device *vout = NULL;
34653 + static struct videobuf_queue_ops video_vbq_ops = {
34654 + .buf_setup = omap_vout_buffer_setup,
34655 + .buf_prepare = omap_vout_buffer_prepare,
34656 + .buf_release = omap_vout_buffer_release,
34657 + .buf_queue = omap_vout_buffer_queue,
34658 + };
34659
34660 vout = video_drvdata(file);
34661 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34662 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34663 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34664
34665 q = &vout->vbq;
34666 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34667 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34668 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34669 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34670 spin_lock_init(&vout->vbq_lock);
34671
34672 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34673 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34674 index 305e6aa..0143317 100644
34675 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34676 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34677 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34678
34679 /* I2C stuff */
34680 struct i2c_adapter i2c_adap;
34681 - struct i2c_algorithm i2c_algo;
34682 + i2c_algorithm_no_const i2c_algo;
34683 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34684 int i2c_cx25840_hack_state;
34685 int i2c_linked;
34686 diff --git a/drivers/media/video/saa7164/saa7164-encoder.c b/drivers/media/video/saa7164/saa7164-encoder.c
34687 index 2fd38a0..ddec3c4 100644
34688 --- a/drivers/media/video/saa7164/saa7164-encoder.c
34689 +++ b/drivers/media/video/saa7164/saa7164-encoder.c
34690 @@ -1136,6 +1136,8 @@ struct saa7164_user_buffer *saa7164_enc_next_buf(struct saa7164_port *port)
34691 }
34692
34693 static ssize_t fops_read(struct file *file, char __user *buffer,
34694 + size_t count, loff_t *pos) __size_overflow(3);
34695 +static ssize_t fops_read(struct file *file, char __user *buffer,
34696 size_t count, loff_t *pos)
34697 {
34698 struct saa7164_encoder_fh *fh = file->private_data;
34699 diff --git a/drivers/media/video/saa7164/saa7164-vbi.c b/drivers/media/video/saa7164/saa7164-vbi.c
34700 index e2e0341..b80056c 100644
34701 --- a/drivers/media/video/saa7164/saa7164-vbi.c
34702 +++ b/drivers/media/video/saa7164/saa7164-vbi.c
34703 @@ -1081,6 +1081,8 @@ struct saa7164_user_buffer *saa7164_vbi_next_buf(struct saa7164_port *port)
34704 }
34705
34706 static ssize_t fops_read(struct file *file, char __user *buffer,
34707 + size_t count, loff_t *pos) __size_overflow(3);
34708 +static ssize_t fops_read(struct file *file, char __user *buffer,
34709 size_t count, loff_t *pos)
34710 {
34711 struct saa7164_vbi_fh *fh = file->private_data;
34712 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34713 index 4ed1c7c2..8f15e13 100644
34714 --- a/drivers/media/video/timblogiw.c
34715 +++ b/drivers/media/video/timblogiw.c
34716 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34717
34718 /* Platform device functions */
34719
34720 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34721 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34722 .vidioc_querycap = timblogiw_querycap,
34723 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34724 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34725 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34726 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34727 };
34728
34729 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34730 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34731 .owner = THIS_MODULE,
34732 .open = timblogiw_open,
34733 .release = timblogiw_close,
34734 diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c
34735 index c969111..a7910f4 100644
34736 --- a/drivers/media/video/videobuf-dma-contig.c
34737 +++ b/drivers/media/video/videobuf-dma-contig.c
34738 @@ -184,6 +184,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
34739 return ret;
34740 }
34741
34742 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
34743 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
34744 {
34745 struct videobuf_dma_contig_memory *mem;
34746 diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
34747 index f300dea..5fc9c4a 100644
34748 --- a/drivers/media/video/videobuf-dma-sg.c
34749 +++ b/drivers/media/video/videobuf-dma-sg.c
34750 @@ -419,6 +419,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
34751 struct videobuf_dma_sg_memory
34752 */
34753
34754 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
34755 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
34756 {
34757 struct videobuf_dma_sg_memory *mem;
34758 diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
34759 index df14258..12cc7a3 100644
34760 --- a/drivers/media/video/videobuf-vmalloc.c
34761 +++ b/drivers/media/video/videobuf-vmalloc.c
34762 @@ -135,6 +135,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
34763 struct videobuf_dma_sg_memory
34764 */
34765
34766 +static struct videobuf_buffer *__videobuf_alloc_vb(size_t size) __size_overflow(1);
34767 static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
34768 {
34769 struct videobuf_vmalloc_memory *mem;
34770 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34771 index a7dc467..a55c423 100644
34772 --- a/drivers/message/fusion/mptbase.c
34773 +++ b/drivers/message/fusion/mptbase.c
34774 @@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34775 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34776 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34777
34778 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34779 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34780 +#else
34781 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34782 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34783 +#endif
34784 +
34785 /*
34786 * Rounding UP to nearest 4-kB boundary here...
34787 */
34788 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34789 index 551262e..7551198 100644
34790 --- a/drivers/message/fusion/mptsas.c
34791 +++ b/drivers/message/fusion/mptsas.c
34792 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34793 return 0;
34794 }
34795
34796 +static inline void
34797 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34798 +{
34799 + if (phy_info->port_details) {
34800 + phy_info->port_details->rphy = rphy;
34801 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34802 + ioc->name, rphy));
34803 + }
34804 +
34805 + if (rphy) {
34806 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34807 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34808 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34809 + ioc->name, rphy, rphy->dev.release));
34810 + }
34811 +}
34812 +
34813 /* no mutex */
34814 static void
34815 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34816 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34817 return NULL;
34818 }
34819
34820 -static inline void
34821 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34822 -{
34823 - if (phy_info->port_details) {
34824 - phy_info->port_details->rphy = rphy;
34825 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34826 - ioc->name, rphy));
34827 - }
34828 -
34829 - if (rphy) {
34830 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34831 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34832 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34833 - ioc->name, rphy, rphy->dev.release));
34834 - }
34835 -}
34836 -
34837 static inline struct sas_port *
34838 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34839 {
34840 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34841 index 0c3ced7..1fe34ec 100644
34842 --- a/drivers/message/fusion/mptscsih.c
34843 +++ b/drivers/message/fusion/mptscsih.c
34844 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34845
34846 h = shost_priv(SChost);
34847
34848 - if (h) {
34849 - if (h->info_kbuf == NULL)
34850 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34851 - return h->info_kbuf;
34852 - h->info_kbuf[0] = '\0';
34853 + if (!h)
34854 + return NULL;
34855
34856 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34857 - h->info_kbuf[size-1] = '\0';
34858 - }
34859 + if (h->info_kbuf == NULL)
34860 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34861 + return h->info_kbuf;
34862 + h->info_kbuf[0] = '\0';
34863 +
34864 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34865 + h->info_kbuf[size-1] = '\0';
34866
34867 return h->info_kbuf;
34868 }
34869 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34870 index 6d115c7..58ff7fd 100644
34871 --- a/drivers/message/i2o/i2o_proc.c
34872 +++ b/drivers/message/i2o/i2o_proc.c
34873 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34874 "Array Controller Device"
34875 };
34876
34877 -static char *chtostr(u8 * chars, int n)
34878 -{
34879 - char tmp[256];
34880 - tmp[0] = 0;
34881 - return strncat(tmp, (char *)chars, n);
34882 -}
34883 -
34884 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34885 char *group)
34886 {
34887 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34888
34889 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34890 seq_printf(seq, "%-#8x", ddm_table.module_id);
34891 - seq_printf(seq, "%-29s",
34892 - chtostr(ddm_table.module_name_version, 28));
34893 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34894 seq_printf(seq, "%9d ", ddm_table.data_size);
34895 seq_printf(seq, "%8d", ddm_table.code_size);
34896
34897 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34898
34899 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34900 seq_printf(seq, "%-#8x", dst->module_id);
34901 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34902 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34903 + seq_printf(seq, "%-.28s", dst->module_name_version);
34904 + seq_printf(seq, "%-.8s", dst->date);
34905 seq_printf(seq, "%8d ", dst->module_size);
34906 seq_printf(seq, "%8d ", dst->mpb_size);
34907 seq_printf(seq, "0x%04x", dst->module_flags);
34908 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34909 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34910 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34911 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34912 - seq_printf(seq, "Vendor info : %s\n",
34913 - chtostr((u8 *) (work32 + 2), 16));
34914 - seq_printf(seq, "Product info : %s\n",
34915 - chtostr((u8 *) (work32 + 6), 16));
34916 - seq_printf(seq, "Description : %s\n",
34917 - chtostr((u8 *) (work32 + 10), 16));
34918 - seq_printf(seq, "Product rev. : %s\n",
34919 - chtostr((u8 *) (work32 + 14), 8));
34920 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34921 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34922 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34923 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34924
34925 seq_printf(seq, "Serial number : ");
34926 print_serial_number(seq, (u8 *) (work32 + 16),
34927 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34928 }
34929
34930 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34931 - seq_printf(seq, "Module name : %s\n",
34932 - chtostr(result.module_name, 24));
34933 - seq_printf(seq, "Module revision : %s\n",
34934 - chtostr(result.module_rev, 8));
34935 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34936 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34937
34938 seq_printf(seq, "Serial number : ");
34939 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34940 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34941 return 0;
34942 }
34943
34944 - seq_printf(seq, "Device name : %s\n",
34945 - chtostr(result.device_name, 64));
34946 - seq_printf(seq, "Service name : %s\n",
34947 - chtostr(result.service_name, 64));
34948 - seq_printf(seq, "Physical name : %s\n",
34949 - chtostr(result.physical_location, 64));
34950 - seq_printf(seq, "Instance number : %s\n",
34951 - chtostr(result.instance_number, 4));
34952 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34953 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34954 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34955 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34956
34957 return 0;
34958 }
34959 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34960 index a8c08f3..155fe3d 100644
34961 --- a/drivers/message/i2o/iop.c
34962 +++ b/drivers/message/i2o/iop.c
34963 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34964
34965 spin_lock_irqsave(&c->context_list_lock, flags);
34966
34967 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34968 - atomic_inc(&c->context_list_counter);
34969 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34970 + atomic_inc_unchecked(&c->context_list_counter);
34971
34972 - entry->context = atomic_read(&c->context_list_counter);
34973 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34974
34975 list_add(&entry->list, &c->context_list);
34976
34977 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34978
34979 #if BITS_PER_LONG == 64
34980 spin_lock_init(&c->context_list_lock);
34981 - atomic_set(&c->context_list_counter, 0);
34982 + atomic_set_unchecked(&c->context_list_counter, 0);
34983 INIT_LIST_HEAD(&c->context_list);
34984 #endif
34985
34986 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34987 index 7ce65f4..e66e9bc 100644
34988 --- a/drivers/mfd/abx500-core.c
34989 +++ b/drivers/mfd/abx500-core.c
34990 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34991
34992 struct abx500_device_entry {
34993 struct list_head list;
34994 - struct abx500_ops ops;
34995 + abx500_ops_no_const ops;
34996 struct device *dev;
34997 };
34998
34999 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
35000 index a9223ed..4127b13 100644
35001 --- a/drivers/mfd/janz-cmodio.c
35002 +++ b/drivers/mfd/janz-cmodio.c
35003 @@ -13,6 +13,7 @@
35004
35005 #include <linux/kernel.h>
35006 #include <linux/module.h>
35007 +#include <linux/slab.h>
35008 #include <linux/init.h>
35009 #include <linux/pci.h>
35010 #include <linux/interrupt.h>
35011 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
35012 index a981e2a..5ca0c8b 100644
35013 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
35014 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
35015 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
35016 * the lid is closed. This leads to interrupts as soon as a little move
35017 * is done.
35018 */
35019 - atomic_inc(&lis3->count);
35020 + atomic_inc_unchecked(&lis3->count);
35021
35022 wake_up_interruptible(&lis3->misc_wait);
35023 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
35024 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
35025 if (lis3->pm_dev)
35026 pm_runtime_get_sync(lis3->pm_dev);
35027
35028 - atomic_set(&lis3->count, 0);
35029 + atomic_set_unchecked(&lis3->count, 0);
35030 return 0;
35031 }
35032
35033 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
35034 add_wait_queue(&lis3->misc_wait, &wait);
35035 while (true) {
35036 set_current_state(TASK_INTERRUPTIBLE);
35037 - data = atomic_xchg(&lis3->count, 0);
35038 + data = atomic_xchg_unchecked(&lis3->count, 0);
35039 if (data)
35040 break;
35041
35042 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
35043 struct lis3lv02d, miscdev);
35044
35045 poll_wait(file, &lis3->misc_wait, wait);
35046 - if (atomic_read(&lis3->count))
35047 + if (atomic_read_unchecked(&lis3->count))
35048 return POLLIN | POLLRDNORM;
35049 return 0;
35050 }
35051 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
35052 index 2b1482a..5d33616 100644
35053 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
35054 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
35055 @@ -266,7 +266,7 @@ struct lis3lv02d {
35056 struct input_polled_dev *idev; /* input device */
35057 struct platform_device *pdev; /* platform device */
35058 struct regulator_bulk_data regulators[2];
35059 - atomic_t count; /* interrupt count after last read */
35060 + atomic_unchecked_t count; /* interrupt count after last read */
35061 union axis_conversion ac; /* hw -> logical axis */
35062 int mapped_btns[3];
35063
35064 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
35065 index 2f30bad..c4c13d0 100644
35066 --- a/drivers/misc/sgi-gru/gruhandles.c
35067 +++ b/drivers/misc/sgi-gru/gruhandles.c
35068 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
35069 unsigned long nsec;
35070
35071 nsec = CLKS2NSEC(clks);
35072 - atomic_long_inc(&mcs_op_statistics[op].count);
35073 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
35074 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
35075 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
35076 if (mcs_op_statistics[op].max < nsec)
35077 mcs_op_statistics[op].max = nsec;
35078 }
35079 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
35080 index 950dbe9..eeef0f8 100644
35081 --- a/drivers/misc/sgi-gru/gruprocfs.c
35082 +++ b/drivers/misc/sgi-gru/gruprocfs.c
35083 @@ -32,9 +32,9 @@
35084
35085 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
35086
35087 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
35088 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
35089 {
35090 - unsigned long val = atomic_long_read(v);
35091 + unsigned long val = atomic_long_read_unchecked(v);
35092
35093 seq_printf(s, "%16lu %s\n", val, id);
35094 }
35095 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
35096
35097 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
35098 for (op = 0; op < mcsop_last; op++) {
35099 - count = atomic_long_read(&mcs_op_statistics[op].count);
35100 - total = atomic_long_read(&mcs_op_statistics[op].total);
35101 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
35102 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
35103 max = mcs_op_statistics[op].max;
35104 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
35105 count ? total / count : 0, max);
35106 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
35107 index 5c3ce24..4915ccb 100644
35108 --- a/drivers/misc/sgi-gru/grutables.h
35109 +++ b/drivers/misc/sgi-gru/grutables.h
35110 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
35111 * GRU statistics.
35112 */
35113 struct gru_stats_s {
35114 - atomic_long_t vdata_alloc;
35115 - atomic_long_t vdata_free;
35116 - atomic_long_t gts_alloc;
35117 - atomic_long_t gts_free;
35118 - atomic_long_t gms_alloc;
35119 - atomic_long_t gms_free;
35120 - atomic_long_t gts_double_allocate;
35121 - atomic_long_t assign_context;
35122 - atomic_long_t assign_context_failed;
35123 - atomic_long_t free_context;
35124 - atomic_long_t load_user_context;
35125 - atomic_long_t load_kernel_context;
35126 - atomic_long_t lock_kernel_context;
35127 - atomic_long_t unlock_kernel_context;
35128 - atomic_long_t steal_user_context;
35129 - atomic_long_t steal_kernel_context;
35130 - atomic_long_t steal_context_failed;
35131 - atomic_long_t nopfn;
35132 - atomic_long_t asid_new;
35133 - atomic_long_t asid_next;
35134 - atomic_long_t asid_wrap;
35135 - atomic_long_t asid_reuse;
35136 - atomic_long_t intr;
35137 - atomic_long_t intr_cbr;
35138 - atomic_long_t intr_tfh;
35139 - atomic_long_t intr_spurious;
35140 - atomic_long_t intr_mm_lock_failed;
35141 - atomic_long_t call_os;
35142 - atomic_long_t call_os_wait_queue;
35143 - atomic_long_t user_flush_tlb;
35144 - atomic_long_t user_unload_context;
35145 - atomic_long_t user_exception;
35146 - atomic_long_t set_context_option;
35147 - atomic_long_t check_context_retarget_intr;
35148 - atomic_long_t check_context_unload;
35149 - atomic_long_t tlb_dropin;
35150 - atomic_long_t tlb_preload_page;
35151 - atomic_long_t tlb_dropin_fail_no_asid;
35152 - atomic_long_t tlb_dropin_fail_upm;
35153 - atomic_long_t tlb_dropin_fail_invalid;
35154 - atomic_long_t tlb_dropin_fail_range_active;
35155 - atomic_long_t tlb_dropin_fail_idle;
35156 - atomic_long_t tlb_dropin_fail_fmm;
35157 - atomic_long_t tlb_dropin_fail_no_exception;
35158 - atomic_long_t tfh_stale_on_fault;
35159 - atomic_long_t mmu_invalidate_range;
35160 - atomic_long_t mmu_invalidate_page;
35161 - atomic_long_t flush_tlb;
35162 - atomic_long_t flush_tlb_gru;
35163 - atomic_long_t flush_tlb_gru_tgh;
35164 - atomic_long_t flush_tlb_gru_zero_asid;
35165 + atomic_long_unchecked_t vdata_alloc;
35166 + atomic_long_unchecked_t vdata_free;
35167 + atomic_long_unchecked_t gts_alloc;
35168 + atomic_long_unchecked_t gts_free;
35169 + atomic_long_unchecked_t gms_alloc;
35170 + atomic_long_unchecked_t gms_free;
35171 + atomic_long_unchecked_t gts_double_allocate;
35172 + atomic_long_unchecked_t assign_context;
35173 + atomic_long_unchecked_t assign_context_failed;
35174 + atomic_long_unchecked_t free_context;
35175 + atomic_long_unchecked_t load_user_context;
35176 + atomic_long_unchecked_t load_kernel_context;
35177 + atomic_long_unchecked_t lock_kernel_context;
35178 + atomic_long_unchecked_t unlock_kernel_context;
35179 + atomic_long_unchecked_t steal_user_context;
35180 + atomic_long_unchecked_t steal_kernel_context;
35181 + atomic_long_unchecked_t steal_context_failed;
35182 + atomic_long_unchecked_t nopfn;
35183 + atomic_long_unchecked_t asid_new;
35184 + atomic_long_unchecked_t asid_next;
35185 + atomic_long_unchecked_t asid_wrap;
35186 + atomic_long_unchecked_t asid_reuse;
35187 + atomic_long_unchecked_t intr;
35188 + atomic_long_unchecked_t intr_cbr;
35189 + atomic_long_unchecked_t intr_tfh;
35190 + atomic_long_unchecked_t intr_spurious;
35191 + atomic_long_unchecked_t intr_mm_lock_failed;
35192 + atomic_long_unchecked_t call_os;
35193 + atomic_long_unchecked_t call_os_wait_queue;
35194 + atomic_long_unchecked_t user_flush_tlb;
35195 + atomic_long_unchecked_t user_unload_context;
35196 + atomic_long_unchecked_t user_exception;
35197 + atomic_long_unchecked_t set_context_option;
35198 + atomic_long_unchecked_t check_context_retarget_intr;
35199 + atomic_long_unchecked_t check_context_unload;
35200 + atomic_long_unchecked_t tlb_dropin;
35201 + atomic_long_unchecked_t tlb_preload_page;
35202 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
35203 + atomic_long_unchecked_t tlb_dropin_fail_upm;
35204 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
35205 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
35206 + atomic_long_unchecked_t tlb_dropin_fail_idle;
35207 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
35208 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
35209 + atomic_long_unchecked_t tfh_stale_on_fault;
35210 + atomic_long_unchecked_t mmu_invalidate_range;
35211 + atomic_long_unchecked_t mmu_invalidate_page;
35212 + atomic_long_unchecked_t flush_tlb;
35213 + atomic_long_unchecked_t flush_tlb_gru;
35214 + atomic_long_unchecked_t flush_tlb_gru_tgh;
35215 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
35216
35217 - atomic_long_t copy_gpa;
35218 - atomic_long_t read_gpa;
35219 + atomic_long_unchecked_t copy_gpa;
35220 + atomic_long_unchecked_t read_gpa;
35221
35222 - atomic_long_t mesq_receive;
35223 - atomic_long_t mesq_receive_none;
35224 - atomic_long_t mesq_send;
35225 - atomic_long_t mesq_send_failed;
35226 - atomic_long_t mesq_noop;
35227 - atomic_long_t mesq_send_unexpected_error;
35228 - atomic_long_t mesq_send_lb_overflow;
35229 - atomic_long_t mesq_send_qlimit_reached;
35230 - atomic_long_t mesq_send_amo_nacked;
35231 - atomic_long_t mesq_send_put_nacked;
35232 - atomic_long_t mesq_page_overflow;
35233 - atomic_long_t mesq_qf_locked;
35234 - atomic_long_t mesq_qf_noop_not_full;
35235 - atomic_long_t mesq_qf_switch_head_failed;
35236 - atomic_long_t mesq_qf_unexpected_error;
35237 - atomic_long_t mesq_noop_unexpected_error;
35238 - atomic_long_t mesq_noop_lb_overflow;
35239 - atomic_long_t mesq_noop_qlimit_reached;
35240 - atomic_long_t mesq_noop_amo_nacked;
35241 - atomic_long_t mesq_noop_put_nacked;
35242 - atomic_long_t mesq_noop_page_overflow;
35243 + atomic_long_unchecked_t mesq_receive;
35244 + atomic_long_unchecked_t mesq_receive_none;
35245 + atomic_long_unchecked_t mesq_send;
35246 + atomic_long_unchecked_t mesq_send_failed;
35247 + atomic_long_unchecked_t mesq_noop;
35248 + atomic_long_unchecked_t mesq_send_unexpected_error;
35249 + atomic_long_unchecked_t mesq_send_lb_overflow;
35250 + atomic_long_unchecked_t mesq_send_qlimit_reached;
35251 + atomic_long_unchecked_t mesq_send_amo_nacked;
35252 + atomic_long_unchecked_t mesq_send_put_nacked;
35253 + atomic_long_unchecked_t mesq_page_overflow;
35254 + atomic_long_unchecked_t mesq_qf_locked;
35255 + atomic_long_unchecked_t mesq_qf_noop_not_full;
35256 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
35257 + atomic_long_unchecked_t mesq_qf_unexpected_error;
35258 + atomic_long_unchecked_t mesq_noop_unexpected_error;
35259 + atomic_long_unchecked_t mesq_noop_lb_overflow;
35260 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
35261 + atomic_long_unchecked_t mesq_noop_amo_nacked;
35262 + atomic_long_unchecked_t mesq_noop_put_nacked;
35263 + atomic_long_unchecked_t mesq_noop_page_overflow;
35264
35265 };
35266
35267 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
35268 tghop_invalidate, mcsop_last};
35269
35270 struct mcs_op_statistic {
35271 - atomic_long_t count;
35272 - atomic_long_t total;
35273 + atomic_long_unchecked_t count;
35274 + atomic_long_unchecked_t total;
35275 unsigned long max;
35276 };
35277
35278 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
35279
35280 #define STAT(id) do { \
35281 if (gru_options & OPT_STATS) \
35282 - atomic_long_inc(&gru_stats.id); \
35283 + atomic_long_inc_unchecked(&gru_stats.id); \
35284 } while (0)
35285
35286 #ifdef CONFIG_SGI_GRU_DEBUG
35287 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
35288 index 851b2f2..a4ec097 100644
35289 --- a/drivers/misc/sgi-xp/xp.h
35290 +++ b/drivers/misc/sgi-xp/xp.h
35291 @@ -289,7 +289,7 @@ struct xpc_interface {
35292 xpc_notify_func, void *);
35293 void (*received) (short, int, void *);
35294 enum xp_retval (*partid_to_nasids) (short, void *);
35295 -};
35296 +} __no_const;
35297
35298 extern struct xpc_interface xpc_interface;
35299
35300 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
35301 index b94d5f7..7f494c5 100644
35302 --- a/drivers/misc/sgi-xp/xpc.h
35303 +++ b/drivers/misc/sgi-xp/xpc.h
35304 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
35305 void (*received_payload) (struct xpc_channel *, void *);
35306 void (*notify_senders_of_disconnect) (struct xpc_channel *);
35307 };
35308 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
35309
35310 /* struct xpc_partition act_state values (for XPC HB) */
35311
35312 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
35313 /* found in xpc_main.c */
35314 extern struct device *xpc_part;
35315 extern struct device *xpc_chan;
35316 -extern struct xpc_arch_operations xpc_arch_ops;
35317 +extern xpc_arch_operations_no_const xpc_arch_ops;
35318 extern int xpc_disengage_timelimit;
35319 extern int xpc_disengage_timedout;
35320 extern int xpc_activate_IRQ_rcvd;
35321 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
35322 index 8d082b4..aa749ae 100644
35323 --- a/drivers/misc/sgi-xp/xpc_main.c
35324 +++ b/drivers/misc/sgi-xp/xpc_main.c
35325 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
35326 .notifier_call = xpc_system_die,
35327 };
35328
35329 -struct xpc_arch_operations xpc_arch_ops;
35330 +xpc_arch_operations_no_const xpc_arch_ops;
35331
35332 /*
35333 * Timer function to enforce the timelimit on the partition disengage.
35334 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
35335 index 6ebdc40..9edf5d8 100644
35336 --- a/drivers/mmc/host/sdhci-pci.c
35337 +++ b/drivers/mmc/host/sdhci-pci.c
35338 @@ -631,7 +631,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
35339 .probe = via_probe,
35340 };
35341
35342 -static const struct pci_device_id pci_ids[] __devinitdata = {
35343 +static const struct pci_device_id pci_ids[] __devinitconst = {
35344 {
35345 .vendor = PCI_VENDOR_ID_RICOH,
35346 .device = PCI_DEVICE_ID_RICOH_R5C822,
35347 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
35348 index 87a431c..4959b43 100644
35349 --- a/drivers/mtd/devices/doc2000.c
35350 +++ b/drivers/mtd/devices/doc2000.c
35351 @@ -764,7 +764,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
35352
35353 /* The ECC will not be calculated correctly if less than 512 is written */
35354 /* DBB-
35355 - if (len != 0x200 && eccbuf)
35356 + if (len != 0x200)
35357 printk(KERN_WARNING
35358 "ECC needs a full sector write (adr: %lx size %lx)\n",
35359 (long) to, (long) len);
35360 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
35361 index 9eacf67..4534b5b 100644
35362 --- a/drivers/mtd/devices/doc2001.c
35363 +++ b/drivers/mtd/devices/doc2001.c
35364 @@ -384,7 +384,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
35365 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
35366
35367 /* Don't allow read past end of device */
35368 - if (from >= this->totlen)
35369 + if (from >= this->totlen || !len)
35370 return -EINVAL;
35371
35372 /* Don't allow a single read to cross a 512-byte block boundary */
35373 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
35374 index 3984d48..28aa897 100644
35375 --- a/drivers/mtd/nand/denali.c
35376 +++ b/drivers/mtd/nand/denali.c
35377 @@ -26,6 +26,7 @@
35378 #include <linux/pci.h>
35379 #include <linux/mtd/mtd.h>
35380 #include <linux/module.h>
35381 +#include <linux/slab.h>
35382
35383 #include "denali.h"
35384
35385 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
35386 index 51b9d6a..52af9a7 100644
35387 --- a/drivers/mtd/nftlmount.c
35388 +++ b/drivers/mtd/nftlmount.c
35389 @@ -24,6 +24,7 @@
35390 #include <asm/errno.h>
35391 #include <linux/delay.h>
35392 #include <linux/slab.h>
35393 +#include <linux/sched.h>
35394 #include <linux/mtd/mtd.h>
35395 #include <linux/mtd/nand.h>
35396 #include <linux/mtd/nftl.h>
35397 diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
35398 index e2cdebf..d48183a 100644
35399 --- a/drivers/mtd/ubi/debug.c
35400 +++ b/drivers/mtd/ubi/debug.c
35401 @@ -338,6 +338,8 @@ out:
35402
35403 /* Write an UBI debugfs file */
35404 static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
35405 + size_t count, loff_t *ppos) __size_overflow(3);
35406 +static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
35407 size_t count, loff_t *ppos)
35408 {
35409 unsigned long ubi_num = (unsigned long)file->private_data;
35410 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
35411 index 071f4c8..440862e 100644
35412 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
35413 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
35414 @@ -2862,7 +2862,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
35415 */
35416
35417 #define ATL2_PARAM(X, desc) \
35418 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35419 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
35420 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
35421 MODULE_PARM_DESC(X, desc);
35422 #else
35423 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35424 index 66da39f..5dc436d 100644
35425 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35426 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
35427 @@ -473,7 +473,7 @@ struct bnx2x_rx_mode_obj {
35428
35429 int (*wait_comp)(struct bnx2x *bp,
35430 struct bnx2x_rx_mode_ramrod_params *p);
35431 -};
35432 +} __no_const;
35433
35434 /********************** Set multicast group ***********************************/
35435
35436 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
35437 index aea8f72..fcebf75 100644
35438 --- a/drivers/net/ethernet/broadcom/tg3.h
35439 +++ b/drivers/net/ethernet/broadcom/tg3.h
35440 @@ -140,6 +140,7 @@
35441 #define CHIPREV_ID_5750_A0 0x4000
35442 #define CHIPREV_ID_5750_A1 0x4001
35443 #define CHIPREV_ID_5750_A3 0x4003
35444 +#define CHIPREV_ID_5750_C1 0x4201
35445 #define CHIPREV_ID_5750_C2 0x4202
35446 #define CHIPREV_ID_5752_A0_HW 0x5000
35447 #define CHIPREV_ID_5752_A0 0x6000
35448 diff --git a/drivers/net/ethernet/chelsio/cxgb/sge.c b/drivers/net/ethernet/chelsio/cxgb/sge.c
35449 index 47a8435..248e4b3 100644
35450 --- a/drivers/net/ethernet/chelsio/cxgb/sge.c
35451 +++ b/drivers/net/ethernet/chelsio/cxgb/sge.c
35452 @@ -1052,6 +1052,8 @@ MODULE_PARM_DESC(copybreak, "Receive copy threshold");
35453 * be copied but there is no memory for the copy.
35454 */
35455 static inline struct sk_buff *get_packet(struct pci_dev *pdev,
35456 + struct freelQ *fl, unsigned int len) __size_overflow(3);
35457 +static inline struct sk_buff *get_packet(struct pci_dev *pdev,
35458 struct freelQ *fl, unsigned int len)
35459 {
35460 struct sk_buff *skb;
35461 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35462 index c4e8643..0979484 100644
35463 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35464 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
35465 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
35466 */
35467 struct l2t_skb_cb {
35468 arp_failure_handler_func arp_failure_handler;
35469 -};
35470 +} __no_const;
35471
35472 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
35473
35474 diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
35475 index cfb60e1..94af340 100644
35476 --- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
35477 +++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
35478 @@ -611,6 +611,8 @@ static void recycle_rx_buf(struct adapter *adap, struct sge_fl *q,
35479 * of the SW ring.
35480 */
35481 static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
35482 + size_t sw_size, dma_addr_t * phys, void *metadata) __size_overflow(2,4);
35483 +static void *alloc_ring(struct pci_dev *pdev, size_t nelem, size_t elem_size,
35484 size_t sw_size, dma_addr_t * phys, void *metadata)
35485 {
35486 size_t len = nelem * elem_size;
35487 @@ -777,6 +779,8 @@ static inline unsigned int flits_to_desc(unsigned int n)
35488 * be copied but there is no memory for the copy.
35489 */
35490 static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
35491 + unsigned int len, unsigned int drop_thres) __size_overflow(3);
35492 +static struct sk_buff *get_packet(struct adapter *adap, struct sge_fl *fl,
35493 unsigned int len, unsigned int drop_thres)
35494 {
35495 struct sk_buff *skb = NULL;
35496 diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
35497 index 2dae795..73037d2 100644
35498 --- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
35499 +++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
35500 @@ -593,6 +593,9 @@ static inline void __refill_fl(struct adapter *adap, struct sge_fl *fl)
35501 */
35502 static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
35503 size_t sw_size, dma_addr_t *phys, void *metadata,
35504 + size_t stat_size, int node) __size_overflow(2,4);
35505 +static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size,
35506 + size_t sw_size, dma_addr_t *phys, void *metadata,
35507 size_t stat_size, int node)
35508 {
35509 size_t len = nelem * elem_size + stat_size;
35510 diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
35511 index 0bd585b..d954ca5 100644
35512 --- a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
35513 +++ b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
35514 @@ -729,6 +729,9 @@ static inline void __refill_fl(struct adapter *adapter, struct sge_fl *fl)
35515 */
35516 static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
35517 size_t swsize, dma_addr_t *busaddrp, void *swringp,
35518 + size_t stat_size) __size_overflow(2,4);
35519 +static void *alloc_ring(struct device *dev, size_t nelem, size_t hwsize,
35520 + size_t swsize, dma_addr_t *busaddrp, void *swringp,
35521 size_t stat_size)
35522 {
35523 /*
35524 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
35525 index 4d71f5a..8004440 100644
35526 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
35527 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
35528 @@ -5392,7 +5392,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35529 for (i=0; i<ETH_ALEN; i++) {
35530 tmp.addr[i] = dev->dev_addr[i];
35531 }
35532 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35533 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
35534 break;
35535
35536 case DE4X5_SET_HWADDR: /* Set the hardware address */
35537 @@ -5432,7 +5432,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
35538 spin_lock_irqsave(&lp->lock, flags);
35539 memcpy(&statbuf, &lp->pktStats, ioc->len);
35540 spin_unlock_irqrestore(&lp->lock, flags);
35541 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
35542 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
35543 return -EFAULT;
35544 break;
35545 }
35546 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
35547 index 14d5b61..1398636 100644
35548 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
35549 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
35550 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
35551 {NULL}};
35552
35553
35554 -static const char *block_name[] __devinitdata = {
35555 +static const char *block_name[] __devinitconst = {
35556 "21140 non-MII",
35557 "21140 MII PHY",
35558 "21142 Serial PHY",
35559 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
35560 index 52da7b2..4ddfe1c 100644
35561 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
35562 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
35563 @@ -236,7 +236,7 @@ struct pci_id_info {
35564 int drv_flags; /* Driver use, intended as capability flags. */
35565 };
35566
35567 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35568 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35569 { /* Sometime a Level-One switch card. */
35570 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
35571 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
35572 diff --git a/drivers/net/ethernet/dlink/dl2k.c b/drivers/net/ethernet/dlink/dl2k.c
35573 index b2dc2c8..2e09edb 100644
35574 --- a/drivers/net/ethernet/dlink/dl2k.c
35575 +++ b/drivers/net/ethernet/dlink/dl2k.c
35576 @@ -1259,55 +1259,21 @@ rio_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
35577 {
35578 int phy_addr;
35579 struct netdev_private *np = netdev_priv(dev);
35580 - struct mii_data *miidata = (struct mii_data *) &rq->ifr_ifru;
35581 -
35582 - struct netdev_desc *desc;
35583 - int i;
35584 + struct mii_ioctl_data *miidata = if_mii(rq);
35585
35586 phy_addr = np->phy_addr;
35587 switch (cmd) {
35588 - case SIOCDEVPRIVATE:
35589 + case SIOCGMIIPHY:
35590 + miidata->phy_id = phy_addr;
35591 break;
35592 -
35593 - case SIOCDEVPRIVATE + 1:
35594 - miidata->out_value = mii_read (dev, phy_addr, miidata->reg_num);
35595 + case SIOCGMIIREG:
35596 + miidata->val_out = mii_read (dev, phy_addr, miidata->reg_num);
35597 break;
35598 - case SIOCDEVPRIVATE + 2:
35599 - mii_write (dev, phy_addr, miidata->reg_num, miidata->in_value);
35600 + case SIOCSMIIREG:
35601 + if (!capable(CAP_NET_ADMIN))
35602 + return -EPERM;
35603 + mii_write (dev, phy_addr, miidata->reg_num, miidata->val_in);
35604 break;
35605 - case SIOCDEVPRIVATE + 3:
35606 - break;
35607 - case SIOCDEVPRIVATE + 4:
35608 - break;
35609 - case SIOCDEVPRIVATE + 5:
35610 - netif_stop_queue (dev);
35611 - break;
35612 - case SIOCDEVPRIVATE + 6:
35613 - netif_wake_queue (dev);
35614 - break;
35615 - case SIOCDEVPRIVATE + 7:
35616 - printk
35617 - ("tx_full=%x cur_tx=%lx old_tx=%lx cur_rx=%lx old_rx=%lx\n",
35618 - netif_queue_stopped(dev), np->cur_tx, np->old_tx, np->cur_rx,
35619 - np->old_rx);
35620 - break;
35621 - case SIOCDEVPRIVATE + 8:
35622 - printk("TX ring:\n");
35623 - for (i = 0; i < TX_RING_SIZE; i++) {
35624 - desc = &np->tx_ring[i];
35625 - printk
35626 - ("%02x:cur:%08x next:%08x status:%08x frag1:%08x frag0:%08x",
35627 - i,
35628 - (u32) (np->tx_ring_dma + i * sizeof (*desc)),
35629 - (u32)le64_to_cpu(desc->next_desc),
35630 - (u32)le64_to_cpu(desc->status),
35631 - (u32)(le64_to_cpu(desc->fraginfo) >> 32),
35632 - (u32)le64_to_cpu(desc->fraginfo));
35633 - printk ("\n");
35634 - }
35635 - printk ("\n");
35636 - break;
35637 -
35638 default:
35639 return -EOPNOTSUPP;
35640 }
35641 diff --git a/drivers/net/ethernet/dlink/dl2k.h b/drivers/net/ethernet/dlink/dl2k.h
35642 index ba0adca..30c2da3 100644
35643 --- a/drivers/net/ethernet/dlink/dl2k.h
35644 +++ b/drivers/net/ethernet/dlink/dl2k.h
35645 @@ -365,13 +365,6 @@ struct ioctl_data {
35646 char *data;
35647 };
35648
35649 -struct mii_data {
35650 - __u16 reserved;
35651 - __u16 reg_num;
35652 - __u16 in_value;
35653 - __u16 out_value;
35654 -};
35655 -
35656 /* The Rx and Tx buffer descriptors. */
35657 struct netdev_desc {
35658 __le64 next_desc;
35659 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
35660 index 28a3a9b..d96cb63 100644
35661 --- a/drivers/net/ethernet/dlink/sundance.c
35662 +++ b/drivers/net/ethernet/dlink/sundance.c
35663 @@ -218,7 +218,7 @@ enum {
35664 struct pci_id_info {
35665 const char *name;
35666 };
35667 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
35668 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
35669 {"D-Link DFE-550TX FAST Ethernet Adapter"},
35670 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
35671 {"D-Link DFE-580TX 4 port Server Adapter"},
35672 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
35673 index e703d64..d62ecf9 100644
35674 --- a/drivers/net/ethernet/emulex/benet/be_main.c
35675 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
35676 @@ -402,7 +402,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
35677
35678 if (wrapped)
35679 newacc += 65536;
35680 - ACCESS_ONCE(*acc) = newacc;
35681 + ACCESS_ONCE_RW(*acc) = newacc;
35682 }
35683
35684 void be_parse_stats(struct be_adapter *adapter)
35685 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
35686 index 47f85c3..82ab6c4 100644
35687 --- a/drivers/net/ethernet/faraday/ftgmac100.c
35688 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
35689 @@ -31,6 +31,8 @@
35690 #include <linux/netdevice.h>
35691 #include <linux/phy.h>
35692 #include <linux/platform_device.h>
35693 +#include <linux/interrupt.h>
35694 +#include <linux/irqreturn.h>
35695 #include <net/ip.h>
35696
35697 #include "ftgmac100.h"
35698 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
35699 index bb336a0..4b472da 100644
35700 --- a/drivers/net/ethernet/faraday/ftmac100.c
35701 +++ b/drivers/net/ethernet/faraday/ftmac100.c
35702 @@ -31,6 +31,8 @@
35703 #include <linux/module.h>
35704 #include <linux/netdevice.h>
35705 #include <linux/platform_device.h>
35706 +#include <linux/interrupt.h>
35707 +#include <linux/irqreturn.h>
35708
35709 #include "ftmac100.h"
35710
35711 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
35712 index c82d444..0007fb4 100644
35713 --- a/drivers/net/ethernet/fealnx.c
35714 +++ b/drivers/net/ethernet/fealnx.c
35715 @@ -150,7 +150,7 @@ struct chip_info {
35716 int flags;
35717 };
35718
35719 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35720 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35721 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35722 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35723 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35724 diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c
35725 index b444f21..b72d976 100644
35726 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c
35727 +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c
35728 @@ -492,7 +492,11 @@ out:
35729 static void e1000_down_and_stop(struct e1000_adapter *adapter)
35730 {
35731 set_bit(__E1000_DOWN, &adapter->flags);
35732 - cancel_work_sync(&adapter->reset_task);
35733 +
35734 + /* Only kill reset task if adapter is not resetting */
35735 + if (!test_bit(__E1000_RESETTING, &adapter->flags))
35736 + cancel_work_sync(&adapter->reset_task);
35737 +
35738 cancel_delayed_work_sync(&adapter->watchdog_task);
35739 cancel_delayed_work_sync(&adapter->phy_info_task);
35740 cancel_delayed_work_sync(&adapter->fifo_stall_task);
35741 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
35742 index e1159e5..e18684d 100644
35743 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
35744 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
35745 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
35746 {
35747 struct e1000_hw *hw = &adapter->hw;
35748 struct e1000_mac_info *mac = &hw->mac;
35749 - struct e1000_mac_operations *func = &mac->ops;
35750 + e1000_mac_operations_no_const *func = &mac->ops;
35751
35752 /* Set media type */
35753 switch (adapter->pdev->device) {
35754 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
35755 index a3e65fd..f451444 100644
35756 --- a/drivers/net/ethernet/intel/e1000e/82571.c
35757 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
35758 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
35759 {
35760 struct e1000_hw *hw = &adapter->hw;
35761 struct e1000_mac_info *mac = &hw->mac;
35762 - struct e1000_mac_operations *func = &mac->ops;
35763 + e1000_mac_operations_no_const *func = &mac->ops;
35764 u32 swsm = 0;
35765 u32 swsm2 = 0;
35766 bool force_clear_smbi = false;
35767 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35768 index 2967039..ca8c40c 100644
35769 --- a/drivers/net/ethernet/intel/e1000e/hw.h
35770 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
35771 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
35772 void (*write_vfta)(struct e1000_hw *, u32, u32);
35773 s32 (*read_mac_addr)(struct e1000_hw *);
35774 };
35775 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35776
35777 /*
35778 * When to use various PHY register access functions:
35779 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
35780 void (*power_up)(struct e1000_hw *);
35781 void (*power_down)(struct e1000_hw *);
35782 };
35783 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35784
35785 /* Function pointers for the NVM. */
35786 struct e1000_nvm_operations {
35787 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
35788 s32 (*validate)(struct e1000_hw *);
35789 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35790 };
35791 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35792
35793 struct e1000_mac_info {
35794 - struct e1000_mac_operations ops;
35795 + e1000_mac_operations_no_const ops;
35796 u8 addr[ETH_ALEN];
35797 u8 perm_addr[ETH_ALEN];
35798
35799 @@ -872,7 +875,7 @@ struct e1000_mac_info {
35800 };
35801
35802 struct e1000_phy_info {
35803 - struct e1000_phy_operations ops;
35804 + e1000_phy_operations_no_const ops;
35805
35806 enum e1000_phy_type type;
35807
35808 @@ -906,7 +909,7 @@ struct e1000_phy_info {
35809 };
35810
35811 struct e1000_nvm_info {
35812 - struct e1000_nvm_operations ops;
35813 + e1000_nvm_operations_no_const ops;
35814
35815 enum e1000_nvm_type type;
35816 enum e1000_nvm_override override;
35817 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35818 index f67cbd3..cef9e3d 100644
35819 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35820 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35821 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
35822 s32 (*read_mac_addr)(struct e1000_hw *);
35823 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
35824 };
35825 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35826
35827 struct e1000_phy_operations {
35828 s32 (*acquire)(struct e1000_hw *);
35829 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
35830 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35831 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35832 };
35833 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35834
35835 struct e1000_nvm_operations {
35836 s32 (*acquire)(struct e1000_hw *);
35837 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
35838 s32 (*update)(struct e1000_hw *);
35839 s32 (*validate)(struct e1000_hw *);
35840 };
35841 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35842
35843 struct e1000_info {
35844 s32 (*get_invariants)(struct e1000_hw *);
35845 @@ -350,7 +353,7 @@ struct e1000_info {
35846 extern const struct e1000_info e1000_82575_info;
35847
35848 struct e1000_mac_info {
35849 - struct e1000_mac_operations ops;
35850 + e1000_mac_operations_no_const ops;
35851
35852 u8 addr[6];
35853 u8 perm_addr[6];
35854 @@ -388,7 +391,7 @@ struct e1000_mac_info {
35855 };
35856
35857 struct e1000_phy_info {
35858 - struct e1000_phy_operations ops;
35859 + e1000_phy_operations_no_const ops;
35860
35861 enum e1000_phy_type type;
35862
35863 @@ -423,7 +426,7 @@ struct e1000_phy_info {
35864 };
35865
35866 struct e1000_nvm_info {
35867 - struct e1000_nvm_operations ops;
35868 + e1000_nvm_operations_no_const ops;
35869 enum e1000_nvm_type type;
35870 enum e1000_nvm_override override;
35871
35872 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
35873 s32 (*check_for_ack)(struct e1000_hw *, u16);
35874 s32 (*check_for_rst)(struct e1000_hw *, u16);
35875 };
35876 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35877
35878 struct e1000_mbx_stats {
35879 u32 msgs_tx;
35880 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
35881 };
35882
35883 struct e1000_mbx_info {
35884 - struct e1000_mbx_operations ops;
35885 + e1000_mbx_operations_no_const ops;
35886 struct e1000_mbx_stats stats;
35887 u32 timeout;
35888 u32 usec_delay;
35889 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35890 index 57db3c6..aa825fc 100644
35891 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35892 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35893 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35894 s32 (*read_mac_addr)(struct e1000_hw *);
35895 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35896 };
35897 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35898
35899 struct e1000_mac_info {
35900 - struct e1000_mac_operations ops;
35901 + e1000_mac_operations_no_const ops;
35902 u8 addr[6];
35903 u8 perm_addr[6];
35904
35905 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35906 s32 (*check_for_ack)(struct e1000_hw *);
35907 s32 (*check_for_rst)(struct e1000_hw *);
35908 };
35909 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35910
35911 struct e1000_mbx_stats {
35912 u32 msgs_tx;
35913 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35914 };
35915
35916 struct e1000_mbx_info {
35917 - struct e1000_mbx_operations ops;
35918 + e1000_mbx_operations_no_const ops;
35919 struct e1000_mbx_stats stats;
35920 u32 timeout;
35921 u32 usec_delay;
35922 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35923 index 9b95bef..7e254ee 100644
35924 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35925 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35926 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
35927 s32 (*update_checksum)(struct ixgbe_hw *);
35928 u16 (*calc_checksum)(struct ixgbe_hw *);
35929 };
35930 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35931
35932 struct ixgbe_mac_operations {
35933 s32 (*init_hw)(struct ixgbe_hw *);
35934 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
35935 /* Manageability interface */
35936 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
35937 };
35938 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35939
35940 struct ixgbe_phy_operations {
35941 s32 (*identify)(struct ixgbe_hw *);
35942 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
35943 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35944 s32 (*check_overtemp)(struct ixgbe_hw *);
35945 };
35946 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35947
35948 struct ixgbe_eeprom_info {
35949 - struct ixgbe_eeprom_operations ops;
35950 + ixgbe_eeprom_operations_no_const ops;
35951 enum ixgbe_eeprom_type type;
35952 u32 semaphore_delay;
35953 u16 word_size;
35954 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
35955
35956 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35957 struct ixgbe_mac_info {
35958 - struct ixgbe_mac_operations ops;
35959 + ixgbe_mac_operations_no_const ops;
35960 enum ixgbe_mac_type type;
35961 u8 addr[ETH_ALEN];
35962 u8 perm_addr[ETH_ALEN];
35963 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
35964 };
35965
35966 struct ixgbe_phy_info {
35967 - struct ixgbe_phy_operations ops;
35968 + ixgbe_phy_operations_no_const ops;
35969 struct mdio_if_info mdio;
35970 enum ixgbe_phy_type type;
35971 u32 id;
35972 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
35973 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35974 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35975 };
35976 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35977
35978 struct ixgbe_mbx_stats {
35979 u32 msgs_tx;
35980 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
35981 };
35982
35983 struct ixgbe_mbx_info {
35984 - struct ixgbe_mbx_operations ops;
35985 + ixgbe_mbx_operations_no_const ops;
35986 struct ixgbe_mbx_stats stats;
35987 u32 timeout;
35988 u32 usec_delay;
35989 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35990 index 25c951d..cc7cf33 100644
35991 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35992 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35993 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35994 s32 (*clear_vfta)(struct ixgbe_hw *);
35995 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35996 };
35997 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35998
35999 enum ixgbe_mac_type {
36000 ixgbe_mac_unknown = 0,
36001 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
36002 };
36003
36004 struct ixgbe_mac_info {
36005 - struct ixgbe_mac_operations ops;
36006 + ixgbe_mac_operations_no_const ops;
36007 u8 addr[6];
36008 u8 perm_addr[6];
36009
36010 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
36011 s32 (*check_for_ack)(struct ixgbe_hw *);
36012 s32 (*check_for_rst)(struct ixgbe_hw *);
36013 };
36014 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
36015
36016 struct ixgbe_mbx_stats {
36017 u32 msgs_tx;
36018 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
36019 };
36020
36021 struct ixgbe_mbx_info {
36022 - struct ixgbe_mbx_operations ops;
36023 + ixgbe_mbx_operations_no_const ops;
36024 struct ixgbe_mbx_stats stats;
36025 u32 timeout;
36026 u32 udelay;
36027 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
36028 index 8bf22b6..7f5baaa 100644
36029 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
36030 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
36031 @@ -41,6 +41,7 @@
36032 #include <linux/slab.h>
36033 #include <linux/io-mapping.h>
36034 #include <linux/delay.h>
36035 +#include <linux/sched.h>
36036
36037 #include <linux/mlx4/device.h>
36038 #include <linux/mlx4/doorbell.h>
36039 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
36040 index 5046a64..71ca936 100644
36041 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
36042 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
36043 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
36044 void (*link_down)(struct __vxge_hw_device *devh);
36045 void (*crit_err)(struct __vxge_hw_device *devh,
36046 enum vxge_hw_event type, u64 ext_data);
36047 -};
36048 +} __no_const;
36049
36050 /*
36051 * struct __vxge_hw_blockpool_entry - Block private data structure
36052 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
36053 index 4a518a3..936b334 100644
36054 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
36055 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
36056 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
36057 struct vxge_hw_mempool_dma *dma_object,
36058 u32 index,
36059 u32 is_last);
36060 -};
36061 +} __no_const;
36062
36063 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
36064 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
36065 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36066 index bbacb37..d60887d 100644
36067 --- a/drivers/net/ethernet/realtek/r8169.c
36068 +++ b/drivers/net/ethernet/realtek/r8169.c
36069 @@ -695,17 +695,17 @@ struct rtl8169_private {
36070 struct mdio_ops {
36071 void (*write)(void __iomem *, int, int);
36072 int (*read)(void __iomem *, int);
36073 - } mdio_ops;
36074 + } __no_const mdio_ops;
36075
36076 struct pll_power_ops {
36077 void (*down)(struct rtl8169_private *);
36078 void (*up)(struct rtl8169_private *);
36079 - } pll_power_ops;
36080 + } __no_const pll_power_ops;
36081
36082 struct jumbo_ops {
36083 void (*enable)(struct rtl8169_private *);
36084 void (*disable)(struct rtl8169_private *);
36085 - } jumbo_ops;
36086 + } __no_const jumbo_ops;
36087
36088 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36089 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36090 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
36091 index 5b118cd..858b523 100644
36092 --- a/drivers/net/ethernet/sis/sis190.c
36093 +++ b/drivers/net/ethernet/sis/sis190.c
36094 @@ -1622,7 +1622,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
36095 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
36096 struct net_device *dev)
36097 {
36098 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
36099 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
36100 struct sis190_private *tp = netdev_priv(dev);
36101 struct pci_dev *isa_bridge;
36102 u8 reg, tmp8;
36103 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36104 index c07cfe9..81cbf7e 100644
36105 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36106 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36107 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36108
36109 writel(value, ioaddr + MMC_CNTRL);
36110
36111 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36112 - MMC_CNTRL, value);
36113 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36114 +// MMC_CNTRL, value);
36115 }
36116
36117 /* To mask all all interrupts.*/
36118 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36119 index dec5836..6d4db7d 100644
36120 --- a/drivers/net/hyperv/hyperv_net.h
36121 +++ b/drivers/net/hyperv/hyperv_net.h
36122 @@ -97,7 +97,7 @@ struct rndis_device {
36123
36124 enum rndis_device_state state;
36125 bool link_state;
36126 - atomic_t new_req_id;
36127 + atomic_unchecked_t new_req_id;
36128
36129 spinlock_t request_lock;
36130 struct list_head req_list;
36131 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36132 index 133b7fb..d58c559 100644
36133 --- a/drivers/net/hyperv/rndis_filter.c
36134 +++ b/drivers/net/hyperv/rndis_filter.c
36135 @@ -96,7 +96,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36136 * template
36137 */
36138 set = &rndis_msg->msg.set_req;
36139 - set->req_id = atomic_inc_return(&dev->new_req_id);
36140 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36141
36142 /* Add to the request list */
36143 spin_lock_irqsave(&dev->request_lock, flags);
36144 @@ -627,7 +627,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36145
36146 /* Setup the rndis set */
36147 halt = &request->request_msg.msg.halt_req;
36148 - halt->req_id = atomic_inc_return(&dev->new_req_id);
36149 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36150
36151 /* Ignore return since this msg is optional. */
36152 rndis_filter_send_request(dev, request);
36153 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36154 index 58dc117..f140c77 100644
36155 --- a/drivers/net/macvtap.c
36156 +++ b/drivers/net/macvtap.c
36157 @@ -526,6 +526,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
36158 }
36159 base = (unsigned long)from->iov_base + offset1;
36160 size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
36161 + if (i + size >= MAX_SKB_FRAGS)
36162 + return -EFAULT;
36163 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
36164 if ((num_pages != size) ||
36165 (num_pages > MAX_SKB_FRAGS - skb_shinfo(skb)->nr_frags))
36166 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36167 index 3ed983c..a1bb418 100644
36168 --- a/drivers/net/ppp/ppp_generic.c
36169 +++ b/drivers/net/ppp/ppp_generic.c
36170 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36171 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36172 struct ppp_stats stats;
36173 struct ppp_comp_stats cstats;
36174 - char *vers;
36175
36176 switch (cmd) {
36177 case SIOCGPPPSTATS:
36178 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36179 break;
36180
36181 case SIOCGPPPVER:
36182 - vers = PPP_VERSION;
36183 - if (copy_to_user(addr, vers, strlen(vers) + 1))
36184 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36185 break;
36186 err = 0;
36187 break;
36188 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
36189 index 515f122..41dd273 100644
36190 --- a/drivers/net/tokenring/abyss.c
36191 +++ b/drivers/net/tokenring/abyss.c
36192 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
36193
36194 static int __init abyss_init (void)
36195 {
36196 - abyss_netdev_ops = tms380tr_netdev_ops;
36197 + pax_open_kernel();
36198 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
36199
36200 - abyss_netdev_ops.ndo_open = abyss_open;
36201 - abyss_netdev_ops.ndo_stop = abyss_close;
36202 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
36203 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
36204 + pax_close_kernel();
36205
36206 return pci_register_driver(&abyss_driver);
36207 }
36208 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
36209 index 6153cfd..cf69c1c 100644
36210 --- a/drivers/net/tokenring/madgemc.c
36211 +++ b/drivers/net/tokenring/madgemc.c
36212 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
36213
36214 static int __init madgemc_init (void)
36215 {
36216 - madgemc_netdev_ops = tms380tr_netdev_ops;
36217 - madgemc_netdev_ops.ndo_open = madgemc_open;
36218 - madgemc_netdev_ops.ndo_stop = madgemc_close;
36219 + pax_open_kernel();
36220 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
36221 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
36222 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
36223 + pax_close_kernel();
36224
36225 return mca_register_driver (&madgemc_driver);
36226 }
36227 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
36228 index 8d362e6..f91cc52 100644
36229 --- a/drivers/net/tokenring/proteon.c
36230 +++ b/drivers/net/tokenring/proteon.c
36231 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
36232 struct platform_device *pdev;
36233 int i, num = 0, err = 0;
36234
36235 - proteon_netdev_ops = tms380tr_netdev_ops;
36236 - proteon_netdev_ops.ndo_open = proteon_open;
36237 - proteon_netdev_ops.ndo_stop = tms380tr_close;
36238 + pax_open_kernel();
36239 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
36240 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
36241 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
36242 + pax_close_kernel();
36243
36244 err = platform_driver_register(&proteon_driver);
36245 if (err)
36246 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
36247 index 46db5c5..37c1536 100644
36248 --- a/drivers/net/tokenring/skisa.c
36249 +++ b/drivers/net/tokenring/skisa.c
36250 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
36251 struct platform_device *pdev;
36252 int i, num = 0, err = 0;
36253
36254 - sk_isa_netdev_ops = tms380tr_netdev_ops;
36255 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
36256 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
36257 + pax_open_kernel();
36258 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
36259 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
36260 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
36261 + pax_close_kernel();
36262
36263 err = platform_driver_register(&sk_isa_driver);
36264 if (err)
36265 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
36266 index e1324b4..e1b0041 100644
36267 --- a/drivers/net/usb/hso.c
36268 +++ b/drivers/net/usb/hso.c
36269 @@ -71,7 +71,7 @@
36270 #include <asm/byteorder.h>
36271 #include <linux/serial_core.h>
36272 #include <linux/serial.h>
36273 -
36274 +#include <asm/local.h>
36275
36276 #define MOD_AUTHOR "Option Wireless"
36277 #define MOD_DESCRIPTION "USB High Speed Option driver"
36278 @@ -257,7 +257,7 @@ struct hso_serial {
36279
36280 /* from usb_serial_port */
36281 struct tty_struct *tty;
36282 - int open_count;
36283 + local_t open_count;
36284 spinlock_t serial_lock;
36285
36286 int (*write_data) (struct hso_serial *serial);
36287 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
36288 struct urb *urb;
36289
36290 urb = serial->rx_urb[0];
36291 - if (serial->open_count > 0) {
36292 + if (local_read(&serial->open_count) > 0) {
36293 count = put_rxbuf_data(urb, serial);
36294 if (count == -1)
36295 return;
36296 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
36297 DUMP1(urb->transfer_buffer, urb->actual_length);
36298
36299 /* Anyone listening? */
36300 - if (serial->open_count == 0)
36301 + if (local_read(&serial->open_count) == 0)
36302 return;
36303
36304 if (status == 0) {
36305 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36306 spin_unlock_irq(&serial->serial_lock);
36307
36308 /* check for port already opened, if not set the termios */
36309 - serial->open_count++;
36310 - if (serial->open_count == 1) {
36311 + if (local_inc_return(&serial->open_count) == 1) {
36312 serial->rx_state = RX_IDLE;
36313 /* Force default termio settings */
36314 _hso_serial_set_termios(tty, NULL);
36315 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36316 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
36317 if (result) {
36318 hso_stop_serial_device(serial->parent);
36319 - serial->open_count--;
36320 + local_dec(&serial->open_count);
36321 kref_put(&serial->parent->ref, hso_serial_ref_free);
36322 }
36323 } else {
36324 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
36325
36326 /* reset the rts and dtr */
36327 /* do the actual close */
36328 - serial->open_count--;
36329 + local_dec(&serial->open_count);
36330
36331 - if (serial->open_count <= 0) {
36332 - serial->open_count = 0;
36333 + if (local_read(&serial->open_count) <= 0) {
36334 + local_set(&serial->open_count, 0);
36335 spin_lock_irq(&serial->serial_lock);
36336 if (serial->tty == tty) {
36337 serial->tty->driver_data = NULL;
36338 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
36339
36340 /* the actual setup */
36341 spin_lock_irqsave(&serial->serial_lock, flags);
36342 - if (serial->open_count)
36343 + if (local_read(&serial->open_count))
36344 _hso_serial_set_termios(tty, old);
36345 else
36346 tty->termios = old;
36347 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
36348 D1("Pending read interrupt on port %d\n", i);
36349 spin_lock(&serial->serial_lock);
36350 if (serial->rx_state == RX_IDLE &&
36351 - serial->open_count > 0) {
36352 + local_read(&serial->open_count) > 0) {
36353 /* Setup and send a ctrl req read on
36354 * port i */
36355 if (!serial->rx_urb_filled[0]) {
36356 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
36357 /* Start all serial ports */
36358 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
36359 if (serial_table[i] && (serial_table[i]->interface == iface)) {
36360 - if (dev2ser(serial_table[i])->open_count) {
36361 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
36362 result =
36363 hso_start_serial_device(serial_table[i], GFP_NOIO);
36364 hso_kick_transmit(dev2ser(serial_table[i]));
36365 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
36366 index efc0111..79c8f5b 100644
36367 --- a/drivers/net/wireless/ath/ath.h
36368 +++ b/drivers/net/wireless/ath/ath.h
36369 @@ -119,6 +119,7 @@ struct ath_ops {
36370 void (*write_flush) (void *);
36371 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
36372 };
36373 +typedef struct ath_ops __no_const ath_ops_no_const;
36374
36375 struct ath_common;
36376 struct ath_bus_ops;
36377 diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
36378 index 8c5ce8b..abf101b 100644
36379 --- a/drivers/net/wireless/ath/ath5k/debug.c
36380 +++ b/drivers/net/wireless/ath/ath5k/debug.c
36381 @@ -343,6 +343,9 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
36382
36383 static ssize_t write_file_debug(struct file *file,
36384 const char __user *userbuf,
36385 + size_t count, loff_t *ppos) __size_overflow(3);
36386 +static ssize_t write_file_debug(struct file *file,
36387 + const char __user *userbuf,
36388 size_t count, loff_t *ppos)
36389 {
36390 struct ath5k_hw *ah = file->private_data;
36391 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36392 index 7b6417b..ab5db98 100644
36393 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36394 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36395 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36396 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
36397 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
36398
36399 - ACCESS_ONCE(ads->ds_link) = i->link;
36400 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
36401 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
36402 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
36403
36404 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
36405 ctl6 = SM(i->keytype, AR_EncrType);
36406 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36407
36408 if ((i->is_first || i->is_last) &&
36409 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
36410 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
36411 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
36412 | set11nTries(i->rates, 1)
36413 | set11nTries(i->rates, 2)
36414 | set11nTries(i->rates, 3)
36415 | (i->dur_update ? AR_DurUpdateEna : 0)
36416 | SM(0, AR_BurstDur);
36417
36418 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
36419 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
36420 | set11nRate(i->rates, 1)
36421 | set11nRate(i->rates, 2)
36422 | set11nRate(i->rates, 3);
36423 } else {
36424 - ACCESS_ONCE(ads->ds_ctl2) = 0;
36425 - ACCESS_ONCE(ads->ds_ctl3) = 0;
36426 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
36427 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
36428 }
36429
36430 if (!i->is_first) {
36431 - ACCESS_ONCE(ads->ds_ctl0) = 0;
36432 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36433 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36434 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
36435 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36436 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36437 return;
36438 }
36439
36440 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36441 break;
36442 }
36443
36444 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36445 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36446 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36447 | SM(i->txpower, AR_XmitPower)
36448 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36449 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36450 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
36451 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
36452
36453 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36454 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36455 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36456 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36457
36458 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
36459 return;
36460
36461 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36462 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36463 | set11nPktDurRTSCTS(i->rates, 1);
36464
36465 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36466 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36467 | set11nPktDurRTSCTS(i->rates, 3);
36468
36469 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36470 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36471 | set11nRateFlags(i->rates, 1)
36472 | set11nRateFlags(i->rates, 2)
36473 | set11nRateFlags(i->rates, 3)
36474 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36475 index 09b8c9d..905339e 100644
36476 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36477 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36478 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36479 (i->qcu << AR_TxQcuNum_S) | 0x17;
36480
36481 checksum += val;
36482 - ACCESS_ONCE(ads->info) = val;
36483 + ACCESS_ONCE_RW(ads->info) = val;
36484
36485 checksum += i->link;
36486 - ACCESS_ONCE(ads->link) = i->link;
36487 + ACCESS_ONCE_RW(ads->link) = i->link;
36488
36489 checksum += i->buf_addr[0];
36490 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
36491 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
36492 checksum += i->buf_addr[1];
36493 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
36494 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
36495 checksum += i->buf_addr[2];
36496 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
36497 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
36498 checksum += i->buf_addr[3];
36499 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
36500 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
36501
36502 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
36503 - ACCESS_ONCE(ads->ctl3) = val;
36504 + ACCESS_ONCE_RW(ads->ctl3) = val;
36505 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
36506 - ACCESS_ONCE(ads->ctl5) = val;
36507 + ACCESS_ONCE_RW(ads->ctl5) = val;
36508 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
36509 - ACCESS_ONCE(ads->ctl7) = val;
36510 + ACCESS_ONCE_RW(ads->ctl7) = val;
36511 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
36512 - ACCESS_ONCE(ads->ctl9) = val;
36513 + ACCESS_ONCE_RW(ads->ctl9) = val;
36514
36515 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
36516 - ACCESS_ONCE(ads->ctl10) = checksum;
36517 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
36518
36519 if (i->is_first || i->is_last) {
36520 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
36521 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
36522 | set11nTries(i->rates, 1)
36523 | set11nTries(i->rates, 2)
36524 | set11nTries(i->rates, 3)
36525 | (i->dur_update ? AR_DurUpdateEna : 0)
36526 | SM(0, AR_BurstDur);
36527
36528 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
36529 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
36530 | set11nRate(i->rates, 1)
36531 | set11nRate(i->rates, 2)
36532 | set11nRate(i->rates, 3);
36533 } else {
36534 - ACCESS_ONCE(ads->ctl13) = 0;
36535 - ACCESS_ONCE(ads->ctl14) = 0;
36536 + ACCESS_ONCE_RW(ads->ctl13) = 0;
36537 + ACCESS_ONCE_RW(ads->ctl14) = 0;
36538 }
36539
36540 ads->ctl20 = 0;
36541 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36542
36543 ctl17 = SM(i->keytype, AR_EncrType);
36544 if (!i->is_first) {
36545 - ACCESS_ONCE(ads->ctl11) = 0;
36546 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36547 - ACCESS_ONCE(ads->ctl15) = 0;
36548 - ACCESS_ONCE(ads->ctl16) = 0;
36549 - ACCESS_ONCE(ads->ctl17) = ctl17;
36550 - ACCESS_ONCE(ads->ctl18) = 0;
36551 - ACCESS_ONCE(ads->ctl19) = 0;
36552 + ACCESS_ONCE_RW(ads->ctl11) = 0;
36553 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36554 + ACCESS_ONCE_RW(ads->ctl15) = 0;
36555 + ACCESS_ONCE_RW(ads->ctl16) = 0;
36556 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36557 + ACCESS_ONCE_RW(ads->ctl18) = 0;
36558 + ACCESS_ONCE_RW(ads->ctl19) = 0;
36559 return;
36560 }
36561
36562 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36563 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36564 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36565 | SM(i->txpower, AR_XmitPower)
36566 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36567 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36568 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36569 ctl12 |= SM(val, AR_PAPRDChainMask);
36570
36571 - ACCESS_ONCE(ads->ctl12) = ctl12;
36572 - ACCESS_ONCE(ads->ctl17) = ctl17;
36573 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
36574 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36575
36576 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36577 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36578 | set11nPktDurRTSCTS(i->rates, 1);
36579
36580 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36581 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36582 | set11nPktDurRTSCTS(i->rates, 3);
36583
36584 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
36585 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
36586 | set11nRateFlags(i->rates, 1)
36587 | set11nRateFlags(i->rates, 2)
36588 | set11nRateFlags(i->rates, 3)
36589 | SM(i->rtscts_rate, AR_RTSCTSRate);
36590
36591 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
36592 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
36593 }
36594
36595 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
36596 diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
36597 index 68d972b..1d9205b 100644
36598 --- a/drivers/net/wireless/ath/ath9k/debug.c
36599 +++ b/drivers/net/wireless/ath/ath9k/debug.c
36600 @@ -60,6 +60,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
36601 }
36602
36603 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
36604 + size_t count, loff_t *ppos) __size_overflow(3);
36605 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
36606 size_t count, loff_t *ppos)
36607 {
36608 struct ath_softc *sc = file->private_data;
36609 diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
36610 index d3ff33c..c98bcda 100644
36611 --- a/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
36612 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_debug.c
36613 @@ -464,6 +464,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
36614 }
36615
36616 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
36617 + size_t count, loff_t *ppos) __size_overflow(3);
36618 +static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
36619 size_t count, loff_t *ppos)
36620 {
36621 struct ath9k_htc_priv *priv = file->private_data;
36622 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
36623 index c8261d4..8d88929 100644
36624 --- a/drivers/net/wireless/ath/ath9k/hw.h
36625 +++ b/drivers/net/wireless/ath/ath9k/hw.h
36626 @@ -773,7 +773,7 @@ struct ath_hw_private_ops {
36627
36628 /* ANI */
36629 void (*ani_cache_ini_regs)(struct ath_hw *ah);
36630 -};
36631 +} __no_const;
36632
36633 /**
36634 * struct ath_hw_ops - callbacks used by hardware code and driver code
36635 @@ -803,7 +803,7 @@ struct ath_hw_ops {
36636 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
36637 struct ath_hw_antcomb_conf *antconf);
36638
36639 -};
36640 +} __no_const;
36641
36642 struct ath_nf_limits {
36643 s16 max;
36644 @@ -823,7 +823,7 @@ enum ath_cal_list {
36645 #define AH_FASTCC 0x4
36646
36647 struct ath_hw {
36648 - struct ath_ops reg_ops;
36649 + ath_ops_no_const reg_ops;
36650
36651 struct ieee80211_hw *hw;
36652 struct ath_common common;
36653 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36654 index af00e2c..ab04d34 100644
36655 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36656 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
36657 @@ -545,7 +545,7 @@ struct phy_func_ptr {
36658 void (*carrsuppr)(struct brcms_phy *);
36659 s32 (*rxsigpwr)(struct brcms_phy *, s32);
36660 void (*detach)(struct brcms_phy *);
36661 -};
36662 +} __no_const;
36663
36664 struct brcms_phy {
36665 struct brcms_phy_pub pubpi_ro;
36666 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
36667 index a2ec369..36fdf14 100644
36668 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
36669 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
36670 @@ -3646,7 +3646,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
36671 */
36672 if (il3945_mod_params.disable_hw_scan) {
36673 D_INFO("Disabling hw_scan\n");
36674 - il3945_hw_ops.hw_scan = NULL;
36675 + pax_open_kernel();
36676 + *(void **)&il3945_hw_ops.hw_scan = NULL;
36677 + pax_close_kernel();
36678 }
36679
36680 D_INFO("*** LOAD DRIVER ***\n");
36681 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
36682 index f8fc239..8cade22 100644
36683 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
36684 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
36685 @@ -86,8 +86,8 @@ do { \
36686 } while (0)
36687
36688 #else
36689 -#define IWL_DEBUG(m, level, fmt, args...)
36690 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
36691 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
36692 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
36693 #define iwl_print_hex_dump(m, level, p, len)
36694 #define IWL_DEBUG_QUIET_RFKILL(p, fmt, args...) \
36695 do { \
36696 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36697 index 4b9e730..7603659 100644
36698 --- a/drivers/net/wireless/mac80211_hwsim.c
36699 +++ b/drivers/net/wireless/mac80211_hwsim.c
36700 @@ -1677,9 +1677,11 @@ static int __init init_mac80211_hwsim(void)
36701 return -EINVAL;
36702
36703 if (fake_hw_scan) {
36704 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36705 - mac80211_hwsim_ops.sw_scan_start = NULL;
36706 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36707 + pax_open_kernel();
36708 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36709 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36710 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36711 + pax_close_kernel();
36712 }
36713
36714 spin_lock_init(&hwsim_radio_lock);
36715 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36716 index 3186aa4..b35b09f 100644
36717 --- a/drivers/net/wireless/mwifiex/main.h
36718 +++ b/drivers/net/wireless/mwifiex/main.h
36719 @@ -536,7 +536,7 @@ struct mwifiex_if_ops {
36720 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
36721 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
36722 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36723 -};
36724 +} __no_const;
36725
36726 struct mwifiex_adapter {
36727 u8 iface_type;
36728 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36729 index a330c69..a81540f 100644
36730 --- a/drivers/net/wireless/rndis_wlan.c
36731 +++ b/drivers/net/wireless/rndis_wlan.c
36732 @@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36733
36734 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36735
36736 - if (rts_threshold < 0 || rts_threshold > 2347)
36737 + if (rts_threshold > 2347)
36738 rts_threshold = 2347;
36739
36740 tmp = cpu_to_le32(rts_threshold);
36741 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
36742 index a77f1bb..c608b2b 100644
36743 --- a/drivers/net/wireless/wl1251/wl1251.h
36744 +++ b/drivers/net/wireless/wl1251/wl1251.h
36745 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36746 void (*reset)(struct wl1251 *wl);
36747 void (*enable_irq)(struct wl1251 *wl);
36748 void (*disable_irq)(struct wl1251 *wl);
36749 -};
36750 +} __no_const;
36751
36752 struct wl1251 {
36753 struct ieee80211_hw *hw;
36754 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36755 index f34b5b2..b5abb9f 100644
36756 --- a/drivers/oprofile/buffer_sync.c
36757 +++ b/drivers/oprofile/buffer_sync.c
36758 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36759 if (cookie == NO_COOKIE)
36760 offset = pc;
36761 if (cookie == INVALID_COOKIE) {
36762 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36763 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36764 offset = pc;
36765 }
36766 if (cookie != last_cookie) {
36767 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36768 /* add userspace sample */
36769
36770 if (!mm) {
36771 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36772 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36773 return 0;
36774 }
36775
36776 cookie = lookup_dcookie(mm, s->eip, &offset);
36777
36778 if (cookie == INVALID_COOKIE) {
36779 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36780 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36781 return 0;
36782 }
36783
36784 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36785 /* ignore backtraces if failed to add a sample */
36786 if (state == sb_bt_start) {
36787 state = sb_bt_ignore;
36788 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36789 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36790 }
36791 }
36792 release_mm(mm);
36793 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36794 index c0cc4e7..44d4e54 100644
36795 --- a/drivers/oprofile/event_buffer.c
36796 +++ b/drivers/oprofile/event_buffer.c
36797 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36798 }
36799
36800 if (buffer_pos == buffer_size) {
36801 - atomic_inc(&oprofile_stats.event_lost_overflow);
36802 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36803 return;
36804 }
36805
36806 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36807 index ed2c3ec..deda85a 100644
36808 --- a/drivers/oprofile/oprof.c
36809 +++ b/drivers/oprofile/oprof.c
36810 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36811 if (oprofile_ops.switch_events())
36812 return;
36813
36814 - atomic_inc(&oprofile_stats.multiplex_counter);
36815 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36816 start_switch_worker();
36817 }
36818
36819 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
36820 index 84a208d..f07d177 100644
36821 --- a/drivers/oprofile/oprofile_files.c
36822 +++ b/drivers/oprofile/oprofile_files.c
36823 @@ -36,6 +36,8 @@ static ssize_t timeout_read(struct file *file, char __user *buf,
36824
36825
36826 static ssize_t timeout_write(struct file *file, char const __user *buf,
36827 + size_t count, loff_t *offset) __size_overflow(3);
36828 +static ssize_t timeout_write(struct file *file, char const __user *buf,
36829 size_t count, loff_t *offset)
36830 {
36831 unsigned long val;
36832 @@ -72,6 +74,7 @@ static ssize_t depth_read(struct file *file, char __user *buf, size_t count, lof
36833 }
36834
36835
36836 +static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
36837 static ssize_t depth_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
36838 {
36839 unsigned long val;
36840 @@ -126,12 +129,14 @@ static const struct file_operations cpu_type_fops = {
36841 };
36842
36843
36844 +static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset) __size_overflow(3);
36845 static ssize_t enable_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
36846 {
36847 return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
36848 }
36849
36850
36851 +static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
36852 static ssize_t enable_write(struct file *file, char const __user *buf, size_t count, loff_t *offset)
36853 {
36854 unsigned long val;
36855 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36856 index 917d28e..d62d981 100644
36857 --- a/drivers/oprofile/oprofile_stats.c
36858 +++ b/drivers/oprofile/oprofile_stats.c
36859 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36860 cpu_buf->sample_invalid_eip = 0;
36861 }
36862
36863 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36864 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36865 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36866 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36867 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36868 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36869 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36870 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36871 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36872 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36873 }
36874
36875
36876 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36877 index 38b6fc0..b5cbfce 100644
36878 --- a/drivers/oprofile/oprofile_stats.h
36879 +++ b/drivers/oprofile/oprofile_stats.h
36880 @@ -13,11 +13,11 @@
36881 #include <linux/atomic.h>
36882
36883 struct oprofile_stat_struct {
36884 - atomic_t sample_lost_no_mm;
36885 - atomic_t sample_lost_no_mapping;
36886 - atomic_t bt_lost_no_mapping;
36887 - atomic_t event_lost_overflow;
36888 - atomic_t multiplex_counter;
36889 + atomic_unchecked_t sample_lost_no_mm;
36890 + atomic_unchecked_t sample_lost_no_mapping;
36891 + atomic_unchecked_t bt_lost_no_mapping;
36892 + atomic_unchecked_t event_lost_overflow;
36893 + atomic_unchecked_t multiplex_counter;
36894 };
36895
36896 extern struct oprofile_stat_struct oprofile_stats;
36897 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36898 index 2f0aa0f..d5246c3 100644
36899 --- a/drivers/oprofile/oprofilefs.c
36900 +++ b/drivers/oprofile/oprofilefs.c
36901 @@ -97,6 +97,7 @@ static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count
36902 }
36903
36904
36905 +static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset) __size_overflow(3);
36906 static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
36907 {
36908 unsigned long value;
36909 @@ -193,7 +194,7 @@ static const struct file_operations atomic_ro_fops = {
36910
36911
36912 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36913 - char const *name, atomic_t *val)
36914 + char const *name, atomic_unchecked_t *val)
36915 {
36916 return __oprofilefs_create_file(sb, root, name,
36917 &atomic_ro_fops, 0444, val);
36918 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36919 index 3f56bc0..707d642 100644
36920 --- a/drivers/parport/procfs.c
36921 +++ b/drivers/parport/procfs.c
36922 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36923
36924 *ppos += len;
36925
36926 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36927 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36928 }
36929
36930 #ifdef CONFIG_PARPORT_1284
36931 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36932
36933 *ppos += len;
36934
36935 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36936 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36937 }
36938 #endif /* IEEE1284.3 support. */
36939
36940 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36941 index 9fff878..ad0ad53 100644
36942 --- a/drivers/pci/hotplug/cpci_hotplug.h
36943 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36944 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36945 int (*hardware_test) (struct slot* slot, u32 value);
36946 u8 (*get_power) (struct slot* slot);
36947 int (*set_power) (struct slot* slot, int value);
36948 -};
36949 +} __no_const;
36950
36951 struct cpci_hp_controller {
36952 unsigned int irq;
36953 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36954 index 76ba8a1..20ca857 100644
36955 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36956 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36957 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36958
36959 void compaq_nvram_init (void __iomem *rom_start)
36960 {
36961 +
36962 +#ifndef CONFIG_PAX_KERNEXEC
36963 if (rom_start) {
36964 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36965 }
36966 +#endif
36967 +
36968 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36969
36970 /* initialize our int15 lock */
36971 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36972 index 2275162..95f1a92 100644
36973 --- a/drivers/pci/pcie/aspm.c
36974 +++ b/drivers/pci/pcie/aspm.c
36975 @@ -27,9 +27,9 @@
36976 #define MODULE_PARAM_PREFIX "pcie_aspm."
36977
36978 /* Note: those are not register definitions */
36979 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36980 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36981 -#define ASPM_STATE_L1 (4) /* L1 state */
36982 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36983 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36984 +#define ASPM_STATE_L1 (4U) /* L1 state */
36985 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36986 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36987
36988 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36989 index 71eac9c..2de27ef 100644
36990 --- a/drivers/pci/probe.c
36991 +++ b/drivers/pci/probe.c
36992 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36993 u32 l, sz, mask;
36994 u16 orig_cmd;
36995
36996 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36997 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36998
36999 if (!dev->mmio_always_on) {
37000 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
37001 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37002 index 27911b5..5b6db88 100644
37003 --- a/drivers/pci/proc.c
37004 +++ b/drivers/pci/proc.c
37005 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37006 static int __init pci_proc_init(void)
37007 {
37008 struct pci_dev *dev = NULL;
37009 +
37010 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
37011 +#ifdef CONFIG_GRKERNSEC_PROC_USER
37012 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37013 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37014 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37015 +#endif
37016 +#else
37017 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37018 +#endif
37019 proc_create("devices", 0, proc_bus_pci_dir,
37020 &proc_bus_pci_dev_operations);
37021 proc_initialized = 1;
37022 diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
37023 index 6f966d6..68e18ed 100644
37024 --- a/drivers/platform/x86/asus_acpi.c
37025 +++ b/drivers/platform/x86/asus_acpi.c
37026 @@ -887,6 +887,8 @@ static int lcd_proc_open(struct inode *inode, struct file *file)
37027 }
37028
37029 static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
37030 + size_t count, loff_t *pos) __size_overflow(3);
37031 +static ssize_t lcd_proc_write(struct file *file, const char __user *buffer,
37032 size_t count, loff_t *pos)
37033 {
37034 int rv, value;
37035 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37036 index ea0c607..58c4628 100644
37037 --- a/drivers/platform/x86/thinkpad_acpi.c
37038 +++ b/drivers/platform/x86/thinkpad_acpi.c
37039 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
37040 return 0;
37041 }
37042
37043 -void static hotkey_mask_warn_incomplete_mask(void)
37044 +static void hotkey_mask_warn_incomplete_mask(void)
37045 {
37046 /* log only what the user can fix... */
37047 const u32 wantedmask = hotkey_driver_mask &
37048 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37049 }
37050 }
37051
37052 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37053 - struct tp_nvram_state *newn,
37054 - const u32 event_mask)
37055 -{
37056 -
37057 #define TPACPI_COMPARE_KEY(__scancode, __member) \
37058 do { \
37059 if ((event_mask & (1 << __scancode)) && \
37060 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37061 tpacpi_hotkey_send_key(__scancode); \
37062 } while (0)
37063
37064 - void issue_volchange(const unsigned int oldvol,
37065 - const unsigned int newvol)
37066 - {
37067 - unsigned int i = oldvol;
37068 +static void issue_volchange(const unsigned int oldvol,
37069 + const unsigned int newvol,
37070 + const u32 event_mask)
37071 +{
37072 + unsigned int i = oldvol;
37073
37074 - while (i > newvol) {
37075 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37076 - i--;
37077 - }
37078 - while (i < newvol) {
37079 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37080 - i++;
37081 - }
37082 + while (i > newvol) {
37083 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37084 + i--;
37085 }
37086 + while (i < newvol) {
37087 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37088 + i++;
37089 + }
37090 +}
37091
37092 - void issue_brightnesschange(const unsigned int oldbrt,
37093 - const unsigned int newbrt)
37094 - {
37095 - unsigned int i = oldbrt;
37096 +static void issue_brightnesschange(const unsigned int oldbrt,
37097 + const unsigned int newbrt,
37098 + const u32 event_mask)
37099 +{
37100 + unsigned int i = oldbrt;
37101
37102 - while (i > newbrt) {
37103 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37104 - i--;
37105 - }
37106 - while (i < newbrt) {
37107 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37108 - i++;
37109 - }
37110 + while (i > newbrt) {
37111 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37112 + i--;
37113 + }
37114 + while (i < newbrt) {
37115 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37116 + i++;
37117 }
37118 +}
37119
37120 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37121 + struct tp_nvram_state *newn,
37122 + const u32 event_mask)
37123 +{
37124 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
37125 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
37126 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
37127 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37128 oldn->volume_level != newn->volume_level) {
37129 /* recently muted, or repeated mute keypress, or
37130 * multiple presses ending in mute */
37131 - issue_volchange(oldn->volume_level, newn->volume_level);
37132 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37133 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
37134 }
37135 } else {
37136 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37137 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37138 }
37139 if (oldn->volume_level != newn->volume_level) {
37140 - issue_volchange(oldn->volume_level, newn->volume_level);
37141 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37142 } else if (oldn->volume_toggle != newn->volume_toggle) {
37143 /* repeated vol up/down keypress at end of scale ? */
37144 if (newn->volume_level == 0)
37145 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37146 /* handle brightness */
37147 if (oldn->brightness_level != newn->brightness_level) {
37148 issue_brightnesschange(oldn->brightness_level,
37149 - newn->brightness_level);
37150 + newn->brightness_level,
37151 + event_mask);
37152 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
37153 /* repeated key presses that didn't change state */
37154 if (newn->brightness_level == 0)
37155 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37156 && !tp_features.bright_unkfw)
37157 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37158 }
37159 +}
37160
37161 #undef TPACPI_COMPARE_KEY
37162 #undef TPACPI_MAY_SEND_KEY
37163 -}
37164
37165 /*
37166 * Polling driver
37167 diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
37168 index dcdc1f4..85cee16 100644
37169 --- a/drivers/platform/x86/toshiba_acpi.c
37170 +++ b/drivers/platform/x86/toshiba_acpi.c
37171 @@ -517,6 +517,8 @@ static int set_lcd_status(struct backlight_device *bd)
37172 }
37173
37174 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
37175 + size_t count, loff_t *pos) __size_overflow(3);
37176 +static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
37177 size_t count, loff_t *pos)
37178 {
37179 struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
37180 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
37181 index b859d16..5cc6b1a 100644
37182 --- a/drivers/pnp/pnpbios/bioscalls.c
37183 +++ b/drivers/pnp/pnpbios/bioscalls.c
37184 @@ -59,7 +59,7 @@ do { \
37185 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37186 } while(0)
37187
37188 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37189 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37190 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37191
37192 /*
37193 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37194
37195 cpu = get_cpu();
37196 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37197 +
37198 + pax_open_kernel();
37199 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37200 + pax_close_kernel();
37201
37202 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37203 spin_lock_irqsave(&pnp_bios_lock, flags);
37204 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37205 :"memory");
37206 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37207
37208 + pax_open_kernel();
37209 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37210 + pax_close_kernel();
37211 +
37212 put_cpu();
37213
37214 /* If we get here and this is set then the PnP BIOS faulted on us. */
37215 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
37216 return status;
37217 }
37218
37219 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
37220 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37221 {
37222 int i;
37223
37224 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37225 pnp_bios_callpoint.offset = header->fields.pm16offset;
37226 pnp_bios_callpoint.segment = PNP_CS16;
37227
37228 + pax_open_kernel();
37229 +
37230 for_each_possible_cpu(i) {
37231 struct desc_struct *gdt = get_cpu_gdt_table(i);
37232 if (!gdt)
37233 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37234 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37235 (unsigned long)__va(header->fields.pm16dseg));
37236 }
37237 +
37238 + pax_close_kernel();
37239 }
37240 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
37241 index b0ecacb..7c9da2e 100644
37242 --- a/drivers/pnp/resource.c
37243 +++ b/drivers/pnp/resource.c
37244 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
37245 return 1;
37246
37247 /* check if the resource is valid */
37248 - if (*irq < 0 || *irq > 15)
37249 + if (*irq > 15)
37250 return 0;
37251
37252 /* check if the resource is reserved */
37253 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
37254 return 1;
37255
37256 /* check if the resource is valid */
37257 - if (*dma < 0 || *dma == 4 || *dma > 7)
37258 + if (*dma == 4 || *dma > 7)
37259 return 0;
37260
37261 /* check if the resource is reserved */
37262 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
37263 index 1ed6ea0..77c0bd2 100644
37264 --- a/drivers/power/bq27x00_battery.c
37265 +++ b/drivers/power/bq27x00_battery.c
37266 @@ -72,7 +72,7 @@
37267 struct bq27x00_device_info;
37268 struct bq27x00_access_methods {
37269 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
37270 -};
37271 +} __no_const;
37272
37273 enum bq27x00_chip { BQ27000, BQ27500 };
37274
37275 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
37276 index a838e66..a9e1665 100644
37277 --- a/drivers/regulator/max8660.c
37278 +++ b/drivers/regulator/max8660.c
37279 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
37280 max8660->shadow_regs[MAX8660_OVER1] = 5;
37281 } else {
37282 /* Otherwise devices can be toggled via software */
37283 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
37284 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
37285 + pax_open_kernel();
37286 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
37287 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
37288 + pax_close_kernel();
37289 }
37290
37291 /*
37292 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
37293 index e8cfc99..072aee2 100644
37294 --- a/drivers/regulator/mc13892-regulator.c
37295 +++ b/drivers/regulator/mc13892-regulator.c
37296 @@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
37297 }
37298 mc13xxx_unlock(mc13892);
37299
37300 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37301 + pax_open_kernel();
37302 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37303 = mc13892_vcam_set_mode;
37304 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37305 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37306 = mc13892_vcam_get_mode;
37307 + pax_close_kernel();
37308
37309 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
37310 ARRAY_SIZE(mc13892_regulators));
37311 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
37312 index cace6d3..f623fda 100644
37313 --- a/drivers/rtc/rtc-dev.c
37314 +++ b/drivers/rtc/rtc-dev.c
37315 @@ -14,6 +14,7 @@
37316 #include <linux/module.h>
37317 #include <linux/rtc.h>
37318 #include <linux/sched.h>
37319 +#include <linux/grsecurity.h>
37320 #include "rtc-core.h"
37321
37322 static dev_t rtc_devt;
37323 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
37324 if (copy_from_user(&tm, uarg, sizeof(tm)))
37325 return -EFAULT;
37326
37327 + gr_log_timechange();
37328 +
37329 return rtc_set_time(rtc, &tm);
37330
37331 case RTC_PIE_ON:
37332 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
37333 index ffb5878..e6d785c 100644
37334 --- a/drivers/scsi/aacraid/aacraid.h
37335 +++ b/drivers/scsi/aacraid/aacraid.h
37336 @@ -492,7 +492,7 @@ struct adapter_ops
37337 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
37338 /* Administrative operations */
37339 int (*adapter_comm)(struct aac_dev * dev, int comm);
37340 -};
37341 +} __no_const;
37342
37343 /*
37344 * Define which interrupt handler needs to be installed
37345 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
37346 index 705e13e..91c873c 100644
37347 --- a/drivers/scsi/aacraid/linit.c
37348 +++ b/drivers/scsi/aacraid/linit.c
37349 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
37350 #elif defined(__devinitconst)
37351 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
37352 #else
37353 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
37354 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
37355 #endif
37356 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
37357 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
37358 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
37359 index d5ff142..49c0ebb 100644
37360 --- a/drivers/scsi/aic94xx/aic94xx_init.c
37361 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
37362 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
37363 .lldd_control_phy = asd_control_phy,
37364 };
37365
37366 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
37367 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
37368 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
37369 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
37370 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
37371 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
37372 index a796de9..1ef20e1 100644
37373 --- a/drivers/scsi/bfa/bfa.h
37374 +++ b/drivers/scsi/bfa/bfa.h
37375 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
37376 u32 *end);
37377 int cpe_vec_q0;
37378 int rme_vec_q0;
37379 -};
37380 +} __no_const;
37381 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
37382
37383 struct bfa_faa_cbfn_s {
37384 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
37385 index f0f80e2..8ec946b 100644
37386 --- a/drivers/scsi/bfa/bfa_fcpim.c
37387 +++ b/drivers/scsi/bfa/bfa_fcpim.c
37388 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
37389
37390 bfa_iotag_attach(fcp);
37391
37392 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
37393 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
37394 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
37395 (fcp->num_itns * sizeof(struct bfa_itn_s));
37396 memset(fcp->itn_arr, 0,
37397 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
37398 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
37399 {
37400 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
37401 - struct bfa_itn_s *itn;
37402 + bfa_itn_s_no_const *itn;
37403
37404 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
37405 itn->isr = isr;
37406 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
37407 index 36f26da..38a34a8 100644
37408 --- a/drivers/scsi/bfa/bfa_fcpim.h
37409 +++ b/drivers/scsi/bfa/bfa_fcpim.h
37410 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
37411 struct bfa_itn_s {
37412 bfa_isr_func_t isr;
37413 };
37414 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
37415
37416 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
37417 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
37418 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
37419 struct list_head iotag_tio_free_q; /* free IO resources */
37420 struct list_head iotag_unused_q; /* unused IO resources*/
37421 struct bfa_iotag_s *iotag_arr;
37422 - struct bfa_itn_s *itn_arr;
37423 + bfa_itn_s_no_const *itn_arr;
37424 int num_ioim_reqs;
37425 int num_fwtio_reqs;
37426 int num_itns;
37427 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
37428 index 546d46b..642fa5b 100644
37429 --- a/drivers/scsi/bfa/bfa_ioc.h
37430 +++ b/drivers/scsi/bfa/bfa_ioc.h
37431 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
37432 bfa_ioc_disable_cbfn_t disable_cbfn;
37433 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
37434 bfa_ioc_reset_cbfn_t reset_cbfn;
37435 -};
37436 +} __no_const;
37437
37438 /*
37439 * IOC event notification mechanism.
37440 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
37441 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
37442 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
37443 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
37444 -};
37445 +} __no_const;
37446
37447 /*
37448 * Queue element to wait for room in request queue. FIFO order is
37449 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
37450 index 351dc0b..951dc32 100644
37451 --- a/drivers/scsi/hosts.c
37452 +++ b/drivers/scsi/hosts.c
37453 @@ -42,7 +42,7 @@
37454 #include "scsi_logging.h"
37455
37456
37457 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
37458 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
37459
37460
37461 static void scsi_host_cls_release(struct device *dev)
37462 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
37463 * subtract one because we increment first then return, but we need to
37464 * know what the next host number was before increment
37465 */
37466 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
37467 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
37468 shost->dma_channel = 0xff;
37469
37470 /* These three are default values which can be overridden */
37471 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
37472 index b96962c..0c82ec2 100644
37473 --- a/drivers/scsi/hpsa.c
37474 +++ b/drivers/scsi/hpsa.c
37475 @@ -507,7 +507,7 @@ static inline u32 next_command(struct ctlr_info *h)
37476 u32 a;
37477
37478 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37479 - return h->access.command_completed(h);
37480 + return h->access->command_completed(h);
37481
37482 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37483 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37484 @@ -2991,7 +2991,7 @@ static void start_io(struct ctlr_info *h)
37485 while (!list_empty(&h->reqQ)) {
37486 c = list_entry(h->reqQ.next, struct CommandList, list);
37487 /* can't do anything if fifo is full */
37488 - if ((h->access.fifo_full(h))) {
37489 + if ((h->access->fifo_full(h))) {
37490 dev_warn(&h->pdev->dev, "fifo full\n");
37491 break;
37492 }
37493 @@ -3001,7 +3001,7 @@ static void start_io(struct ctlr_info *h)
37494 h->Qdepth--;
37495
37496 /* Tell the controller execute command */
37497 - h->access.submit_command(h, c);
37498 + h->access->submit_command(h, c);
37499
37500 /* Put job onto the completed Q */
37501 addQ(&h->cmpQ, c);
37502 @@ -3010,17 +3010,17 @@ static void start_io(struct ctlr_info *h)
37503
37504 static inline unsigned long get_next_completion(struct ctlr_info *h)
37505 {
37506 - return h->access.command_completed(h);
37507 + return h->access->command_completed(h);
37508 }
37509
37510 static inline bool interrupt_pending(struct ctlr_info *h)
37511 {
37512 - return h->access.intr_pending(h);
37513 + return h->access->intr_pending(h);
37514 }
37515
37516 static inline long interrupt_not_for_us(struct ctlr_info *h)
37517 {
37518 - return (h->access.intr_pending(h) == 0) ||
37519 + return (h->access->intr_pending(h) == 0) ||
37520 (h->interrupts_enabled == 0);
37521 }
37522
37523 @@ -3919,7 +3919,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
37524 if (prod_index < 0)
37525 return -ENODEV;
37526 h->product_name = products[prod_index].product_name;
37527 - h->access = *(products[prod_index].access);
37528 + h->access = products[prod_index].access;
37529
37530 if (hpsa_board_disabled(h->pdev)) {
37531 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37532 @@ -4164,7 +4164,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
37533
37534 assert_spin_locked(&lockup_detector_lock);
37535 remove_ctlr_from_lockup_detector_list(h);
37536 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37537 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37538 spin_lock_irqsave(&h->lock, flags);
37539 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
37540 spin_unlock_irqrestore(&h->lock, flags);
37541 @@ -4344,7 +4344,7 @@ reinit_after_soft_reset:
37542 }
37543
37544 /* make sure the board interrupts are off */
37545 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37546 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37547
37548 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
37549 goto clean2;
37550 @@ -4378,7 +4378,7 @@ reinit_after_soft_reset:
37551 * fake ones to scoop up any residual completions.
37552 */
37553 spin_lock_irqsave(&h->lock, flags);
37554 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37555 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37556 spin_unlock_irqrestore(&h->lock, flags);
37557 free_irq(h->intr[h->intr_mode], h);
37558 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
37559 @@ -4397,9 +4397,9 @@ reinit_after_soft_reset:
37560 dev_info(&h->pdev->dev, "Board READY.\n");
37561 dev_info(&h->pdev->dev,
37562 "Waiting for stale completions to drain.\n");
37563 - h->access.set_intr_mask(h, HPSA_INTR_ON);
37564 + h->access->set_intr_mask(h, HPSA_INTR_ON);
37565 msleep(10000);
37566 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37567 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37568
37569 rc = controller_reset_failed(h->cfgtable);
37570 if (rc)
37571 @@ -4420,7 +4420,7 @@ reinit_after_soft_reset:
37572 }
37573
37574 /* Turn the interrupts on so we can service requests */
37575 - h->access.set_intr_mask(h, HPSA_INTR_ON);
37576 + h->access->set_intr_mask(h, HPSA_INTR_ON);
37577
37578 hpsa_hba_inquiry(h);
37579 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
37580 @@ -4472,7 +4472,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
37581 * To write all data in the battery backed cache to disks
37582 */
37583 hpsa_flush_cache(h);
37584 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
37585 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
37586 free_irq(h->intr[h->intr_mode], h);
37587 #ifdef CONFIG_PCI_MSI
37588 if (h->msix_vector)
37589 @@ -4636,7 +4636,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
37590 return;
37591 }
37592 /* Change the access methods to the performant access methods */
37593 - h->access = SA5_performant_access;
37594 + h->access = &SA5_performant_access;
37595 h->transMethod = CFGTBL_Trans_Performant;
37596 }
37597
37598 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
37599 index 91edafb..a9b88ec 100644
37600 --- a/drivers/scsi/hpsa.h
37601 +++ b/drivers/scsi/hpsa.h
37602 @@ -73,7 +73,7 @@ struct ctlr_info {
37603 unsigned int msix_vector;
37604 unsigned int msi_vector;
37605 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
37606 - struct access_method access;
37607 + struct access_method *access;
37608
37609 /* queue and queue Info */
37610 struct list_head reqQ;
37611 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
37612 index f2df059..a3a9930 100644
37613 --- a/drivers/scsi/ips.h
37614 +++ b/drivers/scsi/ips.h
37615 @@ -1027,7 +1027,7 @@ typedef struct {
37616 int (*intr)(struct ips_ha *);
37617 void (*enableint)(struct ips_ha *);
37618 uint32_t (*statupd)(struct ips_ha *);
37619 -} ips_hw_func_t;
37620 +} __no_const ips_hw_func_t;
37621
37622 typedef struct ips_ha {
37623 uint8_t ha_id[IPS_MAX_CHANNELS+1];
37624 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
37625 index 4d70d96..84d0573 100644
37626 --- a/drivers/scsi/libfc/fc_exch.c
37627 +++ b/drivers/scsi/libfc/fc_exch.c
37628 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
37629 * all together if not used XXX
37630 */
37631 struct {
37632 - atomic_t no_free_exch;
37633 - atomic_t no_free_exch_xid;
37634 - atomic_t xid_not_found;
37635 - atomic_t xid_busy;
37636 - atomic_t seq_not_found;
37637 - atomic_t non_bls_resp;
37638 + atomic_unchecked_t no_free_exch;
37639 + atomic_unchecked_t no_free_exch_xid;
37640 + atomic_unchecked_t xid_not_found;
37641 + atomic_unchecked_t xid_busy;
37642 + atomic_unchecked_t seq_not_found;
37643 + atomic_unchecked_t non_bls_resp;
37644 } stats;
37645 };
37646
37647 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
37648 /* allocate memory for exchange */
37649 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
37650 if (!ep) {
37651 - atomic_inc(&mp->stats.no_free_exch);
37652 + atomic_inc_unchecked(&mp->stats.no_free_exch);
37653 goto out;
37654 }
37655 memset(ep, 0, sizeof(*ep));
37656 @@ -780,7 +780,7 @@ out:
37657 return ep;
37658 err:
37659 spin_unlock_bh(&pool->lock);
37660 - atomic_inc(&mp->stats.no_free_exch_xid);
37661 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
37662 mempool_free(ep, mp->ep_pool);
37663 return NULL;
37664 }
37665 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37666 xid = ntohs(fh->fh_ox_id); /* we originated exch */
37667 ep = fc_exch_find(mp, xid);
37668 if (!ep) {
37669 - atomic_inc(&mp->stats.xid_not_found);
37670 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37671 reject = FC_RJT_OX_ID;
37672 goto out;
37673 }
37674 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37675 ep = fc_exch_find(mp, xid);
37676 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37677 if (ep) {
37678 - atomic_inc(&mp->stats.xid_busy);
37679 + atomic_inc_unchecked(&mp->stats.xid_busy);
37680 reject = FC_RJT_RX_ID;
37681 goto rel;
37682 }
37683 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37684 }
37685 xid = ep->xid; /* get our XID */
37686 } else if (!ep) {
37687 - atomic_inc(&mp->stats.xid_not_found);
37688 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37689 reject = FC_RJT_RX_ID; /* XID not found */
37690 goto out;
37691 }
37692 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37693 } else {
37694 sp = &ep->seq;
37695 if (sp->id != fh->fh_seq_id) {
37696 - atomic_inc(&mp->stats.seq_not_found);
37697 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37698 if (f_ctl & FC_FC_END_SEQ) {
37699 /*
37700 * Update sequence_id based on incoming last
37701 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37702
37703 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37704 if (!ep) {
37705 - atomic_inc(&mp->stats.xid_not_found);
37706 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37707 goto out;
37708 }
37709 if (ep->esb_stat & ESB_ST_COMPLETE) {
37710 - atomic_inc(&mp->stats.xid_not_found);
37711 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37712 goto rel;
37713 }
37714 if (ep->rxid == FC_XID_UNKNOWN)
37715 ep->rxid = ntohs(fh->fh_rx_id);
37716 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37717 - atomic_inc(&mp->stats.xid_not_found);
37718 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37719 goto rel;
37720 }
37721 if (ep->did != ntoh24(fh->fh_s_id) &&
37722 ep->did != FC_FID_FLOGI) {
37723 - atomic_inc(&mp->stats.xid_not_found);
37724 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37725 goto rel;
37726 }
37727 sof = fr_sof(fp);
37728 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37729 sp->ssb_stat |= SSB_ST_RESP;
37730 sp->id = fh->fh_seq_id;
37731 } else if (sp->id != fh->fh_seq_id) {
37732 - atomic_inc(&mp->stats.seq_not_found);
37733 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37734 goto rel;
37735 }
37736
37737 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37738 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37739
37740 if (!sp)
37741 - atomic_inc(&mp->stats.xid_not_found);
37742 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37743 else
37744 - atomic_inc(&mp->stats.non_bls_resp);
37745 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37746
37747 fc_frame_free(fp);
37748 }
37749 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37750 index db9238f..4378ed2 100644
37751 --- a/drivers/scsi/libsas/sas_ata.c
37752 +++ b/drivers/scsi/libsas/sas_ata.c
37753 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
37754 .postreset = ata_std_postreset,
37755 .error_handler = ata_std_error_handler,
37756 .post_internal_cmd = sas_ata_post_internal,
37757 - .qc_defer = ata_std_qc_defer,
37758 + .qc_defer = ata_std_qc_defer,
37759 .qc_prep = ata_noop_qc_prep,
37760 .qc_issue = sas_ata_qc_issue,
37761 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37762 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37763 index 825f930..ce42672 100644
37764 --- a/drivers/scsi/lpfc/lpfc.h
37765 +++ b/drivers/scsi/lpfc/lpfc.h
37766 @@ -413,7 +413,7 @@ struct lpfc_vport {
37767 struct dentry *debug_nodelist;
37768 struct dentry *vport_debugfs_root;
37769 struct lpfc_debugfs_trc *disc_trc;
37770 - atomic_t disc_trc_cnt;
37771 + atomic_unchecked_t disc_trc_cnt;
37772 #endif
37773 uint8_t stat_data_enabled;
37774 uint8_t stat_data_blocked;
37775 @@ -821,8 +821,8 @@ struct lpfc_hba {
37776 struct timer_list fabric_block_timer;
37777 unsigned long bit_flags;
37778 #define FABRIC_COMANDS_BLOCKED 0
37779 - atomic_t num_rsrc_err;
37780 - atomic_t num_cmd_success;
37781 + atomic_unchecked_t num_rsrc_err;
37782 + atomic_unchecked_t num_cmd_success;
37783 unsigned long last_rsrc_error_time;
37784 unsigned long last_ramp_down_time;
37785 unsigned long last_ramp_up_time;
37786 @@ -852,7 +852,7 @@ struct lpfc_hba {
37787
37788 struct dentry *debug_slow_ring_trc;
37789 struct lpfc_debugfs_trc *slow_ring_trc;
37790 - atomic_t slow_ring_trc_cnt;
37791 + atomic_unchecked_t slow_ring_trc_cnt;
37792 /* iDiag debugfs sub-directory */
37793 struct dentry *idiag_root;
37794 struct dentry *idiag_pci_cfg;
37795 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37796 index 3587a3f..d45b81b 100644
37797 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37798 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37799 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37800
37801 #include <linux/debugfs.h>
37802
37803 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37804 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37805 static unsigned long lpfc_debugfs_start_time = 0L;
37806
37807 /* iDiag */
37808 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37809 lpfc_debugfs_enable = 0;
37810
37811 len = 0;
37812 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37813 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37814 (lpfc_debugfs_max_disc_trc - 1);
37815 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37816 dtp = vport->disc_trc + i;
37817 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37818 lpfc_debugfs_enable = 0;
37819
37820 len = 0;
37821 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37822 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37823 (lpfc_debugfs_max_slow_ring_trc - 1);
37824 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37825 dtp = phba->slow_ring_trc + i;
37826 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37827 !vport || !vport->disc_trc)
37828 return;
37829
37830 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37831 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37832 (lpfc_debugfs_max_disc_trc - 1);
37833 dtp = vport->disc_trc + index;
37834 dtp->fmt = fmt;
37835 dtp->data1 = data1;
37836 dtp->data2 = data2;
37837 dtp->data3 = data3;
37838 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37839 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37840 dtp->jif = jiffies;
37841 #endif
37842 return;
37843 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37844 !phba || !phba->slow_ring_trc)
37845 return;
37846
37847 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37848 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37849 (lpfc_debugfs_max_slow_ring_trc - 1);
37850 dtp = phba->slow_ring_trc + index;
37851 dtp->fmt = fmt;
37852 dtp->data1 = data1;
37853 dtp->data2 = data2;
37854 dtp->data3 = data3;
37855 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37856 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37857 dtp->jif = jiffies;
37858 #endif
37859 return;
37860 @@ -4040,7 +4040,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37861 "slow_ring buffer\n");
37862 goto debug_failed;
37863 }
37864 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37865 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37866 memset(phba->slow_ring_trc, 0,
37867 (sizeof(struct lpfc_debugfs_trc) *
37868 lpfc_debugfs_max_slow_ring_trc));
37869 @@ -4086,7 +4086,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37870 "buffer\n");
37871 goto debug_failed;
37872 }
37873 - atomic_set(&vport->disc_trc_cnt, 0);
37874 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37875
37876 snprintf(name, sizeof(name), "discovery_trace");
37877 vport->debug_disc_trc =
37878 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37879 index dfea2da..8e17227 100644
37880 --- a/drivers/scsi/lpfc/lpfc_init.c
37881 +++ b/drivers/scsi/lpfc/lpfc_init.c
37882 @@ -10145,8 +10145,10 @@ lpfc_init(void)
37883 printk(LPFC_COPYRIGHT "\n");
37884
37885 if (lpfc_enable_npiv) {
37886 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37887 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37888 + pax_open_kernel();
37889 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37890 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37891 + pax_close_kernel();
37892 }
37893 lpfc_transport_template =
37894 fc_attach_transport(&lpfc_transport_functions);
37895 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37896 index c60f5d0..751535c 100644
37897 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37898 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37899 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37900 uint32_t evt_posted;
37901
37902 spin_lock_irqsave(&phba->hbalock, flags);
37903 - atomic_inc(&phba->num_rsrc_err);
37904 + atomic_inc_unchecked(&phba->num_rsrc_err);
37905 phba->last_rsrc_error_time = jiffies;
37906
37907 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37908 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37909 unsigned long flags;
37910 struct lpfc_hba *phba = vport->phba;
37911 uint32_t evt_posted;
37912 - atomic_inc(&phba->num_cmd_success);
37913 + atomic_inc_unchecked(&phba->num_cmd_success);
37914
37915 if (vport->cfg_lun_queue_depth <= queue_depth)
37916 return;
37917 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37918 unsigned long num_rsrc_err, num_cmd_success;
37919 int i;
37920
37921 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37922 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37923 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37924 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37925
37926 vports = lpfc_create_vport_work_array(phba);
37927 if (vports != NULL)
37928 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37929 }
37930 }
37931 lpfc_destroy_vport_work_array(phba, vports);
37932 - atomic_set(&phba->num_rsrc_err, 0);
37933 - atomic_set(&phba->num_cmd_success, 0);
37934 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37935 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37936 }
37937
37938 /**
37939 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37940 }
37941 }
37942 lpfc_destroy_vport_work_array(phba, vports);
37943 - atomic_set(&phba->num_rsrc_err, 0);
37944 - atomic_set(&phba->num_cmd_success, 0);
37945 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37946 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37947 }
37948
37949 /**
37950 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37951 index ea8a0b4..812a124 100644
37952 --- a/drivers/scsi/pmcraid.c
37953 +++ b/drivers/scsi/pmcraid.c
37954 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37955 res->scsi_dev = scsi_dev;
37956 scsi_dev->hostdata = res;
37957 res->change_detected = 0;
37958 - atomic_set(&res->read_failures, 0);
37959 - atomic_set(&res->write_failures, 0);
37960 + atomic_set_unchecked(&res->read_failures, 0);
37961 + atomic_set_unchecked(&res->write_failures, 0);
37962 rc = 0;
37963 }
37964 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37965 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37966
37967 /* If this was a SCSI read/write command keep count of errors */
37968 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37969 - atomic_inc(&res->read_failures);
37970 + atomic_inc_unchecked(&res->read_failures);
37971 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37972 - atomic_inc(&res->write_failures);
37973 + atomic_inc_unchecked(&res->write_failures);
37974
37975 if (!RES_IS_GSCSI(res->cfg_entry) &&
37976 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37977 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37978 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37979 * hrrq_id assigned here in queuecommand
37980 */
37981 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37982 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37983 pinstance->num_hrrq;
37984 cmd->cmd_done = pmcraid_io_done;
37985
37986 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37987 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37988 * hrrq_id assigned here in queuecommand
37989 */
37990 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37991 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37992 pinstance->num_hrrq;
37993
37994 if (request_size) {
37995 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37996
37997 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37998 /* add resources only after host is added into system */
37999 - if (!atomic_read(&pinstance->expose_resources))
38000 + if (!atomic_read_unchecked(&pinstance->expose_resources))
38001 return;
38002
38003 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38004 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38005 init_waitqueue_head(&pinstance->reset_wait_q);
38006
38007 atomic_set(&pinstance->outstanding_cmds, 0);
38008 - atomic_set(&pinstance->last_message_id, 0);
38009 - atomic_set(&pinstance->expose_resources, 0);
38010 + atomic_set_unchecked(&pinstance->last_message_id, 0);
38011 + atomic_set_unchecked(&pinstance->expose_resources, 0);
38012
38013 INIT_LIST_HEAD(&pinstance->free_res_q);
38014 INIT_LIST_HEAD(&pinstance->used_res_q);
38015 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38016 /* Schedule worker thread to handle CCN and take care of adding and
38017 * removing devices to OS
38018 */
38019 - atomic_set(&pinstance->expose_resources, 1);
38020 + atomic_set_unchecked(&pinstance->expose_resources, 1);
38021 schedule_work(&pinstance->worker_q);
38022 return rc;
38023
38024 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38025 index ca496c7..9c791d5 100644
38026 --- a/drivers/scsi/pmcraid.h
38027 +++ b/drivers/scsi/pmcraid.h
38028 @@ -748,7 +748,7 @@ struct pmcraid_instance {
38029 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38030
38031 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38032 - atomic_t last_message_id;
38033 + atomic_unchecked_t last_message_id;
38034
38035 /* configuration table */
38036 struct pmcraid_config_table *cfg_table;
38037 @@ -777,7 +777,7 @@ struct pmcraid_instance {
38038 atomic_t outstanding_cmds;
38039
38040 /* should add/delete resources to mid-layer now ?*/
38041 - atomic_t expose_resources;
38042 + atomic_unchecked_t expose_resources;
38043
38044
38045
38046 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38047 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38048 };
38049 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38050 - atomic_t read_failures; /* count of failed READ commands */
38051 - atomic_t write_failures; /* count of failed WRITE commands */
38052 + atomic_unchecked_t read_failures; /* count of failed READ commands */
38053 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38054
38055 /* To indicate add/delete/modify during CCN */
38056 u8 change_detected;
38057 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
38058 index af1003f..be55a75 100644
38059 --- a/drivers/scsi/qla2xxx/qla_def.h
38060 +++ b/drivers/scsi/qla2xxx/qla_def.h
38061 @@ -2247,7 +2247,7 @@ struct isp_operations {
38062 int (*start_scsi) (srb_t *);
38063 int (*abort_isp) (struct scsi_qla_host *);
38064 int (*iospace_config)(struct qla_hw_data*);
38065 -};
38066 +} __no_const;
38067
38068 /* MSI-X Support *************************************************************/
38069
38070 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38071 index bfe6854..ceac088 100644
38072 --- a/drivers/scsi/qla4xxx/ql4_def.h
38073 +++ b/drivers/scsi/qla4xxx/ql4_def.h
38074 @@ -261,7 +261,7 @@ struct ddb_entry {
38075 * (4000 only) */
38076 atomic_t relogin_timer; /* Max Time to wait for
38077 * relogin to complete */
38078 - atomic_t relogin_retry_count; /* Num of times relogin has been
38079 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38080 * retried */
38081 uint32_t default_time2wait; /* Default Min time between
38082 * relogins (+aens) */
38083 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
38084 index ce6d3b7..73fac54 100644
38085 --- a/drivers/scsi/qla4xxx/ql4_os.c
38086 +++ b/drivers/scsi/qla4xxx/ql4_os.c
38087 @@ -2178,12 +2178,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
38088 */
38089 if (!iscsi_is_session_online(cls_sess)) {
38090 /* Reset retry relogin timer */
38091 - atomic_inc(&ddb_entry->relogin_retry_count);
38092 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38093 DEBUG2(ql4_printk(KERN_INFO, ha,
38094 "%s: index[%d] relogin timed out-retrying"
38095 " relogin (%d), retry (%d)\n", __func__,
38096 ddb_entry->fw_ddb_index,
38097 - atomic_read(&ddb_entry->relogin_retry_count),
38098 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
38099 ddb_entry->default_time2wait + 4));
38100 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
38101 atomic_set(&ddb_entry->retry_relogin_timer,
38102 @@ -3953,7 +3953,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
38103
38104 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38105 atomic_set(&ddb_entry->relogin_timer, 0);
38106 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38107 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38108 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
38109 ddb_entry->default_relogin_timeout =
38110 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
38111 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
38112 index 2aeb2e9..46e3925 100644
38113 --- a/drivers/scsi/scsi.c
38114 +++ b/drivers/scsi/scsi.c
38115 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
38116 unsigned long timeout;
38117 int rtn = 0;
38118
38119 - atomic_inc(&cmd->device->iorequest_cnt);
38120 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38121
38122 /* check if the device is still usable */
38123 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38124 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
38125 index b2c95db..227d74e 100644
38126 --- a/drivers/scsi/scsi_lib.c
38127 +++ b/drivers/scsi/scsi_lib.c
38128 @@ -1411,7 +1411,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
38129 shost = sdev->host;
38130 scsi_init_cmd_errh(cmd);
38131 cmd->result = DID_NO_CONNECT << 16;
38132 - atomic_inc(&cmd->device->iorequest_cnt);
38133 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38134
38135 /*
38136 * SCSI request completion path will do scsi_device_unbusy(),
38137 @@ -1437,9 +1437,9 @@ static void scsi_softirq_done(struct request *rq)
38138
38139 INIT_LIST_HEAD(&cmd->eh_entry);
38140
38141 - atomic_inc(&cmd->device->iodone_cnt);
38142 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
38143 if (cmd->result)
38144 - atomic_inc(&cmd->device->ioerr_cnt);
38145 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38146
38147 disposition = scsi_decide_disposition(cmd);
38148 if (disposition != SUCCESS &&
38149 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
38150 index 04c2a27..9d8bd66 100644
38151 --- a/drivers/scsi/scsi_sysfs.c
38152 +++ b/drivers/scsi/scsi_sysfs.c
38153 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
38154 char *buf) \
38155 { \
38156 struct scsi_device *sdev = to_scsi_device(dev); \
38157 - unsigned long long count = atomic_read(&sdev->field); \
38158 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
38159 return snprintf(buf, 20, "0x%llx\n", count); \
38160 } \
38161 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
38162 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
38163 index 84a1fdf..693b0d6 100644
38164 --- a/drivers/scsi/scsi_tgt_lib.c
38165 +++ b/drivers/scsi/scsi_tgt_lib.c
38166 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
38167 int err;
38168
38169 dprintk("%lx %u\n", uaddr, len);
38170 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
38171 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
38172 if (err) {
38173 /*
38174 * TODO: need to fixup sg_tablesize, max_segment_size,
38175 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
38176 index f59d4a0..1d89407 100644
38177 --- a/drivers/scsi/scsi_transport_fc.c
38178 +++ b/drivers/scsi/scsi_transport_fc.c
38179 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
38180 * Netlink Infrastructure
38181 */
38182
38183 -static atomic_t fc_event_seq;
38184 +static atomic_unchecked_t fc_event_seq;
38185
38186 /**
38187 * fc_get_event_number - Obtain the next sequential FC event number
38188 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
38189 u32
38190 fc_get_event_number(void)
38191 {
38192 - return atomic_add_return(1, &fc_event_seq);
38193 + return atomic_add_return_unchecked(1, &fc_event_seq);
38194 }
38195 EXPORT_SYMBOL(fc_get_event_number);
38196
38197 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
38198 {
38199 int error;
38200
38201 - atomic_set(&fc_event_seq, 0);
38202 + atomic_set_unchecked(&fc_event_seq, 0);
38203
38204 error = transport_class_register(&fc_host_class);
38205 if (error)
38206 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
38207 char *cp;
38208
38209 *val = simple_strtoul(buf, &cp, 0);
38210 - if ((*cp && (*cp != '\n')) || (*val < 0))
38211 + if (*cp && (*cp != '\n'))
38212 return -EINVAL;
38213 /*
38214 * Check for overflow; dev_loss_tmo is u32
38215 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
38216 index e3e3c7d..ebdab62 100644
38217 --- a/drivers/scsi/scsi_transport_iscsi.c
38218 +++ b/drivers/scsi/scsi_transport_iscsi.c
38219 @@ -79,7 +79,7 @@ struct iscsi_internal {
38220 struct transport_container session_cont;
38221 };
38222
38223 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
38224 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
38225 static struct workqueue_struct *iscsi_eh_timer_workq;
38226
38227 static DEFINE_IDA(iscsi_sess_ida);
38228 @@ -1063,7 +1063,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
38229 int err;
38230
38231 ihost = shost->shost_data;
38232 - session->sid = atomic_add_return(1, &iscsi_session_nr);
38233 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
38234
38235 if (target_id == ISCSI_MAX_TARGET) {
38236 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
38237 @@ -2680,7 +2680,7 @@ static __init int iscsi_transport_init(void)
38238 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
38239 ISCSI_TRANSPORT_VERSION);
38240
38241 - atomic_set(&iscsi_session_nr, 0);
38242 + atomic_set_unchecked(&iscsi_session_nr, 0);
38243
38244 err = class_register(&iscsi_transport_class);
38245 if (err)
38246 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
38247 index 21a045e..ec89e03 100644
38248 --- a/drivers/scsi/scsi_transport_srp.c
38249 +++ b/drivers/scsi/scsi_transport_srp.c
38250 @@ -33,7 +33,7 @@
38251 #include "scsi_transport_srp_internal.h"
38252
38253 struct srp_host_attrs {
38254 - atomic_t next_port_id;
38255 + atomic_unchecked_t next_port_id;
38256 };
38257 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
38258
38259 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
38260 struct Scsi_Host *shost = dev_to_shost(dev);
38261 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
38262
38263 - atomic_set(&srp_host->next_port_id, 0);
38264 + atomic_set_unchecked(&srp_host->next_port_id, 0);
38265 return 0;
38266 }
38267
38268 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
38269 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
38270 rport->roles = ids->roles;
38271
38272 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
38273 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
38274 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
38275
38276 transport_setup_device(&rport->dev);
38277 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
38278 index eacd46b..e3f4d62 100644
38279 --- a/drivers/scsi/sg.c
38280 +++ b/drivers/scsi/sg.c
38281 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
38282 sdp->disk->disk_name,
38283 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
38284 NULL,
38285 - (char *)arg);
38286 + (char __user *)arg);
38287 case BLKTRACESTART:
38288 return blk_trace_startstop(sdp->device->request_queue, 1);
38289 case BLKTRACESTOP:
38290 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
38291 const struct file_operations * fops;
38292 };
38293
38294 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
38295 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
38296 {"allow_dio", &adio_fops},
38297 {"debug", &debug_fops},
38298 {"def_reserved_size", &dressz_fops},
38299 @@ -2332,7 +2332,7 @@ sg_proc_init(void)
38300 if (!sg_proc_sgp)
38301 return 1;
38302 for (k = 0; k < num_leaves; ++k) {
38303 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
38304 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
38305 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
38306 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
38307 }
38308 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
38309 index f64250e..1ee3049 100644
38310 --- a/drivers/spi/spi-dw-pci.c
38311 +++ b/drivers/spi/spi-dw-pci.c
38312 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
38313 #define spi_resume NULL
38314 #endif
38315
38316 -static const struct pci_device_id pci_ids[] __devinitdata = {
38317 +static const struct pci_device_id pci_ids[] __devinitconst = {
38318 /* Intel MID platform SPI controller 0 */
38319 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
38320 {},
38321 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
38322 index b2ccdea..84cde75 100644
38323 --- a/drivers/spi/spi.c
38324 +++ b/drivers/spi/spi.c
38325 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
38326 EXPORT_SYMBOL_GPL(spi_bus_unlock);
38327
38328 /* portable code must never pass more than 32 bytes */
38329 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
38330 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
38331
38332 static u8 *buf;
38333
38334 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
38335 index 400df8c..065d4f4 100644
38336 --- a/drivers/staging/octeon/ethernet-rx.c
38337 +++ b/drivers/staging/octeon/ethernet-rx.c
38338 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38339 /* Increment RX stats for virtual ports */
38340 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
38341 #ifdef CONFIG_64BIT
38342 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
38343 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
38344 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
38345 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
38346 #else
38347 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
38348 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
38349 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
38350 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
38351 #endif
38352 }
38353 netif_receive_skb(skb);
38354 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38355 dev->name);
38356 */
38357 #ifdef CONFIG_64BIT
38358 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
38359 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38360 #else
38361 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
38362 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
38363 #endif
38364 dev_kfree_skb_irq(skb);
38365 }
38366 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
38367 index 9112cd8..92f8d51 100644
38368 --- a/drivers/staging/octeon/ethernet.c
38369 +++ b/drivers/staging/octeon/ethernet.c
38370 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
38371 * since the RX tasklet also increments it.
38372 */
38373 #ifdef CONFIG_64BIT
38374 - atomic64_add(rx_status.dropped_packets,
38375 - (atomic64_t *)&priv->stats.rx_dropped);
38376 + atomic64_add_unchecked(rx_status.dropped_packets,
38377 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38378 #else
38379 - atomic_add(rx_status.dropped_packets,
38380 - (atomic_t *)&priv->stats.rx_dropped);
38381 + atomic_add_unchecked(rx_status.dropped_packets,
38382 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
38383 #endif
38384 }
38385
38386 diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
38387 index f9dae95..ff48901 100644
38388 --- a/drivers/staging/rtl8192e/rtllib_module.c
38389 +++ b/drivers/staging/rtl8192e/rtllib_module.c
38390 @@ -215,6 +215,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
38391 }
38392
38393 static int store_debug_level(struct file *file, const char __user *buffer,
38394 + unsigned long count, void *data) __size_overflow(3);
38395 +static int store_debug_level(struct file *file, const char __user *buffer,
38396 unsigned long count, void *data)
38397 {
38398 char buf[] = "0x00000000";
38399 diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
38400 index e3d47bc..85f4d0d 100644
38401 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
38402 +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
38403 @@ -250,6 +250,8 @@ static int show_debug_level(char *page, char **start, off_t offset,
38404 }
38405
38406 static int store_debug_level(struct file *file, const char *buffer,
38407 + unsigned long count, void *data) __size_overflow(3);
38408 +static int store_debug_level(struct file *file, const char *buffer,
38409 unsigned long count, void *data)
38410 {
38411 char buf[] = "0x00000000";
38412 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
38413 index 86308a0..feaa925 100644
38414 --- a/drivers/staging/rtl8712/rtl871x_io.h
38415 +++ b/drivers/staging/rtl8712/rtl871x_io.h
38416 @@ -108,7 +108,7 @@ struct _io_ops {
38417 u8 *pmem);
38418 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
38419 u8 *pmem);
38420 -};
38421 +} __no_const;
38422
38423 struct io_req {
38424 struct list_head list;
38425 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
38426 index c7b5e8b..783d6cb 100644
38427 --- a/drivers/staging/sbe-2t3e3/netdev.c
38428 +++ b/drivers/staging/sbe-2t3e3/netdev.c
38429 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38430 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
38431
38432 if (rlen)
38433 - if (copy_to_user(data, &resp, rlen))
38434 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
38435 return -EFAULT;
38436
38437 return 0;
38438 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
38439 index 42cdafe..2769103 100644
38440 --- a/drivers/staging/speakup/speakup_soft.c
38441 +++ b/drivers/staging/speakup/speakup_soft.c
38442 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
38443 break;
38444 } else if (!initialized) {
38445 if (*init) {
38446 - ch = *init;
38447 init++;
38448 } else {
38449 initialized = 1;
38450 }
38451 + ch = *init;
38452 } else {
38453 ch = synth_buffer_getc();
38454 }
38455 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
38456 index b8f8c48..1fc5025 100644
38457 --- a/drivers/staging/usbip/usbip_common.h
38458 +++ b/drivers/staging/usbip/usbip_common.h
38459 @@ -289,7 +289,7 @@ struct usbip_device {
38460 void (*shutdown)(struct usbip_device *);
38461 void (*reset)(struct usbip_device *);
38462 void (*unusable)(struct usbip_device *);
38463 - } eh_ops;
38464 + } __no_const eh_ops;
38465 };
38466
38467 /* usbip_common.c */
38468 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
38469 index 88b3298..3783eee 100644
38470 --- a/drivers/staging/usbip/vhci.h
38471 +++ b/drivers/staging/usbip/vhci.h
38472 @@ -88,7 +88,7 @@ struct vhci_hcd {
38473 unsigned resuming:1;
38474 unsigned long re_timeout;
38475
38476 - atomic_t seqnum;
38477 + atomic_unchecked_t seqnum;
38478
38479 /*
38480 * NOTE:
38481 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
38482 index 2ee97e2..0420b86 100644
38483 --- a/drivers/staging/usbip/vhci_hcd.c
38484 +++ b/drivers/staging/usbip/vhci_hcd.c
38485 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
38486 return;
38487 }
38488
38489 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
38490 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38491 if (priv->seqnum == 0xffff)
38492 dev_info(&urb->dev->dev, "seqnum max\n");
38493
38494 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
38495 return -ENOMEM;
38496 }
38497
38498 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
38499 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
38500 if (unlink->seqnum == 0xffff)
38501 pr_info("seqnum max\n");
38502
38503 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
38504 vdev->rhport = rhport;
38505 }
38506
38507 - atomic_set(&vhci->seqnum, 0);
38508 + atomic_set_unchecked(&vhci->seqnum, 0);
38509 spin_lock_init(&vhci->lock);
38510
38511 hcd->power_budget = 0; /* no limit */
38512 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
38513 index 3f511b4..d3dbc1e 100644
38514 --- a/drivers/staging/usbip/vhci_rx.c
38515 +++ b/drivers/staging/usbip/vhci_rx.c
38516 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
38517 if (!urb) {
38518 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
38519 pr_info("max seqnum %d\n",
38520 - atomic_read(&the_controller->seqnum));
38521 + atomic_read_unchecked(&the_controller->seqnum));
38522 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
38523 return;
38524 }
38525 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
38526 index 7735027..30eed13 100644
38527 --- a/drivers/staging/vt6655/hostap.c
38528 +++ b/drivers/staging/vt6655/hostap.c
38529 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
38530 *
38531 */
38532
38533 +static net_device_ops_no_const apdev_netdev_ops;
38534 +
38535 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38536 {
38537 PSDevice apdev_priv;
38538 struct net_device *dev = pDevice->dev;
38539 int ret;
38540 - const struct net_device_ops apdev_netdev_ops = {
38541 - .ndo_start_xmit = pDevice->tx_80211,
38542 - };
38543
38544 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38545
38546 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38547 *apdev_priv = *pDevice;
38548 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38549
38550 + /* only half broken now */
38551 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38552 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38553
38554 pDevice->apdev->type = ARPHRD_IEEE80211;
38555 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
38556 index 51b5adf..098e320 100644
38557 --- a/drivers/staging/vt6656/hostap.c
38558 +++ b/drivers/staging/vt6656/hostap.c
38559 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
38560 *
38561 */
38562
38563 +static net_device_ops_no_const apdev_netdev_ops;
38564 +
38565 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38566 {
38567 PSDevice apdev_priv;
38568 struct net_device *dev = pDevice->dev;
38569 int ret;
38570 - const struct net_device_ops apdev_netdev_ops = {
38571 - .ndo_start_xmit = pDevice->tx_80211,
38572 - };
38573
38574 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
38575
38576 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
38577 *apdev_priv = *pDevice;
38578 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
38579
38580 + /* only half broken now */
38581 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
38582 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
38583
38584 pDevice->apdev->type = ARPHRD_IEEE80211;
38585 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
38586 index 7843dfd..3db105f 100644
38587 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
38588 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
38589 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
38590
38591 struct usbctlx_completor {
38592 int (*complete) (struct usbctlx_completor *);
38593 -};
38594 +} __no_const;
38595
38596 static int
38597 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
38598 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
38599 index 1ca66ea..76f1343 100644
38600 --- a/drivers/staging/zcache/tmem.c
38601 +++ b/drivers/staging/zcache/tmem.c
38602 @@ -39,7 +39,7 @@
38603 * A tmem host implementation must use this function to register callbacks
38604 * for memory allocation.
38605 */
38606 -static struct tmem_hostops tmem_hostops;
38607 +static tmem_hostops_no_const tmem_hostops;
38608
38609 static void tmem_objnode_tree_init(void);
38610
38611 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
38612 * A tmem host implementation must use this function to register
38613 * callbacks for a page-accessible memory (PAM) implementation
38614 */
38615 -static struct tmem_pamops tmem_pamops;
38616 +static tmem_pamops_no_const tmem_pamops;
38617
38618 void tmem_register_pamops(struct tmem_pamops *m)
38619 {
38620 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
38621 index ed147c4..94fc3c6 100644
38622 --- a/drivers/staging/zcache/tmem.h
38623 +++ b/drivers/staging/zcache/tmem.h
38624 @@ -180,6 +180,7 @@ struct tmem_pamops {
38625 void (*new_obj)(struct tmem_obj *);
38626 int (*replace_in_obj)(void *, struct tmem_obj *);
38627 };
38628 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
38629 extern void tmem_register_pamops(struct tmem_pamops *m);
38630
38631 /* memory allocation methods provided by the host implementation */
38632 @@ -189,6 +190,7 @@ struct tmem_hostops {
38633 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
38634 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
38635 };
38636 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
38637 extern void tmem_register_hostops(struct tmem_hostops *m);
38638
38639 /* core tmem accessor functions */
38640 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
38641 index 97c74ee..7f6d77d 100644
38642 --- a/drivers/target/iscsi/iscsi_target.c
38643 +++ b/drivers/target/iscsi/iscsi_target.c
38644 @@ -1361,7 +1361,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
38645 * outstanding_r2ts reaches zero, go ahead and send the delayed
38646 * TASK_ABORTED status.
38647 */
38648 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
38649 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
38650 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
38651 if (--cmd->outstanding_r2ts < 1) {
38652 iscsit_stop_dataout_timer(cmd);
38653 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
38654 index dcb0618..97e3d85 100644
38655 --- a/drivers/target/target_core_tmr.c
38656 +++ b/drivers/target/target_core_tmr.c
38657 @@ -260,7 +260,7 @@ static void core_tmr_drain_task_list(
38658 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
38659 cmd->t_task_list_num,
38660 atomic_read(&cmd->t_task_cdbs_left),
38661 - atomic_read(&cmd->t_task_cdbs_sent),
38662 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
38663 atomic_read(&cmd->t_transport_active),
38664 atomic_read(&cmd->t_transport_stop),
38665 atomic_read(&cmd->t_transport_sent));
38666 @@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
38667 pr_debug("LUN_RESET: got t_transport_active = 1 for"
38668 " task: %p, t_fe_count: %d dev: %p\n", task,
38669 fe_count, dev);
38670 - atomic_set(&cmd->t_transport_aborted, 1);
38671 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
38672 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
38673
38674 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
38675 @@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
38676 }
38677 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
38678 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
38679 - atomic_set(&cmd->t_transport_aborted, 1);
38680 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
38681 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
38682
38683 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
38684 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
38685 index cd5cd95..5249d30 100644
38686 --- a/drivers/target/target_core_transport.c
38687 +++ b/drivers/target/target_core_transport.c
38688 @@ -1330,7 +1330,7 @@ struct se_device *transport_add_device_to_core_hba(
38689 spin_lock_init(&dev->se_port_lock);
38690 spin_lock_init(&dev->se_tmr_lock);
38691 spin_lock_init(&dev->qf_cmd_lock);
38692 - atomic_set(&dev->dev_ordered_id, 0);
38693 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
38694
38695 se_dev_set_default_attribs(dev, dev_limits);
38696
38697 @@ -1517,7 +1517,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
38698 * Used to determine when ORDERED commands should go from
38699 * Dormant to Active status.
38700 */
38701 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
38702 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
38703 smp_mb__after_atomic_inc();
38704 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
38705 cmd->se_ordered_id, cmd->sam_task_attr,
38706 @@ -1862,7 +1862,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
38707 " t_transport_active: %d t_transport_stop: %d"
38708 " t_transport_sent: %d\n", cmd->t_task_list_num,
38709 atomic_read(&cmd->t_task_cdbs_left),
38710 - atomic_read(&cmd->t_task_cdbs_sent),
38711 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
38712 atomic_read(&cmd->t_task_cdbs_ex_left),
38713 atomic_read(&cmd->t_transport_active),
38714 atomic_read(&cmd->t_transport_stop),
38715 @@ -2121,9 +2121,9 @@ check_depth:
38716 cmd = task->task_se_cmd;
38717 spin_lock_irqsave(&cmd->t_state_lock, flags);
38718 task->task_flags |= (TF_ACTIVE | TF_SENT);
38719 - atomic_inc(&cmd->t_task_cdbs_sent);
38720 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
38721
38722 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
38723 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
38724 cmd->t_task_list_num)
38725 atomic_set(&cmd->t_transport_sent, 1);
38726
38727 @@ -4348,7 +4348,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
38728 atomic_set(&cmd->transport_lun_stop, 0);
38729 }
38730 if (!atomic_read(&cmd->t_transport_active) ||
38731 - atomic_read(&cmd->t_transport_aborted)) {
38732 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
38733 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
38734 return false;
38735 }
38736 @@ -4597,7 +4597,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
38737 {
38738 int ret = 0;
38739
38740 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
38741 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
38742 if (!send_status ||
38743 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
38744 return 1;
38745 @@ -4634,7 +4634,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
38746 */
38747 if (cmd->data_direction == DMA_TO_DEVICE) {
38748 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
38749 - atomic_inc(&cmd->t_transport_aborted);
38750 + atomic_inc_unchecked(&cmd->t_transport_aborted);
38751 smp_mb__after_atomic_inc();
38752 }
38753 }
38754 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38755 index b9040be..e3f5aab 100644
38756 --- a/drivers/tty/hvc/hvcs.c
38757 +++ b/drivers/tty/hvc/hvcs.c
38758 @@ -83,6 +83,7 @@
38759 #include <asm/hvcserver.h>
38760 #include <asm/uaccess.h>
38761 #include <asm/vio.h>
38762 +#include <asm/local.h>
38763
38764 /*
38765 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38766 @@ -270,7 +271,7 @@ struct hvcs_struct {
38767 unsigned int index;
38768
38769 struct tty_struct *tty;
38770 - int open_count;
38771 + local_t open_count;
38772
38773 /*
38774 * Used to tell the driver kernel_thread what operations need to take
38775 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38776
38777 spin_lock_irqsave(&hvcsd->lock, flags);
38778
38779 - if (hvcsd->open_count > 0) {
38780 + if (local_read(&hvcsd->open_count) > 0) {
38781 spin_unlock_irqrestore(&hvcsd->lock, flags);
38782 printk(KERN_INFO "HVCS: vterm state unchanged. "
38783 "The hvcs device node is still in use.\n");
38784 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38785 if ((retval = hvcs_partner_connect(hvcsd)))
38786 goto error_release;
38787
38788 - hvcsd->open_count = 1;
38789 + local_set(&hvcsd->open_count, 1);
38790 hvcsd->tty = tty;
38791 tty->driver_data = hvcsd;
38792
38793 @@ -1179,7 +1180,7 @@ fast_open:
38794
38795 spin_lock_irqsave(&hvcsd->lock, flags);
38796 kref_get(&hvcsd->kref);
38797 - hvcsd->open_count++;
38798 + local_inc(&hvcsd->open_count);
38799 hvcsd->todo_mask |= HVCS_SCHED_READ;
38800 spin_unlock_irqrestore(&hvcsd->lock, flags);
38801
38802 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38803 hvcsd = tty->driver_data;
38804
38805 spin_lock_irqsave(&hvcsd->lock, flags);
38806 - if (--hvcsd->open_count == 0) {
38807 + if (local_dec_and_test(&hvcsd->open_count)) {
38808
38809 vio_disable_interrupts(hvcsd->vdev);
38810
38811 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38812 free_irq(irq, hvcsd);
38813 kref_put(&hvcsd->kref, destroy_hvcs_struct);
38814 return;
38815 - } else if (hvcsd->open_count < 0) {
38816 + } else if (local_read(&hvcsd->open_count) < 0) {
38817 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38818 " is missmanaged.\n",
38819 - hvcsd->vdev->unit_address, hvcsd->open_count);
38820 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
38821 }
38822
38823 spin_unlock_irqrestore(&hvcsd->lock, flags);
38824 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38825
38826 spin_lock_irqsave(&hvcsd->lock, flags);
38827 /* Preserve this so that we know how many kref refs to put */
38828 - temp_open_count = hvcsd->open_count;
38829 + temp_open_count = local_read(&hvcsd->open_count);
38830
38831 /*
38832 * Don't kref put inside the spinlock because the destruction
38833 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38834 hvcsd->tty->driver_data = NULL;
38835 hvcsd->tty = NULL;
38836
38837 - hvcsd->open_count = 0;
38838 + local_set(&hvcsd->open_count, 0);
38839
38840 /* This will drop any buffered data on the floor which is OK in a hangup
38841 * scenario. */
38842 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
38843 * the middle of a write operation? This is a crummy place to do this
38844 * but we want to keep it all in the spinlock.
38845 */
38846 - if (hvcsd->open_count <= 0) {
38847 + if (local_read(&hvcsd->open_count) <= 0) {
38848 spin_unlock_irqrestore(&hvcsd->lock, flags);
38849 return -ENODEV;
38850 }
38851 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38852 {
38853 struct hvcs_struct *hvcsd = tty->driver_data;
38854
38855 - if (!hvcsd || hvcsd->open_count <= 0)
38856 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
38857 return 0;
38858
38859 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38860 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38861 index ef92869..f4ebd88 100644
38862 --- a/drivers/tty/ipwireless/tty.c
38863 +++ b/drivers/tty/ipwireless/tty.c
38864 @@ -29,6 +29,7 @@
38865 #include <linux/tty_driver.h>
38866 #include <linux/tty_flip.h>
38867 #include <linux/uaccess.h>
38868 +#include <asm/local.h>
38869
38870 #include "tty.h"
38871 #include "network.h"
38872 @@ -51,7 +52,7 @@ struct ipw_tty {
38873 int tty_type;
38874 struct ipw_network *network;
38875 struct tty_struct *linux_tty;
38876 - int open_count;
38877 + local_t open_count;
38878 unsigned int control_lines;
38879 struct mutex ipw_tty_mutex;
38880 int tx_bytes_queued;
38881 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38882 mutex_unlock(&tty->ipw_tty_mutex);
38883 return -ENODEV;
38884 }
38885 - if (tty->open_count == 0)
38886 + if (local_read(&tty->open_count) == 0)
38887 tty->tx_bytes_queued = 0;
38888
38889 - tty->open_count++;
38890 + local_inc(&tty->open_count);
38891
38892 tty->linux_tty = linux_tty;
38893 linux_tty->driver_data = tty;
38894 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38895
38896 static void do_ipw_close(struct ipw_tty *tty)
38897 {
38898 - tty->open_count--;
38899 -
38900 - if (tty->open_count == 0) {
38901 + if (local_dec_return(&tty->open_count) == 0) {
38902 struct tty_struct *linux_tty = tty->linux_tty;
38903
38904 if (linux_tty != NULL) {
38905 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38906 return;
38907
38908 mutex_lock(&tty->ipw_tty_mutex);
38909 - if (tty->open_count == 0) {
38910 + if (local_read(&tty->open_count) == 0) {
38911 mutex_unlock(&tty->ipw_tty_mutex);
38912 return;
38913 }
38914 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38915 return;
38916 }
38917
38918 - if (!tty->open_count) {
38919 + if (!local_read(&tty->open_count)) {
38920 mutex_unlock(&tty->ipw_tty_mutex);
38921 return;
38922 }
38923 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38924 return -ENODEV;
38925
38926 mutex_lock(&tty->ipw_tty_mutex);
38927 - if (!tty->open_count) {
38928 + if (!local_read(&tty->open_count)) {
38929 mutex_unlock(&tty->ipw_tty_mutex);
38930 return -EINVAL;
38931 }
38932 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38933 if (!tty)
38934 return -ENODEV;
38935
38936 - if (!tty->open_count)
38937 + if (!local_read(&tty->open_count))
38938 return -EINVAL;
38939
38940 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38941 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38942 if (!tty)
38943 return 0;
38944
38945 - if (!tty->open_count)
38946 + if (!local_read(&tty->open_count))
38947 return 0;
38948
38949 return tty->tx_bytes_queued;
38950 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38951 if (!tty)
38952 return -ENODEV;
38953
38954 - if (!tty->open_count)
38955 + if (!local_read(&tty->open_count))
38956 return -EINVAL;
38957
38958 return get_control_lines(tty);
38959 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38960 if (!tty)
38961 return -ENODEV;
38962
38963 - if (!tty->open_count)
38964 + if (!local_read(&tty->open_count))
38965 return -EINVAL;
38966
38967 return set_control_lines(tty, set, clear);
38968 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38969 if (!tty)
38970 return -ENODEV;
38971
38972 - if (!tty->open_count)
38973 + if (!local_read(&tty->open_count))
38974 return -EINVAL;
38975
38976 /* FIXME: Exactly how is the tty object locked here .. */
38977 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38978 against a parallel ioctl etc */
38979 mutex_lock(&ttyj->ipw_tty_mutex);
38980 }
38981 - while (ttyj->open_count)
38982 + while (local_read(&ttyj->open_count))
38983 do_ipw_close(ttyj);
38984 ipwireless_disassociate_network_ttys(network,
38985 ttyj->channel_idx);
38986 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38987 index fc7bbba..9527e93 100644
38988 --- a/drivers/tty/n_gsm.c
38989 +++ b/drivers/tty/n_gsm.c
38990 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38991 kref_init(&dlci->ref);
38992 mutex_init(&dlci->mutex);
38993 dlci->fifo = &dlci->_fifo;
38994 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38995 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38996 kfree(dlci);
38997 return NULL;
38998 }
38999 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
39000 index d2256d0..97476fa 100644
39001 --- a/drivers/tty/n_tty.c
39002 +++ b/drivers/tty/n_tty.c
39003 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
39004 {
39005 *ops = tty_ldisc_N_TTY;
39006 ops->owner = NULL;
39007 - ops->refcount = ops->flags = 0;
39008 + atomic_set(&ops->refcount, 0);
39009 + ops->flags = 0;
39010 }
39011 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
39012 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
39013 index d8653ab..f8afd9d 100644
39014 --- a/drivers/tty/pty.c
39015 +++ b/drivers/tty/pty.c
39016 @@ -765,8 +765,10 @@ static void __init unix98_pty_init(void)
39017 register_sysctl_table(pty_root_table);
39018
39019 /* Now create the /dev/ptmx special device */
39020 + pax_open_kernel();
39021 tty_default_fops(&ptmx_fops);
39022 - ptmx_fops.open = ptmx_open;
39023 + *(void **)&ptmx_fops.open = ptmx_open;
39024 + pax_close_kernel();
39025
39026 cdev_init(&ptmx_cdev, &ptmx_fops);
39027 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
39028 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
39029 index 2b42a01..32a2ed3 100644
39030 --- a/drivers/tty/serial/kgdboc.c
39031 +++ b/drivers/tty/serial/kgdboc.c
39032 @@ -24,8 +24,9 @@
39033 #define MAX_CONFIG_LEN 40
39034
39035 static struct kgdb_io kgdboc_io_ops;
39036 +static struct kgdb_io kgdboc_io_ops_console;
39037
39038 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
39039 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
39040 static int configured = -1;
39041
39042 static char config[MAX_CONFIG_LEN];
39043 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
39044 kgdboc_unregister_kbd();
39045 if (configured == 1)
39046 kgdb_unregister_io_module(&kgdboc_io_ops);
39047 + else if (configured == 2)
39048 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
39049 }
39050
39051 static int configure_kgdboc(void)
39052 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
39053 int err;
39054 char *cptr = config;
39055 struct console *cons;
39056 + int is_console = 0;
39057
39058 err = kgdboc_option_setup(config);
39059 if (err || !strlen(config) || isspace(config[0]))
39060 goto noconfig;
39061
39062 err = -ENODEV;
39063 - kgdboc_io_ops.is_console = 0;
39064 kgdb_tty_driver = NULL;
39065
39066 kgdboc_use_kms = 0;
39067 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
39068 int idx;
39069 if (cons->device && cons->device(cons, &idx) == p &&
39070 idx == tty_line) {
39071 - kgdboc_io_ops.is_console = 1;
39072 + is_console = 1;
39073 break;
39074 }
39075 cons = cons->next;
39076 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
39077 kgdb_tty_line = tty_line;
39078
39079 do_register:
39080 - err = kgdb_register_io_module(&kgdboc_io_ops);
39081 + if (is_console) {
39082 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
39083 + configured = 2;
39084 + } else {
39085 + err = kgdb_register_io_module(&kgdboc_io_ops);
39086 + configured = 1;
39087 + }
39088 if (err)
39089 goto noconfig;
39090
39091 - configured = 1;
39092 -
39093 return 0;
39094
39095 noconfig:
39096 @@ -213,7 +220,7 @@ noconfig:
39097 static int __init init_kgdboc(void)
39098 {
39099 /* Already configured? */
39100 - if (configured == 1)
39101 + if (configured >= 1)
39102 return 0;
39103
39104 return configure_kgdboc();
39105 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
39106 if (config[len - 1] == '\n')
39107 config[len - 1] = '\0';
39108
39109 - if (configured == 1)
39110 + if (configured >= 1)
39111 cleanup_kgdboc();
39112
39113 /* Go and configure with the new params. */
39114 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
39115 .post_exception = kgdboc_post_exp_handler,
39116 };
39117
39118 +static struct kgdb_io kgdboc_io_ops_console = {
39119 + .name = "kgdboc",
39120 + .read_char = kgdboc_get_char,
39121 + .write_char = kgdboc_put_char,
39122 + .pre_exception = kgdboc_pre_exp_handler,
39123 + .post_exception = kgdboc_post_exp_handler,
39124 + .is_console = 1
39125 +};
39126 +
39127 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
39128 /* This is only available if kgdboc is a built in for early debugging */
39129 static int __init kgdboc_early_init(char *opt)
39130 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
39131 index 7867b7c..b3c119d 100644
39132 --- a/drivers/tty/sysrq.c
39133 +++ b/drivers/tty/sysrq.c
39134 @@ -862,7 +862,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
39135 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
39136 size_t count, loff_t *ppos)
39137 {
39138 - if (count) {
39139 + if (count && capable(CAP_SYS_ADMIN)) {
39140 char c;
39141
39142 if (get_user(c, buf))
39143 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
39144 index e41b9bb..84002fb 100644
39145 --- a/drivers/tty/tty_io.c
39146 +++ b/drivers/tty/tty_io.c
39147 @@ -3291,7 +3291,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
39148
39149 void tty_default_fops(struct file_operations *fops)
39150 {
39151 - *fops = tty_fops;
39152 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
39153 }
39154
39155 /*
39156 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
39157 index 24b95db..9c078d0 100644
39158 --- a/drivers/tty/tty_ldisc.c
39159 +++ b/drivers/tty/tty_ldisc.c
39160 @@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
39161 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
39162 struct tty_ldisc_ops *ldo = ld->ops;
39163
39164 - ldo->refcount--;
39165 + atomic_dec(&ldo->refcount);
39166 module_put(ldo->owner);
39167 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39168
39169 @@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
39170 spin_lock_irqsave(&tty_ldisc_lock, flags);
39171 tty_ldiscs[disc] = new_ldisc;
39172 new_ldisc->num = disc;
39173 - new_ldisc->refcount = 0;
39174 + atomic_set(&new_ldisc->refcount, 0);
39175 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39176
39177 return ret;
39178 @@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
39179 return -EINVAL;
39180
39181 spin_lock_irqsave(&tty_ldisc_lock, flags);
39182 - if (tty_ldiscs[disc]->refcount)
39183 + if (atomic_read(&tty_ldiscs[disc]->refcount))
39184 ret = -EBUSY;
39185 else
39186 tty_ldiscs[disc] = NULL;
39187 @@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
39188 if (ldops) {
39189 ret = ERR_PTR(-EAGAIN);
39190 if (try_module_get(ldops->owner)) {
39191 - ldops->refcount++;
39192 + atomic_inc(&ldops->refcount);
39193 ret = ldops;
39194 }
39195 }
39196 @@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
39197 unsigned long flags;
39198
39199 spin_lock_irqsave(&tty_ldisc_lock, flags);
39200 - ldops->refcount--;
39201 + atomic_dec(&ldops->refcount);
39202 module_put(ldops->owner);
39203 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39204 }
39205 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39206 index a605549..6bd3c96 100644
39207 --- a/drivers/tty/vt/keyboard.c
39208 +++ b/drivers/tty/vt/keyboard.c
39209 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39210 kbd->kbdmode == VC_OFF) &&
39211 value != KVAL(K_SAK))
39212 return; /* SAK is allowed even in raw mode */
39213 +
39214 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39215 + {
39216 + void *func = fn_handler[value];
39217 + if (func == fn_show_state || func == fn_show_ptregs ||
39218 + func == fn_show_mem)
39219 + return;
39220 + }
39221 +#endif
39222 +
39223 fn_handler[value](vc);
39224 }
39225
39226 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
39227 index 65447c5..0526f0a 100644
39228 --- a/drivers/tty/vt/vt_ioctl.c
39229 +++ b/drivers/tty/vt/vt_ioctl.c
39230 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
39231 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39232 return -EFAULT;
39233
39234 - if (!capable(CAP_SYS_TTY_CONFIG))
39235 - perm = 0;
39236 -
39237 switch (cmd) {
39238 case KDGKBENT:
39239 key_map = key_maps[s];
39240 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
39241 val = (i ? K_HOLE : K_NOSUCHMAP);
39242 return put_user(val, &user_kbe->kb_value);
39243 case KDSKBENT:
39244 + if (!capable(CAP_SYS_TTY_CONFIG))
39245 + perm = 0;
39246 +
39247 if (!perm)
39248 return -EPERM;
39249 if (!i && v == K_NOSUCHMAP) {
39250 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39251 int i, j, k;
39252 int ret;
39253
39254 - if (!capable(CAP_SYS_TTY_CONFIG))
39255 - perm = 0;
39256 -
39257 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39258 if (!kbs) {
39259 ret = -ENOMEM;
39260 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39261 kfree(kbs);
39262 return ((p && *p) ? -EOVERFLOW : 0);
39263 case KDSKBSENT:
39264 + if (!capable(CAP_SYS_TTY_CONFIG))
39265 + perm = 0;
39266 +
39267 if (!perm) {
39268 ret = -EPERM;
39269 goto reterr;
39270 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39271 index a783d53..cb30d94 100644
39272 --- a/drivers/uio/uio.c
39273 +++ b/drivers/uio/uio.c
39274 @@ -25,6 +25,7 @@
39275 #include <linux/kobject.h>
39276 #include <linux/cdev.h>
39277 #include <linux/uio_driver.h>
39278 +#include <asm/local.h>
39279
39280 #define UIO_MAX_DEVICES (1U << MINORBITS)
39281
39282 @@ -32,10 +33,10 @@ struct uio_device {
39283 struct module *owner;
39284 struct device *dev;
39285 int minor;
39286 - atomic_t event;
39287 + atomic_unchecked_t event;
39288 struct fasync_struct *async_queue;
39289 wait_queue_head_t wait;
39290 - int vma_count;
39291 + local_t vma_count;
39292 struct uio_info *info;
39293 struct kobject *map_dir;
39294 struct kobject *portio_dir;
39295 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39296 struct device_attribute *attr, char *buf)
39297 {
39298 struct uio_device *idev = dev_get_drvdata(dev);
39299 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39300 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39301 }
39302
39303 static struct device_attribute uio_class_attributes[] = {
39304 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39305 {
39306 struct uio_device *idev = info->uio_dev;
39307
39308 - atomic_inc(&idev->event);
39309 + atomic_inc_unchecked(&idev->event);
39310 wake_up_interruptible(&idev->wait);
39311 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39312 }
39313 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39314 }
39315
39316 listener->dev = idev;
39317 - listener->event_count = atomic_read(&idev->event);
39318 + listener->event_count = atomic_read_unchecked(&idev->event);
39319 filep->private_data = listener;
39320
39321 if (idev->info->open) {
39322 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39323 return -EIO;
39324
39325 poll_wait(filep, &idev->wait, wait);
39326 - if (listener->event_count != atomic_read(&idev->event))
39327 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39328 return POLLIN | POLLRDNORM;
39329 return 0;
39330 }
39331 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39332 do {
39333 set_current_state(TASK_INTERRUPTIBLE);
39334
39335 - event_count = atomic_read(&idev->event);
39336 + event_count = atomic_read_unchecked(&idev->event);
39337 if (event_count != listener->event_count) {
39338 if (copy_to_user(buf, &event_count, count))
39339 retval = -EFAULT;
39340 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39341 static void uio_vma_open(struct vm_area_struct *vma)
39342 {
39343 struct uio_device *idev = vma->vm_private_data;
39344 - idev->vma_count++;
39345 + local_inc(&idev->vma_count);
39346 }
39347
39348 static void uio_vma_close(struct vm_area_struct *vma)
39349 {
39350 struct uio_device *idev = vma->vm_private_data;
39351 - idev->vma_count--;
39352 + local_dec(&idev->vma_count);
39353 }
39354
39355 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39356 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39357 idev->owner = owner;
39358 idev->info = info;
39359 init_waitqueue_head(&idev->wait);
39360 - atomic_set(&idev->event, 0);
39361 + atomic_set_unchecked(&idev->event, 0);
39362
39363 ret = uio_get_minor(idev);
39364 if (ret)
39365 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39366 index 98b89fe..aff824e 100644
39367 --- a/drivers/usb/atm/cxacru.c
39368 +++ b/drivers/usb/atm/cxacru.c
39369 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39370 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39371 if (ret < 2)
39372 return -EINVAL;
39373 - if (index < 0 || index > 0x7f)
39374 + if (index > 0x7f)
39375 return -EINVAL;
39376 pos += tmp;
39377
39378 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39379 index d3448ca..d2864ca 100644
39380 --- a/drivers/usb/atm/usbatm.c
39381 +++ b/drivers/usb/atm/usbatm.c
39382 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39383 if (printk_ratelimit())
39384 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39385 __func__, vpi, vci);
39386 - atomic_inc(&vcc->stats->rx_err);
39387 + atomic_inc_unchecked(&vcc->stats->rx_err);
39388 return;
39389 }
39390
39391 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39392 if (length > ATM_MAX_AAL5_PDU) {
39393 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39394 __func__, length, vcc);
39395 - atomic_inc(&vcc->stats->rx_err);
39396 + atomic_inc_unchecked(&vcc->stats->rx_err);
39397 goto out;
39398 }
39399
39400 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39401 if (sarb->len < pdu_length) {
39402 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39403 __func__, pdu_length, sarb->len, vcc);
39404 - atomic_inc(&vcc->stats->rx_err);
39405 + atomic_inc_unchecked(&vcc->stats->rx_err);
39406 goto out;
39407 }
39408
39409 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39410 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39411 __func__, vcc);
39412 - atomic_inc(&vcc->stats->rx_err);
39413 + atomic_inc_unchecked(&vcc->stats->rx_err);
39414 goto out;
39415 }
39416
39417 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39418 if (printk_ratelimit())
39419 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39420 __func__, length);
39421 - atomic_inc(&vcc->stats->rx_drop);
39422 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39423 goto out;
39424 }
39425
39426 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39427
39428 vcc->push(vcc, skb);
39429
39430 - atomic_inc(&vcc->stats->rx);
39431 + atomic_inc_unchecked(&vcc->stats->rx);
39432 out:
39433 skb_trim(sarb, 0);
39434 }
39435 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39436 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39437
39438 usbatm_pop(vcc, skb);
39439 - atomic_inc(&vcc->stats->tx);
39440 + atomic_inc_unchecked(&vcc->stats->tx);
39441
39442 skb = skb_dequeue(&instance->sndqueue);
39443 }
39444 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39445 if (!left--)
39446 return sprintf(page,
39447 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39448 - atomic_read(&atm_dev->stats.aal5.tx),
39449 - atomic_read(&atm_dev->stats.aal5.tx_err),
39450 - atomic_read(&atm_dev->stats.aal5.rx),
39451 - atomic_read(&atm_dev->stats.aal5.rx_err),
39452 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39453 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39454 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39455 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39456 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39457 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39458
39459 if (!left--) {
39460 if (instance->disconnected)
39461 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39462 index d956965..4179a77 100644
39463 --- a/drivers/usb/core/devices.c
39464 +++ b/drivers/usb/core/devices.c
39465 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39466 * time it gets called.
39467 */
39468 static struct device_connect_event {
39469 - atomic_t count;
39470 + atomic_unchecked_t count;
39471 wait_queue_head_t wait;
39472 } device_event = {
39473 .count = ATOMIC_INIT(1),
39474 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39475
39476 void usbfs_conn_disc_event(void)
39477 {
39478 - atomic_add(2, &device_event.count);
39479 + atomic_add_unchecked(2, &device_event.count);
39480 wake_up(&device_event.wait);
39481 }
39482
39483 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39484
39485 poll_wait(file, &device_event.wait, wait);
39486
39487 - event_count = atomic_read(&device_event.count);
39488 + event_count = atomic_read_unchecked(&device_event.count);
39489 if (file->f_version != event_count) {
39490 file->f_version = event_count;
39491 return POLLIN | POLLRDNORM;
39492 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39493 index 1fc8f12..20647c1 100644
39494 --- a/drivers/usb/early/ehci-dbgp.c
39495 +++ b/drivers/usb/early/ehci-dbgp.c
39496 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39497
39498 #ifdef CONFIG_KGDB
39499 static struct kgdb_io kgdbdbgp_io_ops;
39500 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39501 +static struct kgdb_io kgdbdbgp_io_ops_console;
39502 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39503 #else
39504 #define dbgp_kgdb_mode (0)
39505 #endif
39506 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39507 .write_char = kgdbdbgp_write_char,
39508 };
39509
39510 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39511 + .name = "kgdbdbgp",
39512 + .read_char = kgdbdbgp_read_char,
39513 + .write_char = kgdbdbgp_write_char,
39514 + .is_console = 1
39515 +};
39516 +
39517 static int kgdbdbgp_wait_time;
39518
39519 static int __init kgdbdbgp_parse_config(char *str)
39520 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39521 ptr++;
39522 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39523 }
39524 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39525 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39526 + if (early_dbgp_console.index != -1)
39527 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39528 + else
39529 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39530
39531 return 0;
39532 }
39533 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39534 index d6bea3e..60b250e 100644
39535 --- a/drivers/usb/wusbcore/wa-hc.h
39536 +++ b/drivers/usb/wusbcore/wa-hc.h
39537 @@ -192,7 +192,7 @@ struct wahc {
39538 struct list_head xfer_delayed_list;
39539 spinlock_t xfer_list_lock;
39540 struct work_struct xfer_work;
39541 - atomic_t xfer_id_count;
39542 + atomic_unchecked_t xfer_id_count;
39543 };
39544
39545
39546 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39547 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39548 spin_lock_init(&wa->xfer_list_lock);
39549 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39550 - atomic_set(&wa->xfer_id_count, 1);
39551 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39552 }
39553
39554 /**
39555 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39556 index 57c01ab..8a05959 100644
39557 --- a/drivers/usb/wusbcore/wa-xfer.c
39558 +++ b/drivers/usb/wusbcore/wa-xfer.c
39559 @@ -296,7 +296,7 @@ out:
39560 */
39561 static void wa_xfer_id_init(struct wa_xfer *xfer)
39562 {
39563 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39564 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39565 }
39566
39567 /*
39568 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39569 index c14c42b..f955cc2 100644
39570 --- a/drivers/vhost/vhost.c
39571 +++ b/drivers/vhost/vhost.c
39572 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39573 return 0;
39574 }
39575
39576 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39577 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39578 {
39579 struct file *eventfp, *filep = NULL,
39580 *pollstart = NULL, *pollstop = NULL;
39581 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39582 index b0b2ac3..89a4399 100644
39583 --- a/drivers/video/aty/aty128fb.c
39584 +++ b/drivers/video/aty/aty128fb.c
39585 @@ -148,7 +148,7 @@ enum {
39586 };
39587
39588 /* Must match above enum */
39589 -static const char *r128_family[] __devinitdata = {
39590 +static const char *r128_family[] __devinitconst = {
39591 "AGP",
39592 "PCI",
39593 "PRO AGP",
39594 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39595 index 5c3960d..15cf8fc 100644
39596 --- a/drivers/video/fbcmap.c
39597 +++ b/drivers/video/fbcmap.c
39598 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39599 rc = -ENODEV;
39600 goto out;
39601 }
39602 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39603 - !info->fbops->fb_setcmap)) {
39604 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39605 rc = -EINVAL;
39606 goto out1;
39607 }
39608 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39609 index c6ce416..3b9b642 100644
39610 --- a/drivers/video/fbmem.c
39611 +++ b/drivers/video/fbmem.c
39612 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39613 image->dx += image->width + 8;
39614 }
39615 } else if (rotate == FB_ROTATE_UD) {
39616 - for (x = 0; x < num && image->dx >= 0; x++) {
39617 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39618 info->fbops->fb_imageblit(info, image);
39619 image->dx -= image->width + 8;
39620 }
39621 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39622 image->dy += image->height + 8;
39623 }
39624 } else if (rotate == FB_ROTATE_CCW) {
39625 - for (x = 0; x < num && image->dy >= 0; x++) {
39626 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39627 info->fbops->fb_imageblit(info, image);
39628 image->dy -= image->height + 8;
39629 }
39630 @@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39631 return -EFAULT;
39632 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39633 return -EINVAL;
39634 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39635 + if (con2fb.framebuffer >= FB_MAX)
39636 return -EINVAL;
39637 if (!registered_fb[con2fb.framebuffer])
39638 request_module("fb%d", con2fb.framebuffer);
39639 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39640 index 5a5d092..265c5ed 100644
39641 --- a/drivers/video/geode/gx1fb_core.c
39642 +++ b/drivers/video/geode/gx1fb_core.c
39643 @@ -29,7 +29,7 @@ static int crt_option = 1;
39644 static char panel_option[32] = "";
39645
39646 /* Modes relevant to the GX1 (taken from modedb.c) */
39647 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39648 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39649 /* 640x480-60 VESA */
39650 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39651 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39652 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39653 index 0fad23f..0e9afa4 100644
39654 --- a/drivers/video/gxt4500.c
39655 +++ b/drivers/video/gxt4500.c
39656 @@ -156,7 +156,7 @@ struct gxt4500_par {
39657 static char *mode_option;
39658
39659 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39660 -static const struct fb_videomode defaultmode __devinitdata = {
39661 +static const struct fb_videomode defaultmode __devinitconst = {
39662 .refresh = 60,
39663 .xres = 1280,
39664 .yres = 1024,
39665 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39666 return 0;
39667 }
39668
39669 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39670 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39671 .id = "IBM GXT4500P",
39672 .type = FB_TYPE_PACKED_PIXELS,
39673 .visual = FB_VISUAL_PSEUDOCOLOR,
39674 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39675 index 7672d2e..b56437f 100644
39676 --- a/drivers/video/i810/i810_accel.c
39677 +++ b/drivers/video/i810/i810_accel.c
39678 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39679 }
39680 }
39681 printk("ringbuffer lockup!!!\n");
39682 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39683 i810_report_error(mmio);
39684 par->dev_flags |= LOCKUP;
39685 info->pixmap.scan_align = 1;
39686 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39687 index b83f361..2b05a91 100644
39688 --- a/drivers/video/i810/i810_main.c
39689 +++ b/drivers/video/i810/i810_main.c
39690 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39691 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39692
39693 /* PCI */
39694 -static const char *i810_pci_list[] __devinitdata = {
39695 +static const char *i810_pci_list[] __devinitconst = {
39696 "Intel(R) 810 Framebuffer Device" ,
39697 "Intel(R) 810-DC100 Framebuffer Device" ,
39698 "Intel(R) 810E Framebuffer Device" ,
39699 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39700 index de36693..3c63fc2 100644
39701 --- a/drivers/video/jz4740_fb.c
39702 +++ b/drivers/video/jz4740_fb.c
39703 @@ -136,7 +136,7 @@ struct jzfb {
39704 uint32_t pseudo_palette[16];
39705 };
39706
39707 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39708 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39709 .id = "JZ4740 FB",
39710 .type = FB_TYPE_PACKED_PIXELS,
39711 .visual = FB_VISUAL_TRUECOLOR,
39712 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39713 index 3c14e43..eafa544 100644
39714 --- a/drivers/video/logo/logo_linux_clut224.ppm
39715 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39716 @@ -1,1604 +1,1123 @@
39717 P3
39718 -# Standard 224-color Linux logo
39719 80 80
39720 255
39721 - 0 0 0 0 0 0 0 0 0 0 0 0
39722 - 0 0 0 0 0 0 0 0 0 0 0 0
39723 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 6 6 6 6 6 6 10 10 10 10 10 10
39731 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 0 0 0 0 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 6 6 6 10 10 10 14 14 14
39750 - 22 22 22 26 26 26 30 30 30 34 34 34
39751 - 30 30 30 30 30 30 26 26 26 18 18 18
39752 - 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 0 0 1 0 0 1 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 0 0 0
39767 - 0 0 0 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 0 0 0 0 0 0
39769 - 6 6 6 14 14 14 26 26 26 42 42 42
39770 - 54 54 54 66 66 66 78 78 78 78 78 78
39771 - 78 78 78 74 74 74 66 66 66 54 54 54
39772 - 42 42 42 26 26 26 18 18 18 10 10 10
39773 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 1 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 0 0 0 0 0 0
39785 - 0 0 0 0 0 0 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 0 0 0 0 0 0 0
39788 - 0 0 0 0 0 0 0 0 0 10 10 10
39789 - 22 22 22 42 42 42 66 66 66 86 86 86
39790 - 66 66 66 38 38 38 38 38 38 22 22 22
39791 - 26 26 26 34 34 34 54 54 54 66 66 66
39792 - 86 86 86 70 70 70 46 46 46 26 26 26
39793 - 14 14 14 6 6 6 0 0 0 0 0 0
39794 - 0 0 0 0 0 0 0 0 0 0 0 0
39795 - 0 0 0 0 0 0 0 0 0 0 0 0
39796 - 0 0 0 0 0 0 0 0 0 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 1 0 0 1 0 0 1 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 0 0 0 0 0 0
39805 - 0 0 0 0 0 0 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 0 0 0
39807 - 0 0 0 0 0 0 0 0 0 0 0 0
39808 - 0 0 0 0 0 0 10 10 10 26 26 26
39809 - 50 50 50 82 82 82 58 58 58 6 6 6
39810 - 2 2 6 2 2 6 2 2 6 2 2 6
39811 - 2 2 6 2 2 6 2 2 6 2 2 6
39812 - 6 6 6 54 54 54 86 86 86 66 66 66
39813 - 38 38 38 18 18 18 6 6 6 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 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 0 0 0 0 0 0
39825 - 0 0 0 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 0 0 0 0 0 0
39827 - 0 0 0 0 0 0 0 0 0 0 0 0
39828 - 0 0 0 6 6 6 22 22 22 50 50 50
39829 - 78 78 78 34 34 34 2 2 6 2 2 6
39830 - 2 2 6 2 2 6 2 2 6 2 2 6
39831 - 2 2 6 2 2 6 2 2 6 2 2 6
39832 - 2 2 6 2 2 6 6 6 6 70 70 70
39833 - 78 78 78 46 46 46 22 22 22 6 6 6
39834 - 0 0 0 0 0 0 0 0 0 0 0 0
39835 - 0 0 0 0 0 0 0 0 0 0 0 0
39836 - 0 0 0 0 0 0 0 0 0 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 0 0 0
39839 - 0 0 0 0 0 0 0 0 0 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 0 0 1 0 0 1 0 0 1 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 0 0 0 0 0 0 0 0 0 0 0 0
39845 - 0 0 0 0 0 0 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 0 0 0 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 6 6 6 18 18 18 42 42 42 82 82 82
39849 - 26 26 26 2 2 6 2 2 6 2 2 6
39850 - 2 2 6 2 2 6 2 2 6 2 2 6
39851 - 2 2 6 2 2 6 2 2 6 14 14 14
39852 - 46 46 46 34 34 34 6 6 6 2 2 6
39853 - 42 42 42 78 78 78 42 42 42 18 18 18
39854 - 6 6 6 0 0 0 0 0 0 0 0 0
39855 - 0 0 0 0 0 0 0 0 0 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 0 0 0 0 0 0 0 0 0 0
39860 - 0 0 0 0 0 0 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 0 0 0
39862 - 0 0 1 0 0 0 0 0 1 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 0 0 0 0
39867 - 0 0 0 0 0 0 0 0 0 0 0 0
39868 - 10 10 10 30 30 30 66 66 66 58 58 58
39869 - 2 2 6 2 2 6 2 2 6 2 2 6
39870 - 2 2 6 2 2 6 2 2 6 2 2 6
39871 - 2 2 6 2 2 6 2 2 6 26 26 26
39872 - 86 86 86 101 101 101 46 46 46 10 10 10
39873 - 2 2 6 58 58 58 70 70 70 34 34 34
39874 - 10 10 10 0 0 0 0 0 0 0 0 0
39875 - 0 0 0 0 0 0 0 0 0 0 0 0
39876 - 0 0 0 0 0 0 0 0 0 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 0 0 0 0 0 0 0 0 0 0 0 0
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 0 0 0
39882 - 0 0 1 0 0 1 0 0 1 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 0 0 0
39884 - 0 0 0 0 0 0 0 0 0 0 0 0
39885 - 0 0 0 0 0 0 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 0 0 0
39888 - 14 14 14 42 42 42 86 86 86 10 10 10
39889 - 2 2 6 2 2 6 2 2 6 2 2 6
39890 - 2 2 6 2 2 6 2 2 6 2 2 6
39891 - 2 2 6 2 2 6 2 2 6 30 30 30
39892 - 94 94 94 94 94 94 58 58 58 26 26 26
39893 - 2 2 6 6 6 6 78 78 78 54 54 54
39894 - 22 22 22 6 6 6 0 0 0 0 0 0
39895 - 0 0 0 0 0 0 0 0 0 0 0 0
39896 - 0 0 0 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 0 0 0 0 0 0 0 0 0 0 0 0
39900 - 0 0 0 0 0 0 0 0 0 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 0 0 0
39906 - 0 0 0 0 0 0 0 0 0 0 0 0
39907 - 0 0 0 0 0 0 0 0 0 6 6 6
39908 - 22 22 22 62 62 62 62 62 62 2 2 6
39909 - 2 2 6 2 2 6 2 2 6 2 2 6
39910 - 2 2 6 2 2 6 2 2 6 2 2 6
39911 - 2 2 6 2 2 6 2 2 6 26 26 26
39912 - 54 54 54 38 38 38 18 18 18 10 10 10
39913 - 2 2 6 2 2 6 34 34 34 82 82 82
39914 - 38 38 38 14 14 14 0 0 0 0 0 0
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 0 0 0 0 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 0 0 0 0 0 0 0 0 0 0 0 0
39920 - 0 0 0 0 0 0 0 0 0 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 1 0 0 1 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 0 0 0 0 0 0 0 0 0 0 0 0
39927 - 0 0 0 0 0 0 0 0 0 6 6 6
39928 - 30 30 30 78 78 78 30 30 30 2 2 6
39929 - 2 2 6 2 2 6 2 2 6 2 2 6
39930 - 2 2 6 2 2 6 2 2 6 2 2 6
39931 - 2 2 6 2 2 6 2 2 6 10 10 10
39932 - 10 10 10 2 2 6 2 2 6 2 2 6
39933 - 2 2 6 2 2 6 2 2 6 78 78 78
39934 - 50 50 50 18 18 18 6 6 6 0 0 0
39935 - 0 0 0 0 0 0 0 0 0 0 0 0
39936 - 0 0 0 0 0 0 0 0 0 0 0 0
39937 - 0 0 0 0 0 0 0 0 0 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 0 0 0
39939 - 0 0 0 0 0 0 0 0 0 0 0 0
39940 - 0 0 0 0 0 0 0 0 0 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 1 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 0 0 0
39946 - 0 0 0 0 0 0 0 0 0 0 0 0
39947 - 0 0 0 0 0 0 0 0 0 10 10 10
39948 - 38 38 38 86 86 86 14 14 14 2 2 6
39949 - 2 2 6 2 2 6 2 2 6 2 2 6
39950 - 2 2 6 2 2 6 2 2 6 2 2 6
39951 - 2 2 6 2 2 6 2 2 6 2 2 6
39952 - 2 2 6 2 2 6 2 2 6 2 2 6
39953 - 2 2 6 2 2 6 2 2 6 54 54 54
39954 - 66 66 66 26 26 26 6 6 6 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 0 0 0
39959 - 0 0 0 0 0 0 0 0 0 0 0 0
39960 - 0 0 0 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 0 0 0 1 0 0 1 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
39966 - 0 0 0 0 0 0 0 0 0 0 0 0
39967 - 0 0 0 0 0 0 0 0 0 14 14 14
39968 - 42 42 42 82 82 82 2 2 6 2 2 6
39969 - 2 2 6 6 6 6 10 10 10 2 2 6
39970 - 2 2 6 2 2 6 2 2 6 2 2 6
39971 - 2 2 6 2 2 6 2 2 6 6 6 6
39972 - 14 14 14 10 10 10 2 2 6 2 2 6
39973 - 2 2 6 2 2 6 2 2 6 18 18 18
39974 - 82 82 82 34 34 34 10 10 10 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 0 0 0
39979 - 0 0 0 0 0 0 0 0 0 0 0 0
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 1 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 14 14 14
39988 - 46 46 46 86 86 86 2 2 6 2 2 6
39989 - 6 6 6 6 6 6 22 22 22 34 34 34
39990 - 6 6 6 2 2 6 2 2 6 2 2 6
39991 - 2 2 6 2 2 6 18 18 18 34 34 34
39992 - 10 10 10 50 50 50 22 22 22 2 2 6
39993 - 2 2 6 2 2 6 2 2 6 10 10 10
39994 - 86 86 86 42 42 42 14 14 14 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 0 0 0 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 1 0 0 1 0 0 1 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 - 0 0 0 0 0 0 0 0 0 14 14 14
40008 - 46 46 46 86 86 86 2 2 6 2 2 6
40009 - 38 38 38 116 116 116 94 94 94 22 22 22
40010 - 22 22 22 2 2 6 2 2 6 2 2 6
40011 - 14 14 14 86 86 86 138 138 138 162 162 162
40012 -154 154 154 38 38 38 26 26 26 6 6 6
40013 - 2 2 6 2 2 6 2 2 6 2 2 6
40014 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0
40019 - 0 0 0 0 0 0 0 0 0 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 0 0 0 0 0 0
40024 - 0 0 0 0 0 0 0 0 0 0 0 0
40025 - 0 0 0 0 0 0 0 0 0 0 0 0
40026 - 0 0 0 0 0 0 0 0 0 0 0 0
40027 - 0 0 0 0 0 0 0 0 0 14 14 14
40028 - 46 46 46 86 86 86 2 2 6 14 14 14
40029 -134 134 134 198 198 198 195 195 195 116 116 116
40030 - 10 10 10 2 2 6 2 2 6 6 6 6
40031 -101 98 89 187 187 187 210 210 210 218 218 218
40032 -214 214 214 134 134 134 14 14 14 6 6 6
40033 - 2 2 6 2 2 6 2 2 6 2 2 6
40034 - 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0 0 0 0 0 0 0
40039 - 0 0 0 0 0 0 0 0 0 0 0 0
40040 - 0 0 0 0 0 0 0 0 0 0 0 0
40041 - 0 0 0 0 0 0 0 0 1 0 0 0
40042 - 0 0 1 0 0 1 0 0 1 0 0 0
40043 - 0 0 0 0 0 0 0 0 0 0 0 0
40044 - 0 0 0 0 0 0 0 0 0 0 0 0
40045 - 0 0 0 0 0 0 0 0 0 0 0 0
40046 - 0 0 0 0 0 0 0 0 0 0 0 0
40047 - 0 0 0 0 0 0 0 0 0 14 14 14
40048 - 46 46 46 86 86 86 2 2 6 54 54 54
40049 -218 218 218 195 195 195 226 226 226 246 246 246
40050 - 58 58 58 2 2 6 2 2 6 30 30 30
40051 -210 210 210 253 253 253 174 174 174 123 123 123
40052 -221 221 221 234 234 234 74 74 74 2 2 6
40053 - 2 2 6 2 2 6 2 2 6 2 2 6
40054 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
40059 - 0 0 0 0 0 0 0 0 0 0 0 0
40060 - 0 0 0 0 0 0 0 0 0 0 0 0
40061 - 0 0 0 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 0 0 0 0 0 0
40063 - 0 0 0 0 0 0 0 0 0 0 0 0
40064 - 0 0 0 0 0 0 0 0 0 0 0 0
40065 - 0 0 0 0 0 0 0 0 0 0 0 0
40066 - 0 0 0 0 0 0 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 0 14 14 14
40068 - 46 46 46 82 82 82 2 2 6 106 106 106
40069 -170 170 170 26 26 26 86 86 86 226 226 226
40070 -123 123 123 10 10 10 14 14 14 46 46 46
40071 -231 231 231 190 190 190 6 6 6 70 70 70
40072 - 90 90 90 238 238 238 158 158 158 2 2 6
40073 - 2 2 6 2 2 6 2 2 6 2 2 6
40074 - 70 70 70 58 58 58 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40079 - 0 0 0 0 0 0 0 0 0 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 1 0 0 0
40082 - 0 0 1 0 0 1 0 0 1 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 0 0 0 0 0 0 0 0 0 0 0 0
40085 - 0 0 0 0 0 0 0 0 0 0 0 0
40086 - 0 0 0 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 0 14 14 14
40088 - 42 42 42 86 86 86 6 6 6 116 116 116
40089 -106 106 106 6 6 6 70 70 70 149 149 149
40090 -128 128 128 18 18 18 38 38 38 54 54 54
40091 -221 221 221 106 106 106 2 2 6 14 14 14
40092 - 46 46 46 190 190 190 198 198 198 2 2 6
40093 - 2 2 6 2 2 6 2 2 6 2 2 6
40094 - 74 74 74 62 62 62 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40099 - 0 0 0 0 0 0 0 0 0 0 0 0
40100 - 0 0 0 0 0 0 0 0 0 0 0 0
40101 - 0 0 0 0 0 0 0 0 1 0 0 0
40102 - 0 0 1 0 0 0 0 0 1 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 0 0 0 0 0 0 0 0 0 0 0 0
40105 - 0 0 0 0 0 0 0 0 0 0 0 0
40106 - 0 0 0 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 0 0 0 14 14 14
40108 - 42 42 42 94 94 94 14 14 14 101 101 101
40109 -128 128 128 2 2 6 18 18 18 116 116 116
40110 -118 98 46 121 92 8 121 92 8 98 78 10
40111 -162 162 162 106 106 106 2 2 6 2 2 6
40112 - 2 2 6 195 195 195 195 195 195 6 6 6
40113 - 2 2 6 2 2 6 2 2 6 2 2 6
40114 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
40118 - 0 0 0 0 0 0 0 0 0 0 0 0
40119 - 0 0 0 0 0 0 0 0 0 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 0 0 0
40121 - 0 0 0 0 0 0 0 0 1 0 0 1
40122 - 0 0 1 0 0 0 0 0 1 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 0 0 0 0 0 0 0 0 0 0 0 0
40125 - 0 0 0 0 0 0 0 0 0 0 0 0
40126 - 0 0 0 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 10 10 10
40128 - 38 38 38 90 90 90 14 14 14 58 58 58
40129 -210 210 210 26 26 26 54 38 6 154 114 10
40130 -226 170 11 236 186 11 225 175 15 184 144 12
40131 -215 174 15 175 146 61 37 26 9 2 2 6
40132 - 70 70 70 246 246 246 138 138 138 2 2 6
40133 - 2 2 6 2 2 6 2 2 6 2 2 6
40134 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
40138 - 0 0 0 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 0 0 0
40144 - 0 0 0 0 0 0 0 0 0 0 0 0
40145 - 0 0 0 0 0 0 0 0 0 0 0 0
40146 - 0 0 0 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 10 10 10
40148 - 38 38 38 86 86 86 14 14 14 10 10 10
40149 -195 195 195 188 164 115 192 133 9 225 175 15
40150 -239 182 13 234 190 10 232 195 16 232 200 30
40151 -245 207 45 241 208 19 232 195 16 184 144 12
40152 -218 194 134 211 206 186 42 42 42 2 2 6
40153 - 2 2 6 2 2 6 2 2 6 2 2 6
40154 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
40158 - 0 0 0 0 0 0 0 0 0 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 0 0 0
40163 - 0 0 0 0 0 0 0 0 0 0 0 0
40164 - 0 0 0 0 0 0 0 0 0 0 0 0
40165 - 0 0 0 0 0 0 0 0 0 0 0 0
40166 - 0 0 0 0 0 0 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 10 10 10
40168 - 34 34 34 86 86 86 14 14 14 2 2 6
40169 -121 87 25 192 133 9 219 162 10 239 182 13
40170 -236 186 11 232 195 16 241 208 19 244 214 54
40171 -246 218 60 246 218 38 246 215 20 241 208 19
40172 -241 208 19 226 184 13 121 87 25 2 2 6
40173 - 2 2 6 2 2 6 2 2 6 2 2 6
40174 - 50 50 50 82 82 82 34 34 34 10 10 10
40175 - 0 0 0 0 0 0 0 0 0 0 0 0
40176 - 0 0 0 0 0 0 0 0 0 0 0 0
40177 - 0 0 0 0 0 0 0 0 0 0 0 0
40178 - 0 0 0 0 0 0 0 0 0 0 0 0
40179 - 0 0 0 0 0 0 0 0 0 0 0 0
40180 - 0 0 0 0 0 0 0 0 0 0 0 0
40181 - 0 0 0 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 0 0 0 0 0 0
40185 - 0 0 0 0 0 0 0 0 0 0 0 0
40186 - 0 0 0 0 0 0 0 0 0 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 10 10 10
40188 - 34 34 34 82 82 82 30 30 30 61 42 6
40189 -180 123 7 206 145 10 230 174 11 239 182 13
40190 -234 190 10 238 202 15 241 208 19 246 218 74
40191 -246 218 38 246 215 20 246 215 20 246 215 20
40192 -226 184 13 215 174 15 184 144 12 6 6 6
40193 - 2 2 6 2 2 6 2 2 6 2 2 6
40194 - 26 26 26 94 94 94 42 42 42 14 14 14
40195 - 0 0 0 0 0 0 0 0 0 0 0 0
40196 - 0 0 0 0 0 0 0 0 0 0 0 0
40197 - 0 0 0 0 0 0 0 0 0 0 0 0
40198 - 0 0 0 0 0 0 0 0 0 0 0 0
40199 - 0 0 0 0 0 0 0 0 0 0 0 0
40200 - 0 0 0 0 0 0 0 0 0 0 0 0
40201 - 0 0 0 0 0 0 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 0 0 0 0 0 0
40205 - 0 0 0 0 0 0 0 0 0 0 0 0
40206 - 0 0 0 0 0 0 0 0 0 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 10 10 10
40208 - 30 30 30 78 78 78 50 50 50 104 69 6
40209 -192 133 9 216 158 10 236 178 12 236 186 11
40210 -232 195 16 241 208 19 244 214 54 245 215 43
40211 -246 215 20 246 215 20 241 208 19 198 155 10
40212 -200 144 11 216 158 10 156 118 10 2 2 6
40213 - 2 2 6 2 2 6 2 2 6 2 2 6
40214 - 6 6 6 90 90 90 54 54 54 18 18 18
40215 - 6 6 6 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 0 0 0 0 0 0
40218 - 0 0 0 0 0 0 0 0 0 0 0 0
40219 - 0 0 0 0 0 0 0 0 0 0 0 0
40220 - 0 0 0 0 0 0 0 0 0 0 0 0
40221 - 0 0 0 0 0 0 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 0 0 0 0 0 0
40225 - 0 0 0 0 0 0 0 0 0 0 0 0
40226 - 0 0 0 0 0 0 0 0 0 0 0 0
40227 - 0 0 0 0 0 0 0 0 0 10 10 10
40228 - 30 30 30 78 78 78 46 46 46 22 22 22
40229 -137 92 6 210 162 10 239 182 13 238 190 10
40230 -238 202 15 241 208 19 246 215 20 246 215 20
40231 -241 208 19 203 166 17 185 133 11 210 150 10
40232 -216 158 10 210 150 10 102 78 10 2 2 6
40233 - 6 6 6 54 54 54 14 14 14 2 2 6
40234 - 2 2 6 62 62 62 74 74 74 30 30 30
40235 - 10 10 10 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 0 0 0 0 0 0
40238 - 0 0 0 0 0 0 0 0 0 0 0 0
40239 - 0 0 0 0 0 0 0 0 0 0 0 0
40240 - 0 0 0 0 0 0 0 0 0 0 0 0
40241 - 0 0 0 0 0 0 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 0 0 0 0 0 0
40245 - 0 0 0 0 0 0 0 0 0 0 0 0
40246 - 0 0 0 0 0 0 0 0 0 0 0 0
40247 - 0 0 0 0 0 0 0 0 0 10 10 10
40248 - 34 34 34 78 78 78 50 50 50 6 6 6
40249 - 94 70 30 139 102 15 190 146 13 226 184 13
40250 -232 200 30 232 195 16 215 174 15 190 146 13
40251 -168 122 10 192 133 9 210 150 10 213 154 11
40252 -202 150 34 182 157 106 101 98 89 2 2 6
40253 - 2 2 6 78 78 78 116 116 116 58 58 58
40254 - 2 2 6 22 22 22 90 90 90 46 46 46
40255 - 18 18 18 6 6 6 0 0 0 0 0 0
40256 - 0 0 0 0 0 0 0 0 0 0 0 0
40257 - 0 0 0 0 0 0 0 0 0 0 0 0
40258 - 0 0 0 0 0 0 0 0 0 0 0 0
40259 - 0 0 0 0 0 0 0 0 0 0 0 0
40260 - 0 0 0 0 0 0 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 0 0 0 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 0 0 0 0 0 0 0 0 0
40265 - 0 0 0 0 0 0 0 0 0 0 0 0
40266 - 0 0 0 0 0 0 0 0 0 0 0 0
40267 - 0 0 0 0 0 0 0 0 0 10 10 10
40268 - 38 38 38 86 86 86 50 50 50 6 6 6
40269 -128 128 128 174 154 114 156 107 11 168 122 10
40270 -198 155 10 184 144 12 197 138 11 200 144 11
40271 -206 145 10 206 145 10 197 138 11 188 164 115
40272 -195 195 195 198 198 198 174 174 174 14 14 14
40273 - 2 2 6 22 22 22 116 116 116 116 116 116
40274 - 22 22 22 2 2 6 74 74 74 70 70 70
40275 - 30 30 30 10 10 10 0 0 0 0 0 0
40276 - 0 0 0 0 0 0 0 0 0 0 0 0
40277 - 0 0 0 0 0 0 0 0 0 0 0 0
40278 - 0 0 0 0 0 0 0 0 0 0 0 0
40279 - 0 0 0 0 0 0 0 0 0 0 0 0
40280 - 0 0 0 0 0 0 0 0 0 0 0 0
40281 - 0 0 0 0 0 0 0 0 0 0 0 0
40282 - 0 0 0 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 0 0 0
40284 - 0 0 0 0 0 0 0 0 0 0 0 0
40285 - 0 0 0 0 0 0 0 0 0 0 0 0
40286 - 0 0 0 0 0 0 0 0 0 0 0 0
40287 - 0 0 0 0 0 0 6 6 6 18 18 18
40288 - 50 50 50 101 101 101 26 26 26 10 10 10
40289 -138 138 138 190 190 190 174 154 114 156 107 11
40290 -197 138 11 200 144 11 197 138 11 192 133 9
40291 -180 123 7 190 142 34 190 178 144 187 187 187
40292 -202 202 202 221 221 221 214 214 214 66 66 66
40293 - 2 2 6 2 2 6 50 50 50 62 62 62
40294 - 6 6 6 2 2 6 10 10 10 90 90 90
40295 - 50 50 50 18 18 18 6 6 6 0 0 0
40296 - 0 0 0 0 0 0 0 0 0 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 0 0 0
40298 - 0 0 0 0 0 0 0 0 0 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 0 0 0 0 0 0
40301 - 0 0 0 0 0 0 0 0 0 0 0 0
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 0 0 0
40304 - 0 0 0 0 0 0 0 0 0 0 0 0
40305 - 0 0 0 0 0 0 0 0 0 0 0 0
40306 - 0 0 0 0 0 0 0 0 0 0 0 0
40307 - 0 0 0 0 0 0 10 10 10 34 34 34
40308 - 74 74 74 74 74 74 2 2 6 6 6 6
40309 -144 144 144 198 198 198 190 190 190 178 166 146
40310 -154 121 60 156 107 11 156 107 11 168 124 44
40311 -174 154 114 187 187 187 190 190 190 210 210 210
40312 -246 246 246 253 253 253 253 253 253 182 182 182
40313 - 6 6 6 2 2 6 2 2 6 2 2 6
40314 - 2 2 6 2 2 6 2 2 6 62 62 62
40315 - 74 74 74 34 34 34 14 14 14 0 0 0
40316 - 0 0 0 0 0 0 0 0 0 0 0 0
40317 - 0 0 0 0 0 0 0 0 0 0 0 0
40318 - 0 0 0 0 0 0 0 0 0 0 0 0
40319 - 0 0 0 0 0 0 0 0 0 0 0 0
40320 - 0 0 0 0 0 0 0 0 0 0 0 0
40321 - 0 0 0 0 0 0 0 0 0 0 0 0
40322 - 0 0 0 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 0 0 0
40324 - 0 0 0 0 0 0 0 0 0 0 0 0
40325 - 0 0 0 0 0 0 0 0 0 0 0 0
40326 - 0 0 0 0 0 0 0 0 0 0 0 0
40327 - 0 0 0 10 10 10 22 22 22 54 54 54
40328 - 94 94 94 18 18 18 2 2 6 46 46 46
40329 -234 234 234 221 221 221 190 190 190 190 190 190
40330 -190 190 190 187 187 187 187 187 187 190 190 190
40331 -190 190 190 195 195 195 214 214 214 242 242 242
40332 -253 253 253 253 253 253 253 253 253 253 253 253
40333 - 82 82 82 2 2 6 2 2 6 2 2 6
40334 - 2 2 6 2 2 6 2 2 6 14 14 14
40335 - 86 86 86 54 54 54 22 22 22 6 6 6
40336 - 0 0 0 0 0 0 0 0 0 0 0 0
40337 - 0 0 0 0 0 0 0 0 0 0 0 0
40338 - 0 0 0 0 0 0 0 0 0 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 0 0 0 0 0 0 0 0 0 0 0 0
40341 - 0 0 0 0 0 0 0 0 0 0 0 0
40342 - 0 0 0 0 0 0 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 0 0 0
40344 - 0 0 0 0 0 0 0 0 0 0 0 0
40345 - 0 0 0 0 0 0 0 0 0 0 0 0
40346 - 0 0 0 0 0 0 0 0 0 0 0 0
40347 - 6 6 6 18 18 18 46 46 46 90 90 90
40348 - 46 46 46 18 18 18 6 6 6 182 182 182
40349 -253 253 253 246 246 246 206 206 206 190 190 190
40350 -190 190 190 190 190 190 190 190 190 190 190 190
40351 -206 206 206 231 231 231 250 250 250 253 253 253
40352 -253 253 253 253 253 253 253 253 253 253 253 253
40353 -202 202 202 14 14 14 2 2 6 2 2 6
40354 - 2 2 6 2 2 6 2 2 6 2 2 6
40355 - 42 42 42 86 86 86 42 42 42 18 18 18
40356 - 6 6 6 0 0 0 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 0 0 0 0
40358 - 0 0 0 0 0 0 0 0 0 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 0 0 0 0 0 0 0 0 0 0 0 0
40361 - 0 0 0 0 0 0 0 0 0 0 0 0
40362 - 0 0 0 0 0 0 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 0 0 0
40364 - 0 0 0 0 0 0 0 0 0 0 0 0
40365 - 0 0 0 0 0 0 0 0 0 0 0 0
40366 - 0 0 0 0 0 0 0 0 0 6 6 6
40367 - 14 14 14 38 38 38 74 74 74 66 66 66
40368 - 2 2 6 6 6 6 90 90 90 250 250 250
40369 -253 253 253 253 253 253 238 238 238 198 198 198
40370 -190 190 190 190 190 190 195 195 195 221 221 221
40371 -246 246 246 253 253 253 253 253 253 253 253 253
40372 -253 253 253 253 253 253 253 253 253 253 253 253
40373 -253 253 253 82 82 82 2 2 6 2 2 6
40374 - 2 2 6 2 2 6 2 2 6 2 2 6
40375 - 2 2 6 78 78 78 70 70 70 34 34 34
40376 - 14 14 14 6 6 6 0 0 0 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 0 0 0 0 0 0 0 0 0
40381 - 0 0 0 0 0 0 0 0 0 0 0 0
40382 - 0 0 0 0 0 0 0 0 0 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 0 0 0
40384 - 0 0 0 0 0 0 0 0 0 0 0 0
40385 - 0 0 0 0 0 0 0 0 0 0 0 0
40386 - 0 0 0 0 0 0 0 0 0 14 14 14
40387 - 34 34 34 66 66 66 78 78 78 6 6 6
40388 - 2 2 6 18 18 18 218 218 218 253 253 253
40389 -253 253 253 253 253 253 253 253 253 246 246 246
40390 -226 226 226 231 231 231 246 246 246 253 253 253
40391 -253 253 253 253 253 253 253 253 253 253 253 253
40392 -253 253 253 253 253 253 253 253 253 253 253 253
40393 -253 253 253 178 178 178 2 2 6 2 2 6
40394 - 2 2 6 2 2 6 2 2 6 2 2 6
40395 - 2 2 6 18 18 18 90 90 90 62 62 62
40396 - 30 30 30 10 10 10 0 0 0 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 0 0 0
40400 - 0 0 0 0 0 0 0 0 0 0 0 0
40401 - 0 0 0 0 0 0 0 0 0 0 0 0
40402 - 0 0 0 0 0 0 0 0 0 0 0 0
40403 - 0 0 0 0 0 0 0 0 0 0 0 0
40404 - 0 0 0 0 0 0 0 0 0 0 0 0
40405 - 0 0 0 0 0 0 0 0 0 0 0 0
40406 - 0 0 0 0 0 0 10 10 10 26 26 26
40407 - 58 58 58 90 90 90 18 18 18 2 2 6
40408 - 2 2 6 110 110 110 253 253 253 253 253 253
40409 -253 253 253 253 253 253 253 253 253 253 253 253
40410 -250 250 250 253 253 253 253 253 253 253 253 253
40411 -253 253 253 253 253 253 253 253 253 253 253 253
40412 -253 253 253 253 253 253 253 253 253 253 253 253
40413 -253 253 253 231 231 231 18 18 18 2 2 6
40414 - 2 2 6 2 2 6 2 2 6 2 2 6
40415 - 2 2 6 2 2 6 18 18 18 94 94 94
40416 - 54 54 54 26 26 26 10 10 10 0 0 0
40417 - 0 0 0 0 0 0 0 0 0 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 0 0 0 0 0 0
40420 - 0 0 0 0 0 0 0 0 0 0 0 0
40421 - 0 0 0 0 0 0 0 0 0 0 0 0
40422 - 0 0 0 0 0 0 0 0 0 0 0 0
40423 - 0 0 0 0 0 0 0 0 0 0 0 0
40424 - 0 0 0 0 0 0 0 0 0 0 0 0
40425 - 0 0 0 0 0 0 0 0 0 0 0 0
40426 - 0 0 0 6 6 6 22 22 22 50 50 50
40427 - 90 90 90 26 26 26 2 2 6 2 2 6
40428 - 14 14 14 195 195 195 250 250 250 253 253 253
40429 -253 253 253 253 253 253 253 253 253 253 253 253
40430 -253 253 253 253 253 253 253 253 253 253 253 253
40431 -253 253 253 253 253 253 253 253 253 253 253 253
40432 -253 253 253 253 253 253 253 253 253 253 253 253
40433 -250 250 250 242 242 242 54 54 54 2 2 6
40434 - 2 2 6 2 2 6 2 2 6 2 2 6
40435 - 2 2 6 2 2 6 2 2 6 38 38 38
40436 - 86 86 86 50 50 50 22 22 22 6 6 6
40437 - 0 0 0 0 0 0 0 0 0 0 0 0
40438 - 0 0 0 0 0 0 0 0 0 0 0 0
40439 - 0 0 0 0 0 0 0 0 0 0 0 0
40440 - 0 0 0 0 0 0 0 0 0 0 0 0
40441 - 0 0 0 0 0 0 0 0 0 0 0 0
40442 - 0 0 0 0 0 0 0 0 0 0 0 0
40443 - 0 0 0 0 0 0 0 0 0 0 0 0
40444 - 0 0 0 0 0 0 0 0 0 0 0 0
40445 - 0 0 0 0 0 0 0 0 0 0 0 0
40446 - 6 6 6 14 14 14 38 38 38 82 82 82
40447 - 34 34 34 2 2 6 2 2 6 2 2 6
40448 - 42 42 42 195 195 195 246 246 246 253 253 253
40449 -253 253 253 253 253 253 253 253 253 250 250 250
40450 -242 242 242 242 242 242 250 250 250 253 253 253
40451 -253 253 253 253 253 253 253 253 253 253 253 253
40452 -253 253 253 250 250 250 246 246 246 238 238 238
40453 -226 226 226 231 231 231 101 101 101 6 6 6
40454 - 2 2 6 2 2 6 2 2 6 2 2 6
40455 - 2 2 6 2 2 6 2 2 6 2 2 6
40456 - 38 38 38 82 82 82 42 42 42 14 14 14
40457 - 6 6 6 0 0 0 0 0 0 0 0 0
40458 - 0 0 0 0 0 0 0 0 0 0 0 0
40459 - 0 0 0 0 0 0 0 0 0 0 0 0
40460 - 0 0 0 0 0 0 0 0 0 0 0 0
40461 - 0 0 0 0 0 0 0 0 0 0 0 0
40462 - 0 0 0 0 0 0 0 0 0 0 0 0
40463 - 0 0 0 0 0 0 0 0 0 0 0 0
40464 - 0 0 0 0 0 0 0 0 0 0 0 0
40465 - 0 0 0 0 0 0 0 0 0 0 0 0
40466 - 10 10 10 26 26 26 62 62 62 66 66 66
40467 - 2 2 6 2 2 6 2 2 6 6 6 6
40468 - 70 70 70 170 170 170 206 206 206 234 234 234
40469 -246 246 246 250 250 250 250 250 250 238 238 238
40470 -226 226 226 231 231 231 238 238 238 250 250 250
40471 -250 250 250 250 250 250 246 246 246 231 231 231
40472 -214 214 214 206 206 206 202 202 202 202 202 202
40473 -198 198 198 202 202 202 182 182 182 18 18 18
40474 - 2 2 6 2 2 6 2 2 6 2 2 6
40475 - 2 2 6 2 2 6 2 2 6 2 2 6
40476 - 2 2 6 62 62 62 66 66 66 30 30 30
40477 - 10 10 10 0 0 0 0 0 0 0 0 0
40478 - 0 0 0 0 0 0 0 0 0 0 0 0
40479 - 0 0 0 0 0 0 0 0 0 0 0 0
40480 - 0 0 0 0 0 0 0 0 0 0 0 0
40481 - 0 0 0 0 0 0 0 0 0 0 0 0
40482 - 0 0 0 0 0 0 0 0 0 0 0 0
40483 - 0 0 0 0 0 0 0 0 0 0 0 0
40484 - 0 0 0 0 0 0 0 0 0 0 0 0
40485 - 0 0 0 0 0 0 0 0 0 0 0 0
40486 - 14 14 14 42 42 42 82 82 82 18 18 18
40487 - 2 2 6 2 2 6 2 2 6 10 10 10
40488 - 94 94 94 182 182 182 218 218 218 242 242 242
40489 -250 250 250 253 253 253 253 253 253 250 250 250
40490 -234 234 234 253 253 253 253 253 253 253 253 253
40491 -253 253 253 253 253 253 253 253 253 246 246 246
40492 -238 238 238 226 226 226 210 210 210 202 202 202
40493 -195 195 195 195 195 195 210 210 210 158 158 158
40494 - 6 6 6 14 14 14 50 50 50 14 14 14
40495 - 2 2 6 2 2 6 2 2 6 2 2 6
40496 - 2 2 6 6 6 6 86 86 86 46 46 46
40497 - 18 18 18 6 6 6 0 0 0 0 0 0
40498 - 0 0 0 0 0 0 0 0 0 0 0 0
40499 - 0 0 0 0 0 0 0 0 0 0 0 0
40500 - 0 0 0 0 0 0 0 0 0 0 0 0
40501 - 0 0 0 0 0 0 0 0 0 0 0 0
40502 - 0 0 0 0 0 0 0 0 0 0 0 0
40503 - 0 0 0 0 0 0 0 0 0 0 0 0
40504 - 0 0 0 0 0 0 0 0 0 0 0 0
40505 - 0 0 0 0 0 0 0 0 0 6 6 6
40506 - 22 22 22 54 54 54 70 70 70 2 2 6
40507 - 2 2 6 10 10 10 2 2 6 22 22 22
40508 -166 166 166 231 231 231 250 250 250 253 253 253
40509 -253 253 253 253 253 253 253 253 253 250 250 250
40510 -242 242 242 253 253 253 253 253 253 253 253 253
40511 -253 253 253 253 253 253 253 253 253 253 253 253
40512 -253 253 253 253 253 253 253 253 253 246 246 246
40513 -231 231 231 206 206 206 198 198 198 226 226 226
40514 - 94 94 94 2 2 6 6 6 6 38 38 38
40515 - 30 30 30 2 2 6 2 2 6 2 2 6
40516 - 2 2 6 2 2 6 62 62 62 66 66 66
40517 - 26 26 26 10 10 10 0 0 0 0 0 0
40518 - 0 0 0 0 0 0 0 0 0 0 0 0
40519 - 0 0 0 0 0 0 0 0 0 0 0 0
40520 - 0 0 0 0 0 0 0 0 0 0 0 0
40521 - 0 0 0 0 0 0 0 0 0 0 0 0
40522 - 0 0 0 0 0 0 0 0 0 0 0 0
40523 - 0 0 0 0 0 0 0 0 0 0 0 0
40524 - 0 0 0 0 0 0 0 0 0 0 0 0
40525 - 0 0 0 0 0 0 0 0 0 10 10 10
40526 - 30 30 30 74 74 74 50 50 50 2 2 6
40527 - 26 26 26 26 26 26 2 2 6 106 106 106
40528 -238 238 238 253 253 253 253 253 253 253 253 253
40529 -253 253 253 253 253 253 253 253 253 253 253 253
40530 -253 253 253 253 253 253 253 253 253 253 253 253
40531 -253 253 253 253 253 253 253 253 253 253 253 253
40532 -253 253 253 253 253 253 253 253 253 253 253 253
40533 -253 253 253 246 246 246 218 218 218 202 202 202
40534 -210 210 210 14 14 14 2 2 6 2 2 6
40535 - 30 30 30 22 22 22 2 2 6 2 2 6
40536 - 2 2 6 2 2 6 18 18 18 86 86 86
40537 - 42 42 42 14 14 14 0 0 0 0 0 0
40538 - 0 0 0 0 0 0 0 0 0 0 0 0
40539 - 0 0 0 0 0 0 0 0 0 0 0 0
40540 - 0 0 0 0 0 0 0 0 0 0 0 0
40541 - 0 0 0 0 0 0 0 0 0 0 0 0
40542 - 0 0 0 0 0 0 0 0 0 0 0 0
40543 - 0 0 0 0 0 0 0 0 0 0 0 0
40544 - 0 0 0 0 0 0 0 0 0 0 0 0
40545 - 0 0 0 0 0 0 0 0 0 14 14 14
40546 - 42 42 42 90 90 90 22 22 22 2 2 6
40547 - 42 42 42 2 2 6 18 18 18 218 218 218
40548 -253 253 253 253 253 253 253 253 253 253 253 253
40549 -253 253 253 253 253 253 253 253 253 253 253 253
40550 -253 253 253 253 253 253 253 253 253 253 253 253
40551 -253 253 253 253 253 253 253 253 253 253 253 253
40552 -253 253 253 253 253 253 253 253 253 253 253 253
40553 -253 253 253 253 253 253 250 250 250 221 221 221
40554 -218 218 218 101 101 101 2 2 6 14 14 14
40555 - 18 18 18 38 38 38 10 10 10 2 2 6
40556 - 2 2 6 2 2 6 2 2 6 78 78 78
40557 - 58 58 58 22 22 22 6 6 6 0 0 0
40558 - 0 0 0 0 0 0 0 0 0 0 0 0
40559 - 0 0 0 0 0 0 0 0 0 0 0 0
40560 - 0 0 0 0 0 0 0 0 0 0 0 0
40561 - 0 0 0 0 0 0 0 0 0 0 0 0
40562 - 0 0 0 0 0 0 0 0 0 0 0 0
40563 - 0 0 0 0 0 0 0 0 0 0 0 0
40564 - 0 0 0 0 0 0 0 0 0 0 0 0
40565 - 0 0 0 0 0 0 6 6 6 18 18 18
40566 - 54 54 54 82 82 82 2 2 6 26 26 26
40567 - 22 22 22 2 2 6 123 123 123 253 253 253
40568 -253 253 253 253 253 253 253 253 253 253 253 253
40569 -253 253 253 253 253 253 253 253 253 253 253 253
40570 -253 253 253 253 253 253 253 253 253 253 253 253
40571 -253 253 253 253 253 253 253 253 253 253 253 253
40572 -253 253 253 253 253 253 253 253 253 253 253 253
40573 -253 253 253 253 253 253 253 253 253 250 250 250
40574 -238 238 238 198 198 198 6 6 6 38 38 38
40575 - 58 58 58 26 26 26 38 38 38 2 2 6
40576 - 2 2 6 2 2 6 2 2 6 46 46 46
40577 - 78 78 78 30 30 30 10 10 10 0 0 0
40578 - 0 0 0 0 0 0 0 0 0 0 0 0
40579 - 0 0 0 0 0 0 0 0 0 0 0 0
40580 - 0 0 0 0 0 0 0 0 0 0 0 0
40581 - 0 0 0 0 0 0 0 0 0 0 0 0
40582 - 0 0 0 0 0 0 0 0 0 0 0 0
40583 - 0 0 0 0 0 0 0 0 0 0 0 0
40584 - 0 0 0 0 0 0 0 0 0 0 0 0
40585 - 0 0 0 0 0 0 10 10 10 30 30 30
40586 - 74 74 74 58 58 58 2 2 6 42 42 42
40587 - 2 2 6 22 22 22 231 231 231 253 253 253
40588 -253 253 253 253 253 253 253 253 253 253 253 253
40589 -253 253 253 253 253 253 253 253 253 250 250 250
40590 -253 253 253 253 253 253 253 253 253 253 253 253
40591 -253 253 253 253 253 253 253 253 253 253 253 253
40592 -253 253 253 253 253 253 253 253 253 253 253 253
40593 -253 253 253 253 253 253 253 253 253 253 253 253
40594 -253 253 253 246 246 246 46 46 46 38 38 38
40595 - 42 42 42 14 14 14 38 38 38 14 14 14
40596 - 2 2 6 2 2 6 2 2 6 6 6 6
40597 - 86 86 86 46 46 46 14 14 14 0 0 0
40598 - 0 0 0 0 0 0 0 0 0 0 0 0
40599 - 0 0 0 0 0 0 0 0 0 0 0 0
40600 - 0 0 0 0 0 0 0 0 0 0 0 0
40601 - 0 0 0 0 0 0 0 0 0 0 0 0
40602 - 0 0 0 0 0 0 0 0 0 0 0 0
40603 - 0 0 0 0 0 0 0 0 0 0 0 0
40604 - 0 0 0 0 0 0 0 0 0 0 0 0
40605 - 0 0 0 6 6 6 14 14 14 42 42 42
40606 - 90 90 90 18 18 18 18 18 18 26 26 26
40607 - 2 2 6 116 116 116 253 253 253 253 253 253
40608 -253 253 253 253 253 253 253 253 253 253 253 253
40609 -253 253 253 253 253 253 250 250 250 238 238 238
40610 -253 253 253 253 253 253 253 253 253 253 253 253
40611 -253 253 253 253 253 253 253 253 253 253 253 253
40612 -253 253 253 253 253 253 253 253 253 253 253 253
40613 -253 253 253 253 253 253 253 253 253 253 253 253
40614 -253 253 253 253 253 253 94 94 94 6 6 6
40615 - 2 2 6 2 2 6 10 10 10 34 34 34
40616 - 2 2 6 2 2 6 2 2 6 2 2 6
40617 - 74 74 74 58 58 58 22 22 22 6 6 6
40618 - 0 0 0 0 0 0 0 0 0 0 0 0
40619 - 0 0 0 0 0 0 0 0 0 0 0 0
40620 - 0 0 0 0 0 0 0 0 0 0 0 0
40621 - 0 0 0 0 0 0 0 0 0 0 0 0
40622 - 0 0 0 0 0 0 0 0 0 0 0 0
40623 - 0 0 0 0 0 0 0 0 0 0 0 0
40624 - 0 0 0 0 0 0 0 0 0 0 0 0
40625 - 0 0 0 10 10 10 26 26 26 66 66 66
40626 - 82 82 82 2 2 6 38 38 38 6 6 6
40627 - 14 14 14 210 210 210 253 253 253 253 253 253
40628 -253 253 253 253 253 253 253 253 253 253 253 253
40629 -253 253 253 253 253 253 246 246 246 242 242 242
40630 -253 253 253 253 253 253 253 253 253 253 253 253
40631 -253 253 253 253 253 253 253 253 253 253 253 253
40632 -253 253 253 253 253 253 253 253 253 253 253 253
40633 -253 253 253 253 253 253 253 253 253 253 253 253
40634 -253 253 253 253 253 253 144 144 144 2 2 6
40635 - 2 2 6 2 2 6 2 2 6 46 46 46
40636 - 2 2 6 2 2 6 2 2 6 2 2 6
40637 - 42 42 42 74 74 74 30 30 30 10 10 10
40638 - 0 0 0 0 0 0 0 0 0 0 0 0
40639 - 0 0 0 0 0 0 0 0 0 0 0 0
40640 - 0 0 0 0 0 0 0 0 0 0 0 0
40641 - 0 0 0 0 0 0 0 0 0 0 0 0
40642 - 0 0 0 0 0 0 0 0 0 0 0 0
40643 - 0 0 0 0 0 0 0 0 0 0 0 0
40644 - 0 0 0 0 0 0 0 0 0 0 0 0
40645 - 6 6 6 14 14 14 42 42 42 90 90 90
40646 - 26 26 26 6 6 6 42 42 42 2 2 6
40647 - 74 74 74 250 250 250 253 253 253 253 253 253
40648 -253 253 253 253 253 253 253 253 253 253 253 253
40649 -253 253 253 253 253 253 242 242 242 242 242 242
40650 -253 253 253 253 253 253 253 253 253 253 253 253
40651 -253 253 253 253 253 253 253 253 253 253 253 253
40652 -253 253 253 253 253 253 253 253 253 253 253 253
40653 -253 253 253 253 253 253 253 253 253 253 253 253
40654 -253 253 253 253 253 253 182 182 182 2 2 6
40655 - 2 2 6 2 2 6 2 2 6 46 46 46
40656 - 2 2 6 2 2 6 2 2 6 2 2 6
40657 - 10 10 10 86 86 86 38 38 38 10 10 10
40658 - 0 0 0 0 0 0 0 0 0 0 0 0
40659 - 0 0 0 0 0 0 0 0 0 0 0 0
40660 - 0 0 0 0 0 0 0 0 0 0 0 0
40661 - 0 0 0 0 0 0 0 0 0 0 0 0
40662 - 0 0 0 0 0 0 0 0 0 0 0 0
40663 - 0 0 0 0 0 0 0 0 0 0 0 0
40664 - 0 0 0 0 0 0 0 0 0 0 0 0
40665 - 10 10 10 26 26 26 66 66 66 82 82 82
40666 - 2 2 6 22 22 22 18 18 18 2 2 6
40667 -149 149 149 253 253 253 253 253 253 253 253 253
40668 -253 253 253 253 253 253 253 253 253 253 253 253
40669 -253 253 253 253 253 253 234 234 234 242 242 242
40670 -253 253 253 253 253 253 253 253 253 253 253 253
40671 -253 253 253 253 253 253 253 253 253 253 253 253
40672 -253 253 253 253 253 253 253 253 253 253 253 253
40673 -253 253 253 253 253 253 253 253 253 253 253 253
40674 -253 253 253 253 253 253 206 206 206 2 2 6
40675 - 2 2 6 2 2 6 2 2 6 38 38 38
40676 - 2 2 6 2 2 6 2 2 6 2 2 6
40677 - 6 6 6 86 86 86 46 46 46 14 14 14
40678 - 0 0 0 0 0 0 0 0 0 0 0 0
40679 - 0 0 0 0 0 0 0 0 0 0 0 0
40680 - 0 0 0 0 0 0 0 0 0 0 0 0
40681 - 0 0 0 0 0 0 0 0 0 0 0 0
40682 - 0 0 0 0 0 0 0 0 0 0 0 0
40683 - 0 0 0 0 0 0 0 0 0 0 0 0
40684 - 0 0 0 0 0 0 0 0 0 6 6 6
40685 - 18 18 18 46 46 46 86 86 86 18 18 18
40686 - 2 2 6 34 34 34 10 10 10 6 6 6
40687 -210 210 210 253 253 253 253 253 253 253 253 253
40688 -253 253 253 253 253 253 253 253 253 253 253 253
40689 -253 253 253 253 253 253 234 234 234 242 242 242
40690 -253 253 253 253 253 253 253 253 253 253 253 253
40691 -253 253 253 253 253 253 253 253 253 253 253 253
40692 -253 253 253 253 253 253 253 253 253 253 253 253
40693 -253 253 253 253 253 253 253 253 253 253 253 253
40694 -253 253 253 253 253 253 221 221 221 6 6 6
40695 - 2 2 6 2 2 6 6 6 6 30 30 30
40696 - 2 2 6 2 2 6 2 2 6 2 2 6
40697 - 2 2 6 82 82 82 54 54 54 18 18 18
40698 - 6 6 6 0 0 0 0 0 0 0 0 0
40699 - 0 0 0 0 0 0 0 0 0 0 0 0
40700 - 0 0 0 0 0 0 0 0 0 0 0 0
40701 - 0 0 0 0 0 0 0 0 0 0 0 0
40702 - 0 0 0 0 0 0 0 0 0 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 10 10 10
40705 - 26 26 26 66 66 66 62 62 62 2 2 6
40706 - 2 2 6 38 38 38 10 10 10 26 26 26
40707 -238 238 238 253 253 253 253 253 253 253 253 253
40708 -253 253 253 253 253 253 253 253 253 253 253 253
40709 -253 253 253 253 253 253 231 231 231 238 238 238
40710 -253 253 253 253 253 253 253 253 253 253 253 253
40711 -253 253 253 253 253 253 253 253 253 253 253 253
40712 -253 253 253 253 253 253 253 253 253 253 253 253
40713 -253 253 253 253 253 253 253 253 253 253 253 253
40714 -253 253 253 253 253 253 231 231 231 6 6 6
40715 - 2 2 6 2 2 6 10 10 10 30 30 30
40716 - 2 2 6 2 2 6 2 2 6 2 2 6
40717 - 2 2 6 66 66 66 58 58 58 22 22 22
40718 - 6 6 6 0 0 0 0 0 0 0 0 0
40719 - 0 0 0 0 0 0 0 0 0 0 0 0
40720 - 0 0 0 0 0 0 0 0 0 0 0 0
40721 - 0 0 0 0 0 0 0 0 0 0 0 0
40722 - 0 0 0 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 10 10 10
40725 - 38 38 38 78 78 78 6 6 6 2 2 6
40726 - 2 2 6 46 46 46 14 14 14 42 42 42
40727 -246 246 246 253 253 253 253 253 253 253 253 253
40728 -253 253 253 253 253 253 253 253 253 253 253 253
40729 -253 253 253 253 253 253 231 231 231 242 242 242
40730 -253 253 253 253 253 253 253 253 253 253 253 253
40731 -253 253 253 253 253 253 253 253 253 253 253 253
40732 -253 253 253 253 253 253 253 253 253 253 253 253
40733 -253 253 253 253 253 253 253 253 253 253 253 253
40734 -253 253 253 253 253 253 234 234 234 10 10 10
40735 - 2 2 6 2 2 6 22 22 22 14 14 14
40736 - 2 2 6 2 2 6 2 2 6 2 2 6
40737 - 2 2 6 66 66 66 62 62 62 22 22 22
40738 - 6 6 6 0 0 0 0 0 0 0 0 0
40739 - 0 0 0 0 0 0 0 0 0 0 0 0
40740 - 0 0 0 0 0 0 0 0 0 0 0 0
40741 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
40745 - 50 50 50 74 74 74 2 2 6 2 2 6
40746 - 14 14 14 70 70 70 34 34 34 62 62 62
40747 -250 250 250 253 253 253 253 253 253 253 253 253
40748 -253 253 253 253 253 253 253 253 253 253 253 253
40749 -253 253 253 253 253 253 231 231 231 246 246 246
40750 -253 253 253 253 253 253 253 253 253 253 253 253
40751 -253 253 253 253 253 253 253 253 253 253 253 253
40752 -253 253 253 253 253 253 253 253 253 253 253 253
40753 -253 253 253 253 253 253 253 253 253 253 253 253
40754 -253 253 253 253 253 253 234 234 234 14 14 14
40755 - 2 2 6 2 2 6 30 30 30 2 2 6
40756 - 2 2 6 2 2 6 2 2 6 2 2 6
40757 - 2 2 6 66 66 66 62 62 62 22 22 22
40758 - 6 6 6 0 0 0 0 0 0 0 0 0
40759 - 0 0 0 0 0 0 0 0 0 0 0 0
40760 - 0 0 0 0 0 0 0 0 0 0 0 0
40761 - 0 0 0 0 0 0 0 0 0 0 0 0
40762 - 0 0 0 0 0 0 0 0 0 0 0 0
40763 - 0 0 0 0 0 0 0 0 0 0 0 0
40764 - 0 0 0 0 0 0 6 6 6 18 18 18
40765 - 54 54 54 62 62 62 2 2 6 2 2 6
40766 - 2 2 6 30 30 30 46 46 46 70 70 70
40767 -250 250 250 253 253 253 253 253 253 253 253 253
40768 -253 253 253 253 253 253 253 253 253 253 253 253
40769 -253 253 253 253 253 253 231 231 231 246 246 246
40770 -253 253 253 253 253 253 253 253 253 253 253 253
40771 -253 253 253 253 253 253 253 253 253 253 253 253
40772 -253 253 253 253 253 253 253 253 253 253 253 253
40773 -253 253 253 253 253 253 253 253 253 253 253 253
40774 -253 253 253 253 253 253 226 226 226 10 10 10
40775 - 2 2 6 6 6 6 30 30 30 2 2 6
40776 - 2 2 6 2 2 6 2 2 6 2 2 6
40777 - 2 2 6 66 66 66 58 58 58 22 22 22
40778 - 6 6 6 0 0 0 0 0 0 0 0 0
40779 - 0 0 0 0 0 0 0 0 0 0 0 0
40780 - 0 0 0 0 0 0 0 0 0 0 0 0
40781 - 0 0 0 0 0 0 0 0 0 0 0 0
40782 - 0 0 0 0 0 0 0 0 0 0 0 0
40783 - 0 0 0 0 0 0 0 0 0 0 0 0
40784 - 0 0 0 0 0 0 6 6 6 22 22 22
40785 - 58 58 58 62 62 62 2 2 6 2 2 6
40786 - 2 2 6 2 2 6 30 30 30 78 78 78
40787 -250 250 250 253 253 253 253 253 253 253 253 253
40788 -253 253 253 253 253 253 253 253 253 253 253 253
40789 -253 253 253 253 253 253 231 231 231 246 246 246
40790 -253 253 253 253 253 253 253 253 253 253 253 253
40791 -253 253 253 253 253 253 253 253 253 253 253 253
40792 -253 253 253 253 253 253 253 253 253 253 253 253
40793 -253 253 253 253 253 253 253 253 253 253 253 253
40794 -253 253 253 253 253 253 206 206 206 2 2 6
40795 - 22 22 22 34 34 34 18 14 6 22 22 22
40796 - 26 26 26 18 18 18 6 6 6 2 2 6
40797 - 2 2 6 82 82 82 54 54 54 18 18 18
40798 - 6 6 6 0 0 0 0 0 0 0 0 0
40799 - 0 0 0 0 0 0 0 0 0 0 0 0
40800 - 0 0 0 0 0 0 0 0 0 0 0 0
40801 - 0 0 0 0 0 0 0 0 0 0 0 0
40802 - 0 0 0 0 0 0 0 0 0 0 0 0
40803 - 0 0 0 0 0 0 0 0 0 0 0 0
40804 - 0 0 0 0 0 0 6 6 6 26 26 26
40805 - 62 62 62 106 106 106 74 54 14 185 133 11
40806 -210 162 10 121 92 8 6 6 6 62 62 62
40807 -238 238 238 253 253 253 253 253 253 253 253 253
40808 -253 253 253 253 253 253 253 253 253 253 253 253
40809 -253 253 253 253 253 253 231 231 231 246 246 246
40810 -253 253 253 253 253 253 253 253 253 253 253 253
40811 -253 253 253 253 253 253 253 253 253 253 253 253
40812 -253 253 253 253 253 253 253 253 253 253 253 253
40813 -253 253 253 253 253 253 253 253 253 253 253 253
40814 -253 253 253 253 253 253 158 158 158 18 18 18
40815 - 14 14 14 2 2 6 2 2 6 2 2 6
40816 - 6 6 6 18 18 18 66 66 66 38 38 38
40817 - 6 6 6 94 94 94 50 50 50 18 18 18
40818 - 6 6 6 0 0 0 0 0 0 0 0 0
40819 - 0 0 0 0 0 0 0 0 0 0 0 0
40820 - 0 0 0 0 0 0 0 0 0 0 0 0
40821 - 0 0 0 0 0 0 0 0 0 0 0 0
40822 - 0 0 0 0 0 0 0 0 0 0 0 0
40823 - 0 0 0 0 0 0 0 0 0 6 6 6
40824 - 10 10 10 10 10 10 18 18 18 38 38 38
40825 - 78 78 78 142 134 106 216 158 10 242 186 14
40826 -246 190 14 246 190 14 156 118 10 10 10 10
40827 - 90 90 90 238 238 238 253 253 253 253 253 253
40828 -253 253 253 253 253 253 253 253 253 253 253 253
40829 -253 253 253 253 253 253 231 231 231 250 250 250
40830 -253 253 253 253 253 253 253 253 253 253 253 253
40831 -253 253 253 253 253 253 253 253 253 253 253 253
40832 -253 253 253 253 253 253 253 253 253 253 253 253
40833 -253 253 253 253 253 253 253 253 253 246 230 190
40834 -238 204 91 238 204 91 181 142 44 37 26 9
40835 - 2 2 6 2 2 6 2 2 6 2 2 6
40836 - 2 2 6 2 2 6 38 38 38 46 46 46
40837 - 26 26 26 106 106 106 54 54 54 18 18 18
40838 - 6 6 6 0 0 0 0 0 0 0 0 0
40839 - 0 0 0 0 0 0 0 0 0 0 0 0
40840 - 0 0 0 0 0 0 0 0 0 0 0 0
40841 - 0 0 0 0 0 0 0 0 0 0 0 0
40842 - 0 0 0 0 0 0 0 0 0 0 0 0
40843 - 0 0 0 6 6 6 14 14 14 22 22 22
40844 - 30 30 30 38 38 38 50 50 50 70 70 70
40845 -106 106 106 190 142 34 226 170 11 242 186 14
40846 -246 190 14 246 190 14 246 190 14 154 114 10
40847 - 6 6 6 74 74 74 226 226 226 253 253 253
40848 -253 253 253 253 253 253 253 253 253 253 253 253
40849 -253 253 253 253 253 253 231 231 231 250 250 250
40850 -253 253 253 253 253 253 253 253 253 253 253 253
40851 -253 253 253 253 253 253 253 253 253 253 253 253
40852 -253 253 253 253 253 253 253 253 253 253 253 253
40853 -253 253 253 253 253 253 253 253 253 228 184 62
40854 -241 196 14 241 208 19 232 195 16 38 30 10
40855 - 2 2 6 2 2 6 2 2 6 2 2 6
40856 - 2 2 6 6 6 6 30 30 30 26 26 26
40857 -203 166 17 154 142 90 66 66 66 26 26 26
40858 - 6 6 6 0 0 0 0 0 0 0 0 0
40859 - 0 0 0 0 0 0 0 0 0 0 0 0
40860 - 0 0 0 0 0 0 0 0 0 0 0 0
40861 - 0 0 0 0 0 0 0 0 0 0 0 0
40862 - 0 0 0 0 0 0 0 0 0 0 0 0
40863 - 6 6 6 18 18 18 38 38 38 58 58 58
40864 - 78 78 78 86 86 86 101 101 101 123 123 123
40865 -175 146 61 210 150 10 234 174 13 246 186 14
40866 -246 190 14 246 190 14 246 190 14 238 190 10
40867 -102 78 10 2 2 6 46 46 46 198 198 198
40868 -253 253 253 253 253 253 253 253 253 253 253 253
40869 -253 253 253 253 253 253 234 234 234 242 242 242
40870 -253 253 253 253 253 253 253 253 253 253 253 253
40871 -253 253 253 253 253 253 253 253 253 253 253 253
40872 -253 253 253 253 253 253 253 253 253 253 253 253
40873 -253 253 253 253 253 253 253 253 253 224 178 62
40874 -242 186 14 241 196 14 210 166 10 22 18 6
40875 - 2 2 6 2 2 6 2 2 6 2 2 6
40876 - 2 2 6 2 2 6 6 6 6 121 92 8
40877 -238 202 15 232 195 16 82 82 82 34 34 34
40878 - 10 10 10 0 0 0 0 0 0 0 0 0
40879 - 0 0 0 0 0 0 0 0 0 0 0 0
40880 - 0 0 0 0 0 0 0 0 0 0 0 0
40881 - 0 0 0 0 0 0 0 0 0 0 0 0
40882 - 0 0 0 0 0 0 0 0 0 0 0 0
40883 - 14 14 14 38 38 38 70 70 70 154 122 46
40884 -190 142 34 200 144 11 197 138 11 197 138 11
40885 -213 154 11 226 170 11 242 186 14 246 190 14
40886 -246 190 14 246 190 14 246 190 14 246 190 14
40887 -225 175 15 46 32 6 2 2 6 22 22 22
40888 -158 158 158 250 250 250 253 253 253 253 253 253
40889 -253 253 253 253 253 253 253 253 253 253 253 253
40890 -253 253 253 253 253 253 253 253 253 253 253 253
40891 -253 253 253 253 253 253 253 253 253 253 253 253
40892 -253 253 253 253 253 253 253 253 253 253 253 253
40893 -253 253 253 250 250 250 242 242 242 224 178 62
40894 -239 182 13 236 186 11 213 154 11 46 32 6
40895 - 2 2 6 2 2 6 2 2 6 2 2 6
40896 - 2 2 6 2 2 6 61 42 6 225 175 15
40897 -238 190 10 236 186 11 112 100 78 42 42 42
40898 - 14 14 14 0 0 0 0 0 0 0 0 0
40899 - 0 0 0 0 0 0 0 0 0 0 0 0
40900 - 0 0 0 0 0 0 0 0 0 0 0 0
40901 - 0 0 0 0 0 0 0 0 0 0 0 0
40902 - 0 0 0 0 0 0 0 0 0 6 6 6
40903 - 22 22 22 54 54 54 154 122 46 213 154 11
40904 -226 170 11 230 174 11 226 170 11 226 170 11
40905 -236 178 12 242 186 14 246 190 14 246 190 14
40906 -246 190 14 246 190 14 246 190 14 246 190 14
40907 -241 196 14 184 144 12 10 10 10 2 2 6
40908 - 6 6 6 116 116 116 242 242 242 253 253 253
40909 -253 253 253 253 253 253 253 253 253 253 253 253
40910 -253 253 253 253 253 253 253 253 253 253 253 253
40911 -253 253 253 253 253 253 253 253 253 253 253 253
40912 -253 253 253 253 253 253 253 253 253 253 253 253
40913 -253 253 253 231 231 231 198 198 198 214 170 54
40914 -236 178 12 236 178 12 210 150 10 137 92 6
40915 - 18 14 6 2 2 6 2 2 6 2 2 6
40916 - 6 6 6 70 47 6 200 144 11 236 178 12
40917 -239 182 13 239 182 13 124 112 88 58 58 58
40918 - 22 22 22 6 6 6 0 0 0 0 0 0
40919 - 0 0 0 0 0 0 0 0 0 0 0 0
40920 - 0 0 0 0 0 0 0 0 0 0 0 0
40921 - 0 0 0 0 0 0 0 0 0 0 0 0
40922 - 0 0 0 0 0 0 0 0 0 10 10 10
40923 - 30 30 30 70 70 70 180 133 36 226 170 11
40924 -239 182 13 242 186 14 242 186 14 246 186 14
40925 -246 190 14 246 190 14 246 190 14 246 190 14
40926 -246 190 14 246 190 14 246 190 14 246 190 14
40927 -246 190 14 232 195 16 98 70 6 2 2 6
40928 - 2 2 6 2 2 6 66 66 66 221 221 221
40929 -253 253 253 253 253 253 253 253 253 253 253 253
40930 -253 253 253 253 253 253 253 253 253 253 253 253
40931 -253 253 253 253 253 253 253 253 253 253 253 253
40932 -253 253 253 253 253 253 253 253 253 253 253 253
40933 -253 253 253 206 206 206 198 198 198 214 166 58
40934 -230 174 11 230 174 11 216 158 10 192 133 9
40935 -163 110 8 116 81 8 102 78 10 116 81 8
40936 -167 114 7 197 138 11 226 170 11 239 182 13
40937 -242 186 14 242 186 14 162 146 94 78 78 78
40938 - 34 34 34 14 14 14 6 6 6 0 0 0
40939 - 0 0 0 0 0 0 0 0 0 0 0 0
40940 - 0 0 0 0 0 0 0 0 0 0 0 0
40941 - 0 0 0 0 0 0 0 0 0 0 0 0
40942 - 0 0 0 0 0 0 0 0 0 6 6 6
40943 - 30 30 30 78 78 78 190 142 34 226 170 11
40944 -239 182 13 246 190 14 246 190 14 246 190 14
40945 -246 190 14 246 190 14 246 190 14 246 190 14
40946 -246 190 14 246 190 14 246 190 14 246 190 14
40947 -246 190 14 241 196 14 203 166 17 22 18 6
40948 - 2 2 6 2 2 6 2 2 6 38 38 38
40949 -218 218 218 253 253 253 253 253 253 253 253 253
40950 -253 253 253 253 253 253 253 253 253 253 253 253
40951 -253 253 253 253 253 253 253 253 253 253 253 253
40952 -253 253 253 253 253 253 253 253 253 253 253 253
40953 -250 250 250 206 206 206 198 198 198 202 162 69
40954 -226 170 11 236 178 12 224 166 10 210 150 10
40955 -200 144 11 197 138 11 192 133 9 197 138 11
40956 -210 150 10 226 170 11 242 186 14 246 190 14
40957 -246 190 14 246 186 14 225 175 15 124 112 88
40958 - 62 62 62 30 30 30 14 14 14 6 6 6
40959 - 0 0 0 0 0 0 0 0 0 0 0 0
40960 - 0 0 0 0 0 0 0 0 0 0 0 0
40961 - 0 0 0 0 0 0 0 0 0 0 0 0
40962 - 0 0 0 0 0 0 0 0 0 10 10 10
40963 - 30 30 30 78 78 78 174 135 50 224 166 10
40964 -239 182 13 246 190 14 246 190 14 246 190 14
40965 -246 190 14 246 190 14 246 190 14 246 190 14
40966 -246 190 14 246 190 14 246 190 14 246 190 14
40967 -246 190 14 246 190 14 241 196 14 139 102 15
40968 - 2 2 6 2 2 6 2 2 6 2 2 6
40969 - 78 78 78 250 250 250 253 253 253 253 253 253
40970 -253 253 253 253 253 253 253 253 253 253 253 253
40971 -253 253 253 253 253 253 253 253 253 253 253 253
40972 -253 253 253 253 253 253 253 253 253 253 253 253
40973 -250 250 250 214 214 214 198 198 198 190 150 46
40974 -219 162 10 236 178 12 234 174 13 224 166 10
40975 -216 158 10 213 154 11 213 154 11 216 158 10
40976 -226 170 11 239 182 13 246 190 14 246 190 14
40977 -246 190 14 246 190 14 242 186 14 206 162 42
40978 -101 101 101 58 58 58 30 30 30 14 14 14
40979 - 6 6 6 0 0 0 0 0 0 0 0 0
40980 - 0 0 0 0 0 0 0 0 0 0 0 0
40981 - 0 0 0 0 0 0 0 0 0 0 0 0
40982 - 0 0 0 0 0 0 0 0 0 10 10 10
40983 - 30 30 30 74 74 74 174 135 50 216 158 10
40984 -236 178 12 246 190 14 246 190 14 246 190 14
40985 -246 190 14 246 190 14 246 190 14 246 190 14
40986 -246 190 14 246 190 14 246 190 14 246 190 14
40987 -246 190 14 246 190 14 241 196 14 226 184 13
40988 - 61 42 6 2 2 6 2 2 6 2 2 6
40989 - 22 22 22 238 238 238 253 253 253 253 253 253
40990 -253 253 253 253 253 253 253 253 253 253 253 253
40991 -253 253 253 253 253 253 253 253 253 253 253 253
40992 -253 253 253 253 253 253 253 253 253 253 253 253
40993 -253 253 253 226 226 226 187 187 187 180 133 36
40994 -216 158 10 236 178 12 239 182 13 236 178 12
40995 -230 174 11 226 170 11 226 170 11 230 174 11
40996 -236 178 12 242 186 14 246 190 14 246 190 14
40997 -246 190 14 246 190 14 246 186 14 239 182 13
40998 -206 162 42 106 106 106 66 66 66 34 34 34
40999 - 14 14 14 6 6 6 0 0 0 0 0 0
41000 - 0 0 0 0 0 0 0 0 0 0 0 0
41001 - 0 0 0 0 0 0 0 0 0 0 0 0
41002 - 0 0 0 0 0 0 0 0 0 6 6 6
41003 - 26 26 26 70 70 70 163 133 67 213 154 11
41004 -236 178 12 246 190 14 246 190 14 246 190 14
41005 -246 190 14 246 190 14 246 190 14 246 190 14
41006 -246 190 14 246 190 14 246 190 14 246 190 14
41007 -246 190 14 246 190 14 246 190 14 241 196 14
41008 -190 146 13 18 14 6 2 2 6 2 2 6
41009 - 46 46 46 246 246 246 253 253 253 253 253 253
41010 -253 253 253 253 253 253 253 253 253 253 253 253
41011 -253 253 253 253 253 253 253 253 253 253 253 253
41012 -253 253 253 253 253 253 253 253 253 253 253 253
41013 -253 253 253 221 221 221 86 86 86 156 107 11
41014 -216 158 10 236 178 12 242 186 14 246 186 14
41015 -242 186 14 239 182 13 239 182 13 242 186 14
41016 -242 186 14 246 186 14 246 190 14 246 190 14
41017 -246 190 14 246 190 14 246 190 14 246 190 14
41018 -242 186 14 225 175 15 142 122 72 66 66 66
41019 - 30 30 30 10 10 10 0 0 0 0 0 0
41020 - 0 0 0 0 0 0 0 0 0 0 0 0
41021 - 0 0 0 0 0 0 0 0 0 0 0 0
41022 - 0 0 0 0 0 0 0 0 0 6 6 6
41023 - 26 26 26 70 70 70 163 133 67 210 150 10
41024 -236 178 12 246 190 14 246 190 14 246 190 14
41025 -246 190 14 246 190 14 246 190 14 246 190 14
41026 -246 190 14 246 190 14 246 190 14 246 190 14
41027 -246 190 14 246 190 14 246 190 14 246 190 14
41028 -232 195 16 121 92 8 34 34 34 106 106 106
41029 -221 221 221 253 253 253 253 253 253 253 253 253
41030 -253 253 253 253 253 253 253 253 253 253 253 253
41031 -253 253 253 253 253 253 253 253 253 253 253 253
41032 -253 253 253 253 253 253 253 253 253 253 253 253
41033 -242 242 242 82 82 82 18 14 6 163 110 8
41034 -216 158 10 236 178 12 242 186 14 246 190 14
41035 -246 190 14 246 190 14 246 190 14 246 190 14
41036 -246 190 14 246 190 14 246 190 14 246 190 14
41037 -246 190 14 246 190 14 246 190 14 246 190 14
41038 -246 190 14 246 190 14 242 186 14 163 133 67
41039 - 46 46 46 18 18 18 6 6 6 0 0 0
41040 - 0 0 0 0 0 0 0 0 0 0 0 0
41041 - 0 0 0 0 0 0 0 0 0 0 0 0
41042 - 0 0 0 0 0 0 0 0 0 10 10 10
41043 - 30 30 30 78 78 78 163 133 67 210 150 10
41044 -236 178 12 246 186 14 246 190 14 246 190 14
41045 -246 190 14 246 190 14 246 190 14 246 190 14
41046 -246 190 14 246 190 14 246 190 14 246 190 14
41047 -246 190 14 246 190 14 246 190 14 246 190 14
41048 -241 196 14 215 174 15 190 178 144 253 253 253
41049 -253 253 253 253 253 253 253 253 253 253 253 253
41050 -253 253 253 253 253 253 253 253 253 253 253 253
41051 -253 253 253 253 253 253 253 253 253 253 253 253
41052 -253 253 253 253 253 253 253 253 253 218 218 218
41053 - 58 58 58 2 2 6 22 18 6 167 114 7
41054 -216 158 10 236 178 12 246 186 14 246 190 14
41055 -246 190 14 246 190 14 246 190 14 246 190 14
41056 -246 190 14 246 190 14 246 190 14 246 190 14
41057 -246 190 14 246 190 14 246 190 14 246 190 14
41058 -246 190 14 246 186 14 242 186 14 190 150 46
41059 - 54 54 54 22 22 22 6 6 6 0 0 0
41060 - 0 0 0 0 0 0 0 0 0 0 0 0
41061 - 0 0 0 0 0 0 0 0 0 0 0 0
41062 - 0 0 0 0 0 0 0 0 0 14 14 14
41063 - 38 38 38 86 86 86 180 133 36 213 154 11
41064 -236 178 12 246 186 14 246 190 14 246 190 14
41065 -246 190 14 246 190 14 246 190 14 246 190 14
41066 -246 190 14 246 190 14 246 190 14 246 190 14
41067 -246 190 14 246 190 14 246 190 14 246 190 14
41068 -246 190 14 232 195 16 190 146 13 214 214 214
41069 -253 253 253 253 253 253 253 253 253 253 253 253
41070 -253 253 253 253 253 253 253 253 253 253 253 253
41071 -253 253 253 253 253 253 253 253 253 253 253 253
41072 -253 253 253 250 250 250 170 170 170 26 26 26
41073 - 2 2 6 2 2 6 37 26 9 163 110 8
41074 -219 162 10 239 182 13 246 186 14 246 190 14
41075 -246 190 14 246 190 14 246 190 14 246 190 14
41076 -246 190 14 246 190 14 246 190 14 246 190 14
41077 -246 190 14 246 190 14 246 190 14 246 190 14
41078 -246 186 14 236 178 12 224 166 10 142 122 72
41079 - 46 46 46 18 18 18 6 6 6 0 0 0
41080 - 0 0 0 0 0 0 0 0 0 0 0 0
41081 - 0 0 0 0 0 0 0 0 0 0 0 0
41082 - 0 0 0 0 0 0 6 6 6 18 18 18
41083 - 50 50 50 109 106 95 192 133 9 224 166 10
41084 -242 186 14 246 190 14 246 190 14 246 190 14
41085 -246 190 14 246 190 14 246 190 14 246 190 14
41086 -246 190 14 246 190 14 246 190 14 246 190 14
41087 -246 190 14 246 190 14 246 190 14 246 190 14
41088 -242 186 14 226 184 13 210 162 10 142 110 46
41089 -226 226 226 253 253 253 253 253 253 253 253 253
41090 -253 253 253 253 253 253 253 253 253 253 253 253
41091 -253 253 253 253 253 253 253 253 253 253 253 253
41092 -198 198 198 66 66 66 2 2 6 2 2 6
41093 - 2 2 6 2 2 6 50 34 6 156 107 11
41094 -219 162 10 239 182 13 246 186 14 246 190 14
41095 -246 190 14 246 190 14 246 190 14 246 190 14
41096 -246 190 14 246 190 14 246 190 14 246 190 14
41097 -246 190 14 246 190 14 246 190 14 242 186 14
41098 -234 174 13 213 154 11 154 122 46 66 66 66
41099 - 30 30 30 10 10 10 0 0 0 0 0 0
41100 - 0 0 0 0 0 0 0 0 0 0 0 0
41101 - 0 0 0 0 0 0 0 0 0 0 0 0
41102 - 0 0 0 0 0 0 6 6 6 22 22 22
41103 - 58 58 58 154 121 60 206 145 10 234 174 13
41104 -242 186 14 246 186 14 246 190 14 246 190 14
41105 -246 190 14 246 190 14 246 190 14 246 190 14
41106 -246 190 14 246 190 14 246 190 14 246 190 14
41107 -246 190 14 246 190 14 246 190 14 246 190 14
41108 -246 186 14 236 178 12 210 162 10 163 110 8
41109 - 61 42 6 138 138 138 218 218 218 250 250 250
41110 -253 253 253 253 253 253 253 253 253 250 250 250
41111 -242 242 242 210 210 210 144 144 144 66 66 66
41112 - 6 6 6 2 2 6 2 2 6 2 2 6
41113 - 2 2 6 2 2 6 61 42 6 163 110 8
41114 -216 158 10 236 178 12 246 190 14 246 190 14
41115 -246 190 14 246 190 14 246 190 14 246 190 14
41116 -246 190 14 246 190 14 246 190 14 246 190 14
41117 -246 190 14 239 182 13 230 174 11 216 158 10
41118 -190 142 34 124 112 88 70 70 70 38 38 38
41119 - 18 18 18 6 6 6 0 0 0 0 0 0
41120 - 0 0 0 0 0 0 0 0 0 0 0 0
41121 - 0 0 0 0 0 0 0 0 0 0 0 0
41122 - 0 0 0 0 0 0 6 6 6 22 22 22
41123 - 62 62 62 168 124 44 206 145 10 224 166 10
41124 -236 178 12 239 182 13 242 186 14 242 186 14
41125 -246 186 14 246 190 14 246 190 14 246 190 14
41126 -246 190 14 246 190 14 246 190 14 246 190 14
41127 -246 190 14 246 190 14 246 190 14 246 190 14
41128 -246 190 14 236 178 12 216 158 10 175 118 6
41129 - 80 54 7 2 2 6 6 6 6 30 30 30
41130 - 54 54 54 62 62 62 50 50 50 38 38 38
41131 - 14 14 14 2 2 6 2 2 6 2 2 6
41132 - 2 2 6 2 2 6 2 2 6 2 2 6
41133 - 2 2 6 6 6 6 80 54 7 167 114 7
41134 -213 154 11 236 178 12 246 190 14 246 190 14
41135 -246 190 14 246 190 14 246 190 14 246 190 14
41136 -246 190 14 242 186 14 239 182 13 239 182 13
41137 -230 174 11 210 150 10 174 135 50 124 112 88
41138 - 82 82 82 54 54 54 34 34 34 18 18 18
41139 - 6 6 6 0 0 0 0 0 0 0 0 0
41140 - 0 0 0 0 0 0 0 0 0 0 0 0
41141 - 0 0 0 0 0 0 0 0 0 0 0 0
41142 - 0 0 0 0 0 0 6 6 6 18 18 18
41143 - 50 50 50 158 118 36 192 133 9 200 144 11
41144 -216 158 10 219 162 10 224 166 10 226 170 11
41145 -230 174 11 236 178 12 239 182 13 239 182 13
41146 -242 186 14 246 186 14 246 190 14 246 190 14
41147 -246 190 14 246 190 14 246 190 14 246 190 14
41148 -246 186 14 230 174 11 210 150 10 163 110 8
41149 -104 69 6 10 10 10 2 2 6 2 2 6
41150 - 2 2 6 2 2 6 2 2 6 2 2 6
41151 - 2 2 6 2 2 6 2 2 6 2 2 6
41152 - 2 2 6 2 2 6 2 2 6 2 2 6
41153 - 2 2 6 6 6 6 91 60 6 167 114 7
41154 -206 145 10 230 174 11 242 186 14 246 190 14
41155 -246 190 14 246 190 14 246 186 14 242 186 14
41156 -239 182 13 230 174 11 224 166 10 213 154 11
41157 -180 133 36 124 112 88 86 86 86 58 58 58
41158 - 38 38 38 22 22 22 10 10 10 6 6 6
41159 - 0 0 0 0 0 0 0 0 0 0 0 0
41160 - 0 0 0 0 0 0 0 0 0 0 0 0
41161 - 0 0 0 0 0 0 0 0 0 0 0 0
41162 - 0 0 0 0 0 0 0 0 0 14 14 14
41163 - 34 34 34 70 70 70 138 110 50 158 118 36
41164 -167 114 7 180 123 7 192 133 9 197 138 11
41165 -200 144 11 206 145 10 213 154 11 219 162 10
41166 -224 166 10 230 174 11 239 182 13 242 186 14
41167 -246 186 14 246 186 14 246 186 14 246 186 14
41168 -239 182 13 216 158 10 185 133 11 152 99 6
41169 -104 69 6 18 14 6 2 2 6 2 2 6
41170 - 2 2 6 2 2 6 2 2 6 2 2 6
41171 - 2 2 6 2 2 6 2 2 6 2 2 6
41172 - 2 2 6 2 2 6 2 2 6 2 2 6
41173 - 2 2 6 6 6 6 80 54 7 152 99 6
41174 -192 133 9 219 162 10 236 178 12 239 182 13
41175 -246 186 14 242 186 14 239 182 13 236 178 12
41176 -224 166 10 206 145 10 192 133 9 154 121 60
41177 - 94 94 94 62 62 62 42 42 42 22 22 22
41178 - 14 14 14 6 6 6 0 0 0 0 0 0
41179 - 0 0 0 0 0 0 0 0 0 0 0 0
41180 - 0 0 0 0 0 0 0 0 0 0 0 0
41181 - 0 0 0 0 0 0 0 0 0 0 0 0
41182 - 0 0 0 0 0 0 0 0 0 6 6 6
41183 - 18 18 18 34 34 34 58 58 58 78 78 78
41184 -101 98 89 124 112 88 142 110 46 156 107 11
41185 -163 110 8 167 114 7 175 118 6 180 123 7
41186 -185 133 11 197 138 11 210 150 10 219 162 10
41187 -226 170 11 236 178 12 236 178 12 234 174 13
41188 -219 162 10 197 138 11 163 110 8 130 83 6
41189 - 91 60 6 10 10 10 2 2 6 2 2 6
41190 - 18 18 18 38 38 38 38 38 38 38 38 38
41191 - 38 38 38 38 38 38 38 38 38 38 38 38
41192 - 38 38 38 38 38 38 26 26 26 2 2 6
41193 - 2 2 6 6 6 6 70 47 6 137 92 6
41194 -175 118 6 200 144 11 219 162 10 230 174 11
41195 -234 174 13 230 174 11 219 162 10 210 150 10
41196 -192 133 9 163 110 8 124 112 88 82 82 82
41197 - 50 50 50 30 30 30 14 14 14 6 6 6
41198 - 0 0 0 0 0 0 0 0 0 0 0 0
41199 - 0 0 0 0 0 0 0 0 0 0 0 0
41200 - 0 0 0 0 0 0 0 0 0 0 0 0
41201 - 0 0 0 0 0 0 0 0 0 0 0 0
41202 - 0 0 0 0 0 0 0 0 0 0 0 0
41203 - 6 6 6 14 14 14 22 22 22 34 34 34
41204 - 42 42 42 58 58 58 74 74 74 86 86 86
41205 -101 98 89 122 102 70 130 98 46 121 87 25
41206 -137 92 6 152 99 6 163 110 8 180 123 7
41207 -185 133 11 197 138 11 206 145 10 200 144 11
41208 -180 123 7 156 107 11 130 83 6 104 69 6
41209 - 50 34 6 54 54 54 110 110 110 101 98 89
41210 - 86 86 86 82 82 82 78 78 78 78 78 78
41211 - 78 78 78 78 78 78 78 78 78 78 78 78
41212 - 78 78 78 82 82 82 86 86 86 94 94 94
41213 -106 106 106 101 101 101 86 66 34 124 80 6
41214 -156 107 11 180 123 7 192 133 9 200 144 11
41215 -206 145 10 200 144 11 192 133 9 175 118 6
41216 -139 102 15 109 106 95 70 70 70 42 42 42
41217 - 22 22 22 10 10 10 0 0 0 0 0 0
41218 - 0 0 0 0 0 0 0 0 0 0 0 0
41219 - 0 0 0 0 0 0 0 0 0 0 0 0
41220 - 0 0 0 0 0 0 0 0 0 0 0 0
41221 - 0 0 0 0 0 0 0 0 0 0 0 0
41222 - 0 0 0 0 0 0 0 0 0 0 0 0
41223 - 0 0 0 0 0 0 6 6 6 10 10 10
41224 - 14 14 14 22 22 22 30 30 30 38 38 38
41225 - 50 50 50 62 62 62 74 74 74 90 90 90
41226 -101 98 89 112 100 78 121 87 25 124 80 6
41227 -137 92 6 152 99 6 152 99 6 152 99 6
41228 -138 86 6 124 80 6 98 70 6 86 66 30
41229 -101 98 89 82 82 82 58 58 58 46 46 46
41230 - 38 38 38 34 34 34 34 34 34 34 34 34
41231 - 34 34 34 34 34 34 34 34 34 34 34 34
41232 - 34 34 34 34 34 34 38 38 38 42 42 42
41233 - 54 54 54 82 82 82 94 86 76 91 60 6
41234 -134 86 6 156 107 11 167 114 7 175 118 6
41235 -175 118 6 167 114 7 152 99 6 121 87 25
41236 -101 98 89 62 62 62 34 34 34 18 18 18
41237 - 6 6 6 0 0 0 0 0 0 0 0 0
41238 - 0 0 0 0 0 0 0 0 0 0 0 0
41239 - 0 0 0 0 0 0 0 0 0 0 0 0
41240 - 0 0 0 0 0 0 0 0 0 0 0 0
41241 - 0 0 0 0 0 0 0 0 0 0 0 0
41242 - 0 0 0 0 0 0 0 0 0 0 0 0
41243 - 0 0 0 0 0 0 0 0 0 0 0 0
41244 - 0 0 0 6 6 6 6 6 6 10 10 10
41245 - 18 18 18 22 22 22 30 30 30 42 42 42
41246 - 50 50 50 66 66 66 86 86 86 101 98 89
41247 -106 86 58 98 70 6 104 69 6 104 69 6
41248 -104 69 6 91 60 6 82 62 34 90 90 90
41249 - 62 62 62 38 38 38 22 22 22 14 14 14
41250 - 10 10 10 10 10 10 10 10 10 10 10 10
41251 - 10 10 10 10 10 10 6 6 6 10 10 10
41252 - 10 10 10 10 10 10 10 10 10 14 14 14
41253 - 22 22 22 42 42 42 70 70 70 89 81 66
41254 - 80 54 7 104 69 6 124 80 6 137 92 6
41255 -134 86 6 116 81 8 100 82 52 86 86 86
41256 - 58 58 58 30 30 30 14 14 14 6 6 6
41257 - 0 0 0 0 0 0 0 0 0 0 0 0
41258 - 0 0 0 0 0 0 0 0 0 0 0 0
41259 - 0 0 0 0 0 0 0 0 0 0 0 0
41260 - 0 0 0 0 0 0 0 0 0 0 0 0
41261 - 0 0 0 0 0 0 0 0 0 0 0 0
41262 - 0 0 0 0 0 0 0 0 0 0 0 0
41263 - 0 0 0 0 0 0 0 0 0 0 0 0
41264 - 0 0 0 0 0 0 0 0 0 0 0 0
41265 - 0 0 0 6 6 6 10 10 10 14 14 14
41266 - 18 18 18 26 26 26 38 38 38 54 54 54
41267 - 70 70 70 86 86 86 94 86 76 89 81 66
41268 - 89 81 66 86 86 86 74 74 74 50 50 50
41269 - 30 30 30 14 14 14 6 6 6 0 0 0
41270 - 0 0 0 0 0 0 0 0 0 0 0 0
41271 - 0 0 0 0 0 0 0 0 0 0 0 0
41272 - 0 0 0 0 0 0 0 0 0 0 0 0
41273 - 6 6 6 18 18 18 34 34 34 58 58 58
41274 - 82 82 82 89 81 66 89 81 66 89 81 66
41275 - 94 86 66 94 86 76 74 74 74 50 50 50
41276 - 26 26 26 14 14 14 6 6 6 0 0 0
41277 - 0 0 0 0 0 0 0 0 0 0 0 0
41278 - 0 0 0 0 0 0 0 0 0 0 0 0
41279 - 0 0 0 0 0 0 0 0 0 0 0 0
41280 - 0 0 0 0 0 0 0 0 0 0 0 0
41281 - 0 0 0 0 0 0 0 0 0 0 0 0
41282 - 0 0 0 0 0 0 0 0 0 0 0 0
41283 - 0 0 0 0 0 0 0 0 0 0 0 0
41284 - 0 0 0 0 0 0 0 0 0 0 0 0
41285 - 0 0 0 0 0 0 0 0 0 0 0 0
41286 - 6 6 6 6 6 6 14 14 14 18 18 18
41287 - 30 30 30 38 38 38 46 46 46 54 54 54
41288 - 50 50 50 42 42 42 30 30 30 18 18 18
41289 - 10 10 10 0 0 0 0 0 0 0 0 0
41290 - 0 0 0 0 0 0 0 0 0 0 0 0
41291 - 0 0 0 0 0 0 0 0 0 0 0 0
41292 - 0 0 0 0 0 0 0 0 0 0 0 0
41293 - 0 0 0 6 6 6 14 14 14 26 26 26
41294 - 38 38 38 50 50 50 58 58 58 58 58 58
41295 - 54 54 54 42 42 42 30 30 30 18 18 18
41296 - 10 10 10 0 0 0 0 0 0 0 0 0
41297 - 0 0 0 0 0 0 0 0 0 0 0 0
41298 - 0 0 0 0 0 0 0 0 0 0 0 0
41299 - 0 0 0 0 0 0 0 0 0 0 0 0
41300 - 0 0 0 0 0 0 0 0 0 0 0 0
41301 - 0 0 0 0 0 0 0 0 0 0 0 0
41302 - 0 0 0 0 0 0 0 0 0 0 0 0
41303 - 0 0 0 0 0 0 0 0 0 0 0 0
41304 - 0 0 0 0 0 0 0 0 0 0 0 0
41305 - 0 0 0 0 0 0 0 0 0 0 0 0
41306 - 0 0 0 0 0 0 0 0 0 6 6 6
41307 - 6 6 6 10 10 10 14 14 14 18 18 18
41308 - 18 18 18 14 14 14 10 10 10 6 6 6
41309 - 0 0 0 0 0 0 0 0 0 0 0 0
41310 - 0 0 0 0 0 0 0 0 0 0 0 0
41311 - 0 0 0 0 0 0 0 0 0 0 0 0
41312 - 0 0 0 0 0 0 0 0 0 0 0 0
41313 - 0 0 0 0 0 0 0 0 0 6 6 6
41314 - 14 14 14 18 18 18 22 22 22 22 22 22
41315 - 18 18 18 14 14 14 10 10 10 6 6 6
41316 - 0 0 0 0 0 0 0 0 0 0 0 0
41317 - 0 0 0 0 0 0 0 0 0 0 0 0
41318 - 0 0 0 0 0 0 0 0 0 0 0 0
41319 - 0 0 0 0 0 0 0 0 0 0 0 0
41320 - 0 0 0 0 0 0 0 0 0 0 0 0
41321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41334 +4 4 4 4 4 4
41335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41348 +4 4 4 4 4 4
41349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41362 +4 4 4 4 4 4
41363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41376 +4 4 4 4 4 4
41377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41390 +4 4 4 4 4 4
41391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41404 +4 4 4 4 4 4
41405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41410 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41414 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41415 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41416 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41418 +4 4 4 4 4 4
41419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41423 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41424 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41425 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41428 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41429 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41430 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41431 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41432 +4 4 4 4 4 4
41433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41437 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41438 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41439 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41442 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41443 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41444 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41445 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41446 +4 4 4 4 4 4
41447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41450 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41451 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41452 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41453 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41455 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41456 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41457 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41458 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41459 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41460 +4 4 4 4 4 4
41461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41464 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41465 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41466 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41467 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41468 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41469 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41470 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41471 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41472 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41473 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41474 +4 4 4 4 4 4
41475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41478 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41479 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41480 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41481 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41482 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41483 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41484 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41485 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41486 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41487 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41488 +4 4 4 4 4 4
41489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41491 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41492 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41493 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41494 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41495 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41496 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41497 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41498 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41499 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41500 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41501 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41502 +4 4 4 4 4 4
41503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41505 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41506 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41507 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41508 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41509 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41510 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41511 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41512 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41513 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41514 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41515 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41516 +4 4 4 4 4 4
41517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41519 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41520 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41521 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41522 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41523 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41524 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41525 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41526 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41527 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41528 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41529 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41530 +4 4 4 4 4 4
41531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41533 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41534 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41535 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41536 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41537 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41538 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41539 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41540 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41541 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41542 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41543 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41544 +4 4 4 4 4 4
41545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41546 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41547 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41548 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41549 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41550 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41551 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41552 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41553 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41554 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41555 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41556 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41557 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41558 +4 4 4 4 4 4
41559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41560 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41561 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41562 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41563 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41564 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41565 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41566 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41567 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41568 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41569 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41570 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41571 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41572 +0 0 0 4 4 4
41573 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41574 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41575 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41576 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41577 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41578 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41579 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41580 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41581 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41582 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41583 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41584 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41585 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41586 +2 0 0 0 0 0
41587 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41588 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41589 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41590 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41591 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41592 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41593 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41594 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41595 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41596 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41597 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41598 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41599 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41600 +37 38 37 0 0 0
41601 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41602 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41603 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41604 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41605 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41606 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41607 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41608 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41609 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41610 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41611 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41612 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41613 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41614 +85 115 134 4 0 0
41615 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41616 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41617 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41618 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41619 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41620 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41621 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41622 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41623 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41624 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41625 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41626 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41627 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41628 +60 73 81 4 0 0
41629 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41630 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41631 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41632 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41633 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41634 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41635 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41636 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41637 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41638 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41639 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41640 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41641 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41642 +16 19 21 4 0 0
41643 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41644 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41645 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41646 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41647 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41648 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41649 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41650 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41651 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41652 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41653 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41654 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41655 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41656 +4 0 0 4 3 3
41657 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41658 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41659 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41661 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41662 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41663 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41664 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41665 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41666 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41667 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41668 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41669 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41670 +3 2 2 4 4 4
41671 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41672 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41673 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41674 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41675 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41676 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41677 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41678 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41679 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41680 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41681 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41682 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41683 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41684 +4 4 4 4 4 4
41685 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41686 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41687 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41688 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41689 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41690 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41691 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41692 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41693 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41694 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41695 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41696 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41697 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41698 +4 4 4 4 4 4
41699 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41700 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41701 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41702 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41703 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41704 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41705 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41706 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41707 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41708 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41709 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41710 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41711 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41712 +5 5 5 5 5 5
41713 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41714 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41715 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41716 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41717 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41718 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41719 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41720 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41721 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41722 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41723 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41724 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41725 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41726 +5 5 5 4 4 4
41727 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41728 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41729 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41730 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41731 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41732 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41733 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41734 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41735 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41736 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41737 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41738 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41740 +4 4 4 4 4 4
41741 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41742 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41743 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41744 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41745 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41746 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41747 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41748 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41749 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41750 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41751 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41752 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41754 +4 4 4 4 4 4
41755 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41756 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41757 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41758 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41759 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41760 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41761 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41762 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41763 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41764 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41765 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41768 +4 4 4 4 4 4
41769 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41770 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41771 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41772 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41773 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41774 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41775 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41776 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41777 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41778 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41779 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41782 +4 4 4 4 4 4
41783 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41784 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41785 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41786 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41787 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41788 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41789 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41790 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41791 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41792 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41793 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41796 +4 4 4 4 4 4
41797 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41798 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41799 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41800 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41801 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41802 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41803 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41804 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41805 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41806 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41807 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41810 +4 4 4 4 4 4
41811 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41812 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41813 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41814 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41815 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41816 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41817 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41818 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41819 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41820 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41821 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41824 +4 4 4 4 4 4
41825 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41826 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41827 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41828 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41829 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41830 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41831 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41832 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41833 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41834 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41835 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41838 +4 4 4 4 4 4
41839 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41840 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41841 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41842 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41843 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41844 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41845 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41846 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41847 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41848 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41849 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41852 +4 4 4 4 4 4
41853 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41854 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41855 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41856 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41857 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41858 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41859 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41860 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41861 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41862 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41863 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41866 +4 4 4 4 4 4
41867 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41868 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41869 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41870 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41871 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41872 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41873 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41874 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41875 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41876 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41877 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41880 +4 4 4 4 4 4
41881 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41882 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41883 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41884 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41885 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41886 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41887 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41888 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41889 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41890 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41891 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41894 +4 4 4 4 4 4
41895 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41896 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41897 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41898 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41899 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41900 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41901 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41902 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41903 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41904 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41905 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41908 +4 4 4 4 4 4
41909 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41910 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41911 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41912 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41913 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41914 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41915 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41916 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41917 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41918 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41919 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41922 +4 4 4 4 4 4
41923 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41924 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41925 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41926 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41927 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41928 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41929 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41930 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41931 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41932 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41933 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41936 +4 4 4 4 4 4
41937 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41938 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41939 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41940 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41941 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41942 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41943 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41944 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41945 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41946 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41947 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41950 +4 4 4 4 4 4
41951 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41952 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41953 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41954 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41955 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41956 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41957 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41958 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41959 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41960 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41961 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41964 +4 4 4 4 4 4
41965 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41966 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41967 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41968 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41969 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41970 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41971 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41972 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41973 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41974 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41975 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41978 +4 4 4 4 4 4
41979 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41980 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41981 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41982 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41983 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41984 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41985 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41986 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41987 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41988 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41989 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41992 +4 4 4 4 4 4
41993 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41994 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41995 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41996 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41997 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41998 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41999 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42000 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
42001 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
42002 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42003 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42006 +4 4 4 4 4 4
42007 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42008 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
42009 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
42010 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42011 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
42012 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
42013 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
42014 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
42015 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
42016 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42017 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42020 +4 4 4 4 4 4
42021 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
42022 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
42023 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
42024 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
42025 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
42026 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
42027 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
42028 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
42029 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
42030 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42031 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42034 +4 4 4 4 4 4
42035 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42036 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
42037 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
42038 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
42039 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
42040 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
42041 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
42042 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
42043 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
42044 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42045 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42048 +4 4 4 4 4 4
42049 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42050 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42051 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42052 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42053 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42054 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42055 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42056 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42057 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42058 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42059 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42062 +4 4 4 4 4 4
42063 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42064 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42065 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42066 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42067 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42068 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42069 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42070 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42071 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42072 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42073 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42076 +4 4 4 4 4 4
42077 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42078 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42079 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42080 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42081 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42082 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42083 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42084 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42085 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42086 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42087 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42090 +4 4 4 4 4 4
42091 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42092 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42093 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42094 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42095 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42096 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42097 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42098 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42099 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42100 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42101 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42104 +4 4 4 4 4 4
42105 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42106 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42107 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42108 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42109 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42110 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42111 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42112 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42113 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42114 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42115 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42118 +4 4 4 4 4 4
42119 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42120 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42121 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42122 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42123 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42124 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42125 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42126 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42127 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42128 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42129 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42132 +4 4 4 4 4 4
42133 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42134 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42135 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42136 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42137 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42138 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42139 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42140 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42141 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42142 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42146 +4 4 4 4 4 4
42147 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42148 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42149 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42150 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42151 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42152 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42153 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42154 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42155 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42156 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42160 +4 4 4 4 4 4
42161 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42162 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42163 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42164 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42165 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42166 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42167 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42168 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42169 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42170 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42174 +4 4 4 4 4 4
42175 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42176 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42177 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42178 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42179 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42180 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42181 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42182 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42183 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42184 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42188 +4 4 4 4 4 4
42189 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42190 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42191 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42192 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42193 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42194 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42195 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42196 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42197 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42202 +4 4 4 4 4 4
42203 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42204 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42205 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42206 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42207 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42208 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42209 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42210 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42211 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42216 +4 4 4 4 4 4
42217 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42218 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42219 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42220 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42221 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42222 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42223 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42224 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42225 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42230 +4 4 4 4 4 4
42231 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42232 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42233 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42234 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42235 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42236 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42237 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42238 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42244 +4 4 4 4 4 4
42245 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42246 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42247 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42248 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42249 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42250 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42251 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42252 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42258 +4 4 4 4 4 4
42259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42260 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42261 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42262 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42263 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42264 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42265 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42266 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42272 +4 4 4 4 4 4
42273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42274 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42275 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42276 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42277 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42278 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42279 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42280 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42286 +4 4 4 4 4 4
42287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42288 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42289 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42290 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42291 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42292 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42293 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42294 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42300 +4 4 4 4 4 4
42301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42303 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42304 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42305 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42306 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42307 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42308 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42314 +4 4 4 4 4 4
42315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42318 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42319 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42320 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42321 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42328 +4 4 4 4 4 4
42329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42332 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42333 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42334 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42335 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42342 +4 4 4 4 4 4
42343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42346 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42347 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42348 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42349 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42356 +4 4 4 4 4 4
42357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42360 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42361 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42362 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42363 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42370 +4 4 4 4 4 4
42371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42375 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42376 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42377 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42384 +4 4 4 4 4 4
42385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42389 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42390 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42391 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42398 +4 4 4 4 4 4
42399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42403 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42404 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42405 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42412 +4 4 4 4 4 4
42413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42417 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42418 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42421 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42426 +4 4 4 4 4 4
42427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42431 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42432 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42440 +4 4 4 4 4 4
42441 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42442 index a40c05e..785c583 100644
42443 --- a/drivers/video/udlfb.c
42444 +++ b/drivers/video/udlfb.c
42445 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42446 dlfb_urb_completion(urb);
42447
42448 error:
42449 - atomic_add(bytes_sent, &dev->bytes_sent);
42450 - atomic_add(bytes_identical, &dev->bytes_identical);
42451 - atomic_add(width*height*2, &dev->bytes_rendered);
42452 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42453 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42454 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42455 end_cycles = get_cycles();
42456 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42457 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42458 >> 10)), /* Kcycles */
42459 &dev->cpu_kcycles_used);
42460
42461 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42462 dlfb_urb_completion(urb);
42463
42464 error:
42465 - atomic_add(bytes_sent, &dev->bytes_sent);
42466 - atomic_add(bytes_identical, &dev->bytes_identical);
42467 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42468 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42469 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42470 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42471 end_cycles = get_cycles();
42472 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42473 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42474 >> 10)), /* Kcycles */
42475 &dev->cpu_kcycles_used);
42476 }
42477 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42478 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42479 struct dlfb_data *dev = fb_info->par;
42480 return snprintf(buf, PAGE_SIZE, "%u\n",
42481 - atomic_read(&dev->bytes_rendered));
42482 + atomic_read_unchecked(&dev->bytes_rendered));
42483 }
42484
42485 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42486 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42487 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42488 struct dlfb_data *dev = fb_info->par;
42489 return snprintf(buf, PAGE_SIZE, "%u\n",
42490 - atomic_read(&dev->bytes_identical));
42491 + atomic_read_unchecked(&dev->bytes_identical));
42492 }
42493
42494 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42495 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42496 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42497 struct dlfb_data *dev = fb_info->par;
42498 return snprintf(buf, PAGE_SIZE, "%u\n",
42499 - atomic_read(&dev->bytes_sent));
42500 + atomic_read_unchecked(&dev->bytes_sent));
42501 }
42502
42503 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42504 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42505 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42506 struct dlfb_data *dev = fb_info->par;
42507 return snprintf(buf, PAGE_SIZE, "%u\n",
42508 - atomic_read(&dev->cpu_kcycles_used));
42509 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42510 }
42511
42512 static ssize_t edid_show(
42513 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42514 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42515 struct dlfb_data *dev = fb_info->par;
42516
42517 - atomic_set(&dev->bytes_rendered, 0);
42518 - atomic_set(&dev->bytes_identical, 0);
42519 - atomic_set(&dev->bytes_sent, 0);
42520 - atomic_set(&dev->cpu_kcycles_used, 0);
42521 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42522 + atomic_set_unchecked(&dev->bytes_identical, 0);
42523 + atomic_set_unchecked(&dev->bytes_sent, 0);
42524 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42525
42526 return count;
42527 }
42528 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42529 index 8408543..d6f20f1 100644
42530 --- a/drivers/video/uvesafb.c
42531 +++ b/drivers/video/uvesafb.c
42532 @@ -19,6 +19,7 @@
42533 #include <linux/io.h>
42534 #include <linux/mutex.h>
42535 #include <linux/slab.h>
42536 +#include <linux/moduleloader.h>
42537 #include <video/edid.h>
42538 #include <video/uvesafb.h>
42539 #ifdef CONFIG_X86
42540 @@ -73,7 +74,7 @@ static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *ns
42541 struct uvesafb_task *utask;
42542 struct uvesafb_ktask *task;
42543
42544 - if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
42545 + if (!capable(CAP_SYS_ADMIN))
42546 return;
42547
42548 if (msg->seq >= UVESAFB_TASKS_MAX)
42549 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
42550 NULL,
42551 };
42552
42553 - return call_usermodehelper(v86d_path, argv, envp, 1);
42554 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
42555 }
42556
42557 /*
42558 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42559 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42560 par->pmi_setpal = par->ypan = 0;
42561 } else {
42562 +
42563 +#ifdef CONFIG_PAX_KERNEXEC
42564 +#ifdef CONFIG_MODULES
42565 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42566 +#endif
42567 + if (!par->pmi_code) {
42568 + par->pmi_setpal = par->ypan = 0;
42569 + return 0;
42570 + }
42571 +#endif
42572 +
42573 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42574 + task->t.regs.edi);
42575 +
42576 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42577 + pax_open_kernel();
42578 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42579 + pax_close_kernel();
42580 +
42581 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42582 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42583 +#else
42584 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42585 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42586 +#endif
42587 +
42588 printk(KERN_INFO "uvesafb: protected mode interface info at "
42589 "%04x:%04x\n",
42590 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42591 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42592 par->ypan = ypan;
42593
42594 if (par->pmi_setpal || par->ypan) {
42595 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42596 if (__supported_pte_mask & _PAGE_NX) {
42597 par->pmi_setpal = par->ypan = 0;
42598 printk(KERN_WARNING "uvesafb: NX protection is actively."
42599 "We have better not to use the PMI.\n");
42600 - } else {
42601 + } else
42602 +#endif
42603 uvesafb_vbe_getpmi(task, par);
42604 - }
42605 }
42606 #else
42607 /* The protected mode interface is not available on non-x86. */
42608 @@ -1828,6 +1852,11 @@ out:
42609 if (par->vbe_modes)
42610 kfree(par->vbe_modes);
42611
42612 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42613 + if (par->pmi_code)
42614 + module_free_exec(NULL, par->pmi_code);
42615 +#endif
42616 +
42617 framebuffer_release(info);
42618 return err;
42619 }
42620 @@ -1854,6 +1883,12 @@ static int uvesafb_remove(struct platform_device *dev)
42621 kfree(par->vbe_state_orig);
42622 if (par->vbe_state_saved)
42623 kfree(par->vbe_state_saved);
42624 +
42625 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42626 + if (par->pmi_code)
42627 + module_free_exec(NULL, par->pmi_code);
42628 +#endif
42629 +
42630 }
42631
42632 framebuffer_release(info);
42633 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42634 index 501b340..86bd4cf 100644
42635 --- a/drivers/video/vesafb.c
42636 +++ b/drivers/video/vesafb.c
42637 @@ -9,6 +9,7 @@
42638 */
42639
42640 #include <linux/module.h>
42641 +#include <linux/moduleloader.h>
42642 #include <linux/kernel.h>
42643 #include <linux/errno.h>
42644 #include <linux/string.h>
42645 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42646 static int vram_total __initdata; /* Set total amount of memory */
42647 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42648 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42649 -static void (*pmi_start)(void) __read_mostly;
42650 -static void (*pmi_pal) (void) __read_mostly;
42651 +static void (*pmi_start)(void) __read_only;
42652 +static void (*pmi_pal) (void) __read_only;
42653 static int depth __read_mostly;
42654 static int vga_compat __read_mostly;
42655 /* --------------------------------------------------------------------- */
42656 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42657 unsigned int size_vmode;
42658 unsigned int size_remap;
42659 unsigned int size_total;
42660 + void *pmi_code = NULL;
42661
42662 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42663 return -ENODEV;
42664 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42665 size_remap = size_total;
42666 vesafb_fix.smem_len = size_remap;
42667
42668 -#ifndef __i386__
42669 - screen_info.vesapm_seg = 0;
42670 -#endif
42671 -
42672 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42673 printk(KERN_WARNING
42674 "vesafb: cannot reserve video memory at 0x%lx\n",
42675 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42676 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42677 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42678
42679 +#ifdef __i386__
42680 +
42681 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42682 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42683 + if (!pmi_code)
42684 +#elif !defined(CONFIG_PAX_KERNEXEC)
42685 + if (0)
42686 +#endif
42687 +
42688 +#endif
42689 + screen_info.vesapm_seg = 0;
42690 +
42691 if (screen_info.vesapm_seg) {
42692 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42693 - screen_info.vesapm_seg,screen_info.vesapm_off);
42694 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42695 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42696 }
42697
42698 if (screen_info.vesapm_seg < 0xc000)
42699 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42700
42701 if (ypan || pmi_setpal) {
42702 unsigned short *pmi_base;
42703 +
42704 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42705 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42706 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42707 +
42708 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42709 + pax_open_kernel();
42710 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42711 +#else
42712 + pmi_code = pmi_base;
42713 +#endif
42714 +
42715 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42716 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42717 +
42718 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42719 + pmi_start = ktva_ktla(pmi_start);
42720 + pmi_pal = ktva_ktla(pmi_pal);
42721 + pax_close_kernel();
42722 +#endif
42723 +
42724 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42725 if (pmi_base[3]) {
42726 printk(KERN_INFO "vesafb: pmi: ports = ");
42727 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42728 info->node, info->fix.id);
42729 return 0;
42730 err:
42731 +
42732 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42733 + module_free_exec(NULL, pmi_code);
42734 +#endif
42735 +
42736 if (info->screen_base)
42737 iounmap(info->screen_base);
42738 framebuffer_release(info);
42739 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42740 index 88714ae..16c2e11 100644
42741 --- a/drivers/video/via/via_clock.h
42742 +++ b/drivers/video/via/via_clock.h
42743 @@ -56,7 +56,7 @@ struct via_clock {
42744
42745 void (*set_engine_pll_state)(u8 state);
42746 void (*set_engine_pll)(struct via_pll_config config);
42747 -};
42748 +} __no_const;
42749
42750
42751 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42752 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42753 index e56c934..fc22f4b 100644
42754 --- a/drivers/xen/xen-pciback/conf_space.h
42755 +++ b/drivers/xen/xen-pciback/conf_space.h
42756 @@ -44,15 +44,15 @@ struct config_field {
42757 struct {
42758 conf_dword_write write;
42759 conf_dword_read read;
42760 - } dw;
42761 + } __no_const dw;
42762 struct {
42763 conf_word_write write;
42764 conf_word_read read;
42765 - } w;
42766 + } __no_const w;
42767 struct {
42768 conf_byte_write write;
42769 conf_byte_read read;
42770 - } b;
42771 + } __no_const b;
42772 } u;
42773 struct list_head list;
42774 };
42775 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42776 index 014c8dd..6f3dfe6 100644
42777 --- a/fs/9p/vfs_inode.c
42778 +++ b/fs/9p/vfs_inode.c
42779 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42780 void
42781 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42782 {
42783 - char *s = nd_get_link(nd);
42784 + const char *s = nd_get_link(nd);
42785
42786 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42787 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42788 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42789 index e95d1b6..3454244 100644
42790 --- a/fs/Kconfig.binfmt
42791 +++ b/fs/Kconfig.binfmt
42792 @@ -89,7 +89,7 @@ config HAVE_AOUT
42793
42794 config BINFMT_AOUT
42795 tristate "Kernel support for a.out and ECOFF binaries"
42796 - depends on HAVE_AOUT
42797 + depends on HAVE_AOUT && BROKEN
42798 ---help---
42799 A.out (Assembler.OUTput) is a set of formats for libraries and
42800 executables used in the earliest versions of UNIX. Linux used
42801 diff --git a/fs/aio.c b/fs/aio.c
42802 index b9d64d8..86cb1d5 100644
42803 --- a/fs/aio.c
42804 +++ b/fs/aio.c
42805 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42806 size += sizeof(struct io_event) * nr_events;
42807 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42808
42809 - if (nr_pages < 0)
42810 + if (nr_pages <= 0)
42811 return -EINVAL;
42812
42813 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42814 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42815 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42816 {
42817 ssize_t ret;
42818 + struct iovec iovstack;
42819
42820 #ifdef CONFIG_COMPAT
42821 if (compat)
42822 ret = compat_rw_copy_check_uvector(type,
42823 (struct compat_iovec __user *)kiocb->ki_buf,
42824 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42825 + kiocb->ki_nbytes, 1, &iovstack,
42826 &kiocb->ki_iovec, 1);
42827 else
42828 #endif
42829 ret = rw_copy_check_uvector(type,
42830 (struct iovec __user *)kiocb->ki_buf,
42831 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42832 + kiocb->ki_nbytes, 1, &iovstack,
42833 &kiocb->ki_iovec, 1);
42834 if (ret < 0)
42835 goto out;
42836
42837 + if (kiocb->ki_iovec == &iovstack) {
42838 + kiocb->ki_inline_vec = iovstack;
42839 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42840 + }
42841 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42842 kiocb->ki_cur_seg = 0;
42843 /* ki_nbytes/left now reflect bytes instead of segs */
42844 diff --git a/fs/attr.c b/fs/attr.c
42845 index 95053ad..2cc93ca 100644
42846 --- a/fs/attr.c
42847 +++ b/fs/attr.c
42848 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42849 unsigned long limit;
42850
42851 limit = rlimit(RLIMIT_FSIZE);
42852 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42853 if (limit != RLIM_INFINITY && offset > limit)
42854 goto out_sig;
42855 if (offset > inode->i_sb->s_maxbytes)
42856 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42857 index f624cd0..3d9a559 100644
42858 --- a/fs/autofs4/waitq.c
42859 +++ b/fs/autofs4/waitq.c
42860 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42861 {
42862 unsigned long sigpipe, flags;
42863 mm_segment_t fs;
42864 - const char *data = (const char *)addr;
42865 + const char __user *data = (const char __force_user *)addr;
42866 ssize_t wr = 0;
42867
42868 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42869 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42870 index 6e6d536..457113a 100644
42871 --- a/fs/befs/linuxvfs.c
42872 +++ b/fs/befs/linuxvfs.c
42873 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42874 {
42875 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42876 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42877 - char *link = nd_get_link(nd);
42878 + const char *link = nd_get_link(nd);
42879 if (!IS_ERR(link))
42880 kfree(link);
42881 }
42882 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42883 index 1ff9405..f1e376a 100644
42884 --- a/fs/binfmt_aout.c
42885 +++ b/fs/binfmt_aout.c
42886 @@ -16,6 +16,7 @@
42887 #include <linux/string.h>
42888 #include <linux/fs.h>
42889 #include <linux/file.h>
42890 +#include <linux/security.h>
42891 #include <linux/stat.h>
42892 #include <linux/fcntl.h>
42893 #include <linux/ptrace.h>
42894 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42895 #endif
42896 # define START_STACK(u) ((void __user *)u.start_stack)
42897
42898 + memset(&dump, 0, sizeof(dump));
42899 +
42900 fs = get_fs();
42901 set_fs(KERNEL_DS);
42902 has_dumped = 1;
42903 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42904
42905 /* If the size of the dump file exceeds the rlimit, then see what would happen
42906 if we wrote the stack, but not the data area. */
42907 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42908 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42909 dump.u_dsize = 0;
42910
42911 /* Make sure we have enough room to write the stack and data areas. */
42912 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42913 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42914 dump.u_ssize = 0;
42915
42916 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42917 rlim = rlimit(RLIMIT_DATA);
42918 if (rlim >= RLIM_INFINITY)
42919 rlim = ~0;
42920 +
42921 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42922 if (ex.a_data + ex.a_bss > rlim)
42923 return -ENOMEM;
42924
42925 @@ -269,6 +276,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42926 install_exec_creds(bprm);
42927 current->flags &= ~PF_FORKNOEXEC;
42928
42929 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42930 + current->mm->pax_flags = 0UL;
42931 +#endif
42932 +
42933 +#ifdef CONFIG_PAX_PAGEEXEC
42934 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42935 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42936 +
42937 +#ifdef CONFIG_PAX_EMUTRAMP
42938 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42939 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42940 +#endif
42941 +
42942 +#ifdef CONFIG_PAX_MPROTECT
42943 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42944 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42945 +#endif
42946 +
42947 + }
42948 +#endif
42949 +
42950 if (N_MAGIC(ex) == OMAGIC) {
42951 unsigned long text_addr, map_size;
42952 loff_t pos;
42953 @@ -341,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42954
42955 down_write(&current->mm->mmap_sem);
42956 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42957 - PROT_READ | PROT_WRITE | PROT_EXEC,
42958 + PROT_READ | PROT_WRITE,
42959 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42960 fd_offset + ex.a_text);
42961 up_write(&current->mm->mmap_sem);
42962 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42963 index 07d096c..25762af 100644
42964 --- a/fs/binfmt_elf.c
42965 +++ b/fs/binfmt_elf.c
42966 @@ -32,6 +32,7 @@
42967 #include <linux/elf.h>
42968 #include <linux/utsname.h>
42969 #include <linux/coredump.h>
42970 +#include <linux/xattr.h>
42971 #include <asm/uaccess.h>
42972 #include <asm/param.h>
42973 #include <asm/page.h>
42974 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42975 #define elf_core_dump NULL
42976 #endif
42977
42978 +#ifdef CONFIG_PAX_MPROTECT
42979 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42980 +#endif
42981 +
42982 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42983 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42984 #else
42985 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42986 .load_binary = load_elf_binary,
42987 .load_shlib = load_elf_library,
42988 .core_dump = elf_core_dump,
42989 +
42990 +#ifdef CONFIG_PAX_MPROTECT
42991 + .handle_mprotect= elf_handle_mprotect,
42992 +#endif
42993 +
42994 .min_coredump = ELF_EXEC_PAGESIZE,
42995 };
42996
42997 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42998
42999 static int set_brk(unsigned long start, unsigned long end)
43000 {
43001 + unsigned long e = end;
43002 +
43003 start = ELF_PAGEALIGN(start);
43004 end = ELF_PAGEALIGN(end);
43005 if (end > start) {
43006 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
43007 if (BAD_ADDR(addr))
43008 return addr;
43009 }
43010 - current->mm->start_brk = current->mm->brk = end;
43011 + current->mm->start_brk = current->mm->brk = e;
43012 return 0;
43013 }
43014
43015 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43016 elf_addr_t __user *u_rand_bytes;
43017 const char *k_platform = ELF_PLATFORM;
43018 const char *k_base_platform = ELF_BASE_PLATFORM;
43019 - unsigned char k_rand_bytes[16];
43020 + u32 k_rand_bytes[4];
43021 int items;
43022 elf_addr_t *elf_info;
43023 int ei_index = 0;
43024 const struct cred *cred = current_cred();
43025 struct vm_area_struct *vma;
43026 + unsigned long saved_auxv[AT_VECTOR_SIZE];
43027
43028 /*
43029 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43030 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43031 * Generate 16 random bytes for userspace PRNG seeding.
43032 */
43033 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43034 - u_rand_bytes = (elf_addr_t __user *)
43035 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43036 + srandom32(k_rand_bytes[0] ^ random32());
43037 + srandom32(k_rand_bytes[1] ^ random32());
43038 + srandom32(k_rand_bytes[2] ^ random32());
43039 + srandom32(k_rand_bytes[3] ^ random32());
43040 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43041 + u_rand_bytes = (elf_addr_t __user *) p;
43042 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43043 return -EFAULT;
43044
43045 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43046 return -EFAULT;
43047 current->mm->env_end = p;
43048
43049 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43050 +
43051 /* Put the elf_info on the stack in the right place. */
43052 sp = (elf_addr_t __user *)envp + 1;
43053 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43054 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43055 return -EFAULT;
43056 return 0;
43057 }
43058 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43059 {
43060 struct elf_phdr *elf_phdata;
43061 struct elf_phdr *eppnt;
43062 - unsigned long load_addr = 0;
43063 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43064 int load_addr_set = 0;
43065 unsigned long last_bss = 0, elf_bss = 0;
43066 - unsigned long error = ~0UL;
43067 + unsigned long error = -EINVAL;
43068 unsigned long total_size;
43069 int retval, i, size;
43070
43071 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43072 goto out_close;
43073 }
43074
43075 +#ifdef CONFIG_PAX_SEGMEXEC
43076 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43077 + pax_task_size = SEGMEXEC_TASK_SIZE;
43078 +#endif
43079 +
43080 eppnt = elf_phdata;
43081 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43082 if (eppnt->p_type == PT_LOAD) {
43083 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43084 k = load_addr + eppnt->p_vaddr;
43085 if (BAD_ADDR(k) ||
43086 eppnt->p_filesz > eppnt->p_memsz ||
43087 - eppnt->p_memsz > TASK_SIZE ||
43088 - TASK_SIZE - eppnt->p_memsz < k) {
43089 + eppnt->p_memsz > pax_task_size ||
43090 + pax_task_size - eppnt->p_memsz < k) {
43091 error = -ENOMEM;
43092 goto out_close;
43093 }
43094 @@ -528,6 +552,351 @@ out:
43095 return error;
43096 }
43097
43098 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
43099 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43100 +{
43101 + unsigned long pax_flags = 0UL;
43102 +
43103 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43104 +
43105 +#ifdef CONFIG_PAX_PAGEEXEC
43106 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43107 + pax_flags |= MF_PAX_PAGEEXEC;
43108 +#endif
43109 +
43110 +#ifdef CONFIG_PAX_SEGMEXEC
43111 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43112 + pax_flags |= MF_PAX_SEGMEXEC;
43113 +#endif
43114 +
43115 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43116 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43117 + if ((__supported_pte_mask & _PAGE_NX))
43118 + pax_flags &= ~MF_PAX_SEGMEXEC;
43119 + else
43120 + pax_flags &= ~MF_PAX_PAGEEXEC;
43121 + }
43122 +#endif
43123 +
43124 +#ifdef CONFIG_PAX_EMUTRAMP
43125 + if (elf_phdata->p_flags & PF_EMUTRAMP)
43126 + pax_flags |= MF_PAX_EMUTRAMP;
43127 +#endif
43128 +
43129 +#ifdef CONFIG_PAX_MPROTECT
43130 + if (elf_phdata->p_flags & PF_MPROTECT)
43131 + pax_flags |= MF_PAX_MPROTECT;
43132 +#endif
43133 +
43134 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43135 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43136 + pax_flags |= MF_PAX_RANDMMAP;
43137 +#endif
43138 +
43139 +#endif
43140 +
43141 + return pax_flags;
43142 +}
43143 +
43144 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43145 +{
43146 + unsigned long pax_flags = 0UL;
43147 +
43148 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43149 +
43150 +#ifdef CONFIG_PAX_PAGEEXEC
43151 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43152 + pax_flags |= MF_PAX_PAGEEXEC;
43153 +#endif
43154 +
43155 +#ifdef CONFIG_PAX_SEGMEXEC
43156 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43157 + pax_flags |= MF_PAX_SEGMEXEC;
43158 +#endif
43159 +
43160 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43161 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43162 + if ((__supported_pte_mask & _PAGE_NX))
43163 + pax_flags &= ~MF_PAX_SEGMEXEC;
43164 + else
43165 + pax_flags &= ~MF_PAX_PAGEEXEC;
43166 + }
43167 +#endif
43168 +
43169 +#ifdef CONFIG_PAX_EMUTRAMP
43170 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43171 + pax_flags |= MF_PAX_EMUTRAMP;
43172 +#endif
43173 +
43174 +#ifdef CONFIG_PAX_MPROTECT
43175 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43176 + pax_flags |= MF_PAX_MPROTECT;
43177 +#endif
43178 +
43179 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43180 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43181 + pax_flags |= MF_PAX_RANDMMAP;
43182 +#endif
43183 +
43184 +#endif
43185 +
43186 + return pax_flags;
43187 +}
43188 +
43189 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43190 +{
43191 + unsigned long pax_flags = 0UL;
43192 +
43193 +#ifdef CONFIG_PAX_EI_PAX
43194 +
43195 +#ifdef CONFIG_PAX_PAGEEXEC
43196 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43197 + pax_flags |= MF_PAX_PAGEEXEC;
43198 +#endif
43199 +
43200 +#ifdef CONFIG_PAX_SEGMEXEC
43201 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43202 + pax_flags |= MF_PAX_SEGMEXEC;
43203 +#endif
43204 +
43205 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43206 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43207 + if ((__supported_pte_mask & _PAGE_NX))
43208 + pax_flags &= ~MF_PAX_SEGMEXEC;
43209 + else
43210 + pax_flags &= ~MF_PAX_PAGEEXEC;
43211 + }
43212 +#endif
43213 +
43214 +#ifdef CONFIG_PAX_EMUTRAMP
43215 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43216 + pax_flags |= MF_PAX_EMUTRAMP;
43217 +#endif
43218 +
43219 +#ifdef CONFIG_PAX_MPROTECT
43220 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43221 + pax_flags |= MF_PAX_MPROTECT;
43222 +#endif
43223 +
43224 +#ifdef CONFIG_PAX_ASLR
43225 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43226 + pax_flags |= MF_PAX_RANDMMAP;
43227 +#endif
43228 +
43229 +#else
43230 +
43231 +#ifdef CONFIG_PAX_PAGEEXEC
43232 + pax_flags |= MF_PAX_PAGEEXEC;
43233 +#endif
43234 +
43235 +#ifdef CONFIG_PAX_MPROTECT
43236 + pax_flags |= MF_PAX_MPROTECT;
43237 +#endif
43238 +
43239 +#ifdef CONFIG_PAX_RANDMMAP
43240 + pax_flags |= MF_PAX_RANDMMAP;
43241 +#endif
43242 +
43243 +#ifdef CONFIG_PAX_SEGMEXEC
43244 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
43245 + pax_flags &= ~MF_PAX_PAGEEXEC;
43246 + pax_flags |= MF_PAX_SEGMEXEC;
43247 + }
43248 +#endif
43249 +
43250 +#endif
43251 +
43252 + return pax_flags;
43253 +}
43254 +
43255 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43256 +{
43257 +
43258 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43259 + unsigned long i;
43260 +
43261 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43262 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43263 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43264 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43265 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43266 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43267 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43268 + return ~0UL;
43269 +
43270 +#ifdef CONFIG_PAX_SOFTMODE
43271 + if (pax_softmode)
43272 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43273 + else
43274 +#endif
43275 +
43276 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43277 + break;
43278 + }
43279 +#endif
43280 +
43281 + return ~0UL;
43282 +}
43283 +
43284 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43285 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43286 +{
43287 + unsigned long pax_flags = 0UL;
43288 +
43289 +#ifdef CONFIG_PAX_PAGEEXEC
43290 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43291 + pax_flags |= MF_PAX_PAGEEXEC;
43292 +#endif
43293 +
43294 +#ifdef CONFIG_PAX_SEGMEXEC
43295 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43296 + pax_flags |= MF_PAX_SEGMEXEC;
43297 +#endif
43298 +
43299 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43300 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43301 + if ((__supported_pte_mask & _PAGE_NX))
43302 + pax_flags &= ~MF_PAX_SEGMEXEC;
43303 + else
43304 + pax_flags &= ~MF_PAX_PAGEEXEC;
43305 + }
43306 +#endif
43307 +
43308 +#ifdef CONFIG_PAX_EMUTRAMP
43309 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43310 + pax_flags |= MF_PAX_EMUTRAMP;
43311 +#endif
43312 +
43313 +#ifdef CONFIG_PAX_MPROTECT
43314 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43315 + pax_flags |= MF_PAX_MPROTECT;
43316 +#endif
43317 +
43318 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43319 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43320 + pax_flags |= MF_PAX_RANDMMAP;
43321 +#endif
43322 +
43323 + return pax_flags;
43324 +}
43325 +
43326 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43327 +{
43328 + unsigned long pax_flags = 0UL;
43329 +
43330 +#ifdef CONFIG_PAX_PAGEEXEC
43331 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43332 + pax_flags |= MF_PAX_PAGEEXEC;
43333 +#endif
43334 +
43335 +#ifdef CONFIG_PAX_SEGMEXEC
43336 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43337 + pax_flags |= MF_PAX_SEGMEXEC;
43338 +#endif
43339 +
43340 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43341 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43342 + if ((__supported_pte_mask & _PAGE_NX))
43343 + pax_flags &= ~MF_PAX_SEGMEXEC;
43344 + else
43345 + pax_flags &= ~MF_PAX_PAGEEXEC;
43346 + }
43347 +#endif
43348 +
43349 +#ifdef CONFIG_PAX_EMUTRAMP
43350 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43351 + pax_flags |= MF_PAX_EMUTRAMP;
43352 +#endif
43353 +
43354 +#ifdef CONFIG_PAX_MPROTECT
43355 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43356 + pax_flags |= MF_PAX_MPROTECT;
43357 +#endif
43358 +
43359 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43360 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43361 + pax_flags |= MF_PAX_RANDMMAP;
43362 +#endif
43363 +
43364 + return pax_flags;
43365 +}
43366 +#endif
43367 +
43368 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43369 +{
43370 +
43371 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43372 + ssize_t xattr_size, i;
43373 + unsigned char xattr_value[5];
43374 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43375 +
43376 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43377 + if (xattr_size <= 0)
43378 + return ~0UL;
43379 +
43380 + for (i = 0; i < xattr_size; i++)
43381 + switch (xattr_value[i]) {
43382 + default:
43383 + return ~0UL;
43384 +
43385 +#define parse_flag(option1, option2, flag) \
43386 + case option1: \
43387 + pax_flags_hardmode |= MF_PAX_##flag; \
43388 + break; \
43389 + case option2: \
43390 + pax_flags_softmode |= MF_PAX_##flag; \
43391 + break;
43392 +
43393 + parse_flag('p', 'P', PAGEEXEC);
43394 + parse_flag('e', 'E', EMUTRAMP);
43395 + parse_flag('m', 'M', MPROTECT);
43396 + parse_flag('r', 'R', RANDMMAP);
43397 + parse_flag('s', 'S', SEGMEXEC);
43398 +
43399 +#undef parse_flag
43400 + }
43401 +
43402 + if (pax_flags_hardmode & pax_flags_softmode)
43403 + return ~0UL;
43404 +
43405 +#ifdef CONFIG_PAX_SOFTMODE
43406 + if (pax_softmode)
43407 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43408 + else
43409 +#endif
43410 +
43411 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43412 +#else
43413 + return ~0UL;
43414 +#endif
43415 +
43416 +}
43417 +
43418 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43419 +{
43420 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43421 +
43422 + pax_flags = pax_parse_ei_pax(elf_ex);
43423 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43424 + xattr_pax_flags = pax_parse_xattr_pax(file);
43425 +
43426 + if (pt_pax_flags == ~0UL)
43427 + pt_pax_flags = xattr_pax_flags;
43428 + else if (xattr_pax_flags == ~0UL)
43429 + xattr_pax_flags = pt_pax_flags;
43430 + if (pt_pax_flags != xattr_pax_flags)
43431 + return -EINVAL;
43432 + if (pt_pax_flags != ~0UL)
43433 + pax_flags = pt_pax_flags;
43434 +
43435 + if (0 > pax_check_flags(&pax_flags))
43436 + return -EINVAL;
43437 +
43438 + current->mm->pax_flags = pax_flags;
43439 + return 0;
43440 +}
43441 +#endif
43442 +
43443 /*
43444 * These are the functions used to load ELF style executables and shared
43445 * libraries. There is no binary dependent code anywhere else.
43446 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43447 {
43448 unsigned int random_variable = 0;
43449
43450 +#ifdef CONFIG_PAX_RANDUSTACK
43451 + if (randomize_va_space)
43452 + return stack_top - current->mm->delta_stack;
43453 +#endif
43454 +
43455 if ((current->flags & PF_RANDOMIZE) &&
43456 !(current->personality & ADDR_NO_RANDOMIZE)) {
43457 random_variable = get_random_int() & STACK_RND_MASK;
43458 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43459 unsigned long load_addr = 0, load_bias = 0;
43460 int load_addr_set = 0;
43461 char * elf_interpreter = NULL;
43462 - unsigned long error;
43463 + unsigned long error = 0;
43464 struct elf_phdr *elf_ppnt, *elf_phdata;
43465 unsigned long elf_bss, elf_brk;
43466 int retval, i;
43467 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43468 unsigned long start_code, end_code, start_data, end_data;
43469 unsigned long reloc_func_desc __maybe_unused = 0;
43470 int executable_stack = EXSTACK_DEFAULT;
43471 - unsigned long def_flags = 0;
43472 struct {
43473 struct elfhdr elf_ex;
43474 struct elfhdr interp_elf_ex;
43475 } *loc;
43476 + unsigned long pax_task_size = TASK_SIZE;
43477
43478 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43479 if (!loc) {
43480 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43481
43482 /* OK, This is the point of no return */
43483 current->flags &= ~PF_FORKNOEXEC;
43484 - current->mm->def_flags = def_flags;
43485 +
43486 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43487 + current->mm->pax_flags = 0UL;
43488 +#endif
43489 +
43490 +#ifdef CONFIG_PAX_DLRESOLVE
43491 + current->mm->call_dl_resolve = 0UL;
43492 +#endif
43493 +
43494 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43495 + current->mm->call_syscall = 0UL;
43496 +#endif
43497 +
43498 +#ifdef CONFIG_PAX_ASLR
43499 + current->mm->delta_mmap = 0UL;
43500 + current->mm->delta_stack = 0UL;
43501 +#endif
43502 +
43503 + current->mm->def_flags = 0;
43504 +
43505 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
43506 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43507 + send_sig(SIGKILL, current, 0);
43508 + goto out_free_dentry;
43509 + }
43510 +#endif
43511 +
43512 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43513 + pax_set_initial_flags(bprm);
43514 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43515 + if (pax_set_initial_flags_func)
43516 + (pax_set_initial_flags_func)(bprm);
43517 +#endif
43518 +
43519 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43520 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43521 + current->mm->context.user_cs_limit = PAGE_SIZE;
43522 + current->mm->def_flags |= VM_PAGEEXEC;
43523 + }
43524 +#endif
43525 +
43526 +#ifdef CONFIG_PAX_SEGMEXEC
43527 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43528 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43529 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43530 + pax_task_size = SEGMEXEC_TASK_SIZE;
43531 + current->mm->def_flags |= VM_NOHUGEPAGE;
43532 + }
43533 +#endif
43534 +
43535 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43536 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43537 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43538 + put_cpu();
43539 + }
43540 +#endif
43541
43542 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43543 may depend on the personality. */
43544 SET_PERSONALITY(loc->elf_ex);
43545 +
43546 +#ifdef CONFIG_PAX_ASLR
43547 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43548 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43549 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43550 + }
43551 +#endif
43552 +
43553 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43554 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43555 + executable_stack = EXSTACK_DISABLE_X;
43556 + current->personality &= ~READ_IMPLIES_EXEC;
43557 + } else
43558 +#endif
43559 +
43560 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43561 current->personality |= READ_IMPLIES_EXEC;
43562
43563 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43564 #else
43565 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43566 #endif
43567 +
43568 +#ifdef CONFIG_PAX_RANDMMAP
43569 + /* PaX: randomize base address at the default exe base if requested */
43570 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43571 +#ifdef CONFIG_SPARC64
43572 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43573 +#else
43574 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43575 +#endif
43576 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43577 + elf_flags |= MAP_FIXED;
43578 + }
43579 +#endif
43580 +
43581 }
43582
43583 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43584 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43585 * allowed task size. Note that p_filesz must always be
43586 * <= p_memsz so it is only necessary to check p_memsz.
43587 */
43588 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43589 - elf_ppnt->p_memsz > TASK_SIZE ||
43590 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43591 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43592 + elf_ppnt->p_memsz > pax_task_size ||
43593 + pax_task_size - elf_ppnt->p_memsz < k) {
43594 /* set_brk can never work. Avoid overflows. */
43595 send_sig(SIGKILL, current, 0);
43596 retval = -EINVAL;
43597 @@ -881,11 +1339,40 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43598 goto out_free_dentry;
43599 }
43600 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43601 - send_sig(SIGSEGV, current, 0);
43602 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43603 - goto out_free_dentry;
43604 + /*
43605 + * This bss-zeroing can fail if the ELF
43606 + * file specifies odd protections. So
43607 + * we don't check the return value
43608 + */
43609 }
43610
43611 +#ifdef CONFIG_PAX_RANDMMAP
43612 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43613 + unsigned long start, size;
43614 +
43615 + start = ELF_PAGEALIGN(elf_brk);
43616 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43617 + down_write(&current->mm->mmap_sem);
43618 + retval = -ENOMEM;
43619 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43620 + unsigned long prot = PROT_NONE;
43621 +
43622 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43623 +// if (current->personality & ADDR_NO_RANDOMIZE)
43624 +// prot = PROT_READ;
43625 + start = do_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43626 + retval = IS_ERR_VALUE(start) ? start : 0;
43627 + }
43628 + up_write(&current->mm->mmap_sem);
43629 + if (retval == 0)
43630 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43631 + if (retval < 0) {
43632 + send_sig(SIGKILL, current, 0);
43633 + goto out_free_dentry;
43634 + }
43635 + }
43636 +#endif
43637 +
43638 if (elf_interpreter) {
43639 unsigned long uninitialized_var(interp_map_addr);
43640
43641 @@ -1098,7 +1585,7 @@ out:
43642 * Decide what to dump of a segment, part, all or none.
43643 */
43644 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43645 - unsigned long mm_flags)
43646 + unsigned long mm_flags, long signr)
43647 {
43648 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43649
43650 @@ -1132,7 +1619,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43651 if (vma->vm_file == NULL)
43652 return 0;
43653
43654 - if (FILTER(MAPPED_PRIVATE))
43655 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43656 goto whole;
43657
43658 /*
43659 @@ -1354,9 +1841,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43660 {
43661 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43662 int i = 0;
43663 - do
43664 + do {
43665 i += 2;
43666 - while (auxv[i - 2] != AT_NULL);
43667 + } while (auxv[i - 2] != AT_NULL);
43668 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43669 }
43670
43671 @@ -1862,14 +2349,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43672 }
43673
43674 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43675 - unsigned long mm_flags)
43676 + struct coredump_params *cprm)
43677 {
43678 struct vm_area_struct *vma;
43679 size_t size = 0;
43680
43681 for (vma = first_vma(current, gate_vma); vma != NULL;
43682 vma = next_vma(vma, gate_vma))
43683 - size += vma_dump_size(vma, mm_flags);
43684 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43685 return size;
43686 }
43687
43688 @@ -1963,7 +2450,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43689
43690 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43691
43692 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43693 + offset += elf_core_vma_data_size(gate_vma, cprm);
43694 offset += elf_core_extra_data_size();
43695 e_shoff = offset;
43696
43697 @@ -1977,10 +2464,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43698 offset = dataoff;
43699
43700 size += sizeof(*elf);
43701 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43702 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43703 goto end_coredump;
43704
43705 size += sizeof(*phdr4note);
43706 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43707 if (size > cprm->limit
43708 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43709 goto end_coredump;
43710 @@ -1994,7 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43711 phdr.p_offset = offset;
43712 phdr.p_vaddr = vma->vm_start;
43713 phdr.p_paddr = 0;
43714 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43715 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43716 phdr.p_memsz = vma->vm_end - vma->vm_start;
43717 offset += phdr.p_filesz;
43718 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43719 @@ -2005,6 +2494,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43720 phdr.p_align = ELF_EXEC_PAGESIZE;
43721
43722 size += sizeof(phdr);
43723 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43724 if (size > cprm->limit
43725 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43726 goto end_coredump;
43727 @@ -2029,7 +2519,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43728 unsigned long addr;
43729 unsigned long end;
43730
43731 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43732 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43733
43734 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43735 struct page *page;
43736 @@ -2038,6 +2528,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43737 page = get_dump_page(addr);
43738 if (page) {
43739 void *kaddr = kmap(page);
43740 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43741 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43742 !dump_write(cprm->file, kaddr,
43743 PAGE_SIZE);
43744 @@ -2055,6 +2546,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43745
43746 if (e_phnum == PN_XNUM) {
43747 size += sizeof(*shdr4extnum);
43748 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43749 if (size > cprm->limit
43750 || !dump_write(cprm->file, shdr4extnum,
43751 sizeof(*shdr4extnum)))
43752 @@ -2075,6 +2567,97 @@ out:
43753
43754 #endif /* CONFIG_ELF_CORE */
43755
43756 +#ifdef CONFIG_PAX_MPROTECT
43757 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43758 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43759 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43760 + *
43761 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43762 + * basis because we want to allow the common case and not the special ones.
43763 + */
43764 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43765 +{
43766 + struct elfhdr elf_h;
43767 + struct elf_phdr elf_p;
43768 + unsigned long i;
43769 + unsigned long oldflags;
43770 + bool is_textrel_rw, is_textrel_rx, is_relro;
43771 +
43772 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43773 + return;
43774 +
43775 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43776 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43777 +
43778 +#ifdef CONFIG_PAX_ELFRELOCS
43779 + /* possible TEXTREL */
43780 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43781 + 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);
43782 +#else
43783 + is_textrel_rw = false;
43784 + is_textrel_rx = false;
43785 +#endif
43786 +
43787 + /* possible RELRO */
43788 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43789 +
43790 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43791 + return;
43792 +
43793 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43794 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43795 +
43796 +#ifdef CONFIG_PAX_ETEXECRELOCS
43797 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43798 +#else
43799 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43800 +#endif
43801 +
43802 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43803 + !elf_check_arch(&elf_h) ||
43804 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43805 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43806 + return;
43807 +
43808 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43809 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43810 + return;
43811 + switch (elf_p.p_type) {
43812 + case PT_DYNAMIC:
43813 + if (!is_textrel_rw && !is_textrel_rx)
43814 + continue;
43815 + i = 0UL;
43816 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43817 + elf_dyn dyn;
43818 +
43819 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43820 + return;
43821 + if (dyn.d_tag == DT_NULL)
43822 + return;
43823 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43824 + gr_log_textrel(vma);
43825 + if (is_textrel_rw)
43826 + vma->vm_flags |= VM_MAYWRITE;
43827 + else
43828 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43829 + vma->vm_flags &= ~VM_MAYWRITE;
43830 + return;
43831 + }
43832 + i++;
43833 + }
43834 + return;
43835 +
43836 + case PT_GNU_RELRO:
43837 + if (!is_relro)
43838 + continue;
43839 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43840 + vma->vm_flags &= ~VM_MAYWRITE;
43841 + return;
43842 + }
43843 + }
43844 +}
43845 +#endif
43846 +
43847 static int __init init_elf_binfmt(void)
43848 {
43849 return register_binfmt(&elf_format);
43850 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43851 index 1bffbe0..c8c283e 100644
43852 --- a/fs/binfmt_flat.c
43853 +++ b/fs/binfmt_flat.c
43854 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43855 realdatastart = (unsigned long) -ENOMEM;
43856 printk("Unable to allocate RAM for process data, errno %d\n",
43857 (int)-realdatastart);
43858 + down_write(&current->mm->mmap_sem);
43859 do_munmap(current->mm, textpos, text_len);
43860 + up_write(&current->mm->mmap_sem);
43861 ret = realdatastart;
43862 goto err;
43863 }
43864 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43865 }
43866 if (IS_ERR_VALUE(result)) {
43867 printk("Unable to read data+bss, errno %d\n", (int)-result);
43868 + down_write(&current->mm->mmap_sem);
43869 do_munmap(current->mm, textpos, text_len);
43870 do_munmap(current->mm, realdatastart, len);
43871 + up_write(&current->mm->mmap_sem);
43872 ret = result;
43873 goto err;
43874 }
43875 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43876 }
43877 if (IS_ERR_VALUE(result)) {
43878 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43879 + down_write(&current->mm->mmap_sem);
43880 do_munmap(current->mm, textpos, text_len + data_len + extra +
43881 MAX_SHARED_LIBS * sizeof(unsigned long));
43882 + up_write(&current->mm->mmap_sem);
43883 ret = result;
43884 goto err;
43885 }
43886 diff --git a/fs/bio.c b/fs/bio.c
43887 index b980ecd..74800bf 100644
43888 --- a/fs/bio.c
43889 +++ b/fs/bio.c
43890 @@ -833,7 +833,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43891 /*
43892 * Overflow, abort
43893 */
43894 - if (end < start)
43895 + if (end < start || end - start > INT_MAX - nr_pages)
43896 return ERR_PTR(-EINVAL);
43897
43898 nr_pages += end - start;
43899 @@ -1229,7 +1229,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43900 const int read = bio_data_dir(bio) == READ;
43901 struct bio_map_data *bmd = bio->bi_private;
43902 int i;
43903 - char *p = bmd->sgvecs[0].iov_base;
43904 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43905
43906 __bio_for_each_segment(bvec, bio, i, 0) {
43907 char *addr = page_address(bvec->bv_page);
43908 diff --git a/fs/block_dev.c b/fs/block_dev.c
43909 index 5e9f198..6bf9b1c 100644
43910 --- a/fs/block_dev.c
43911 +++ b/fs/block_dev.c
43912 @@ -703,7 +703,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43913 else if (bdev->bd_contains == bdev)
43914 return true; /* is a whole device which isn't held */
43915
43916 - else if (whole->bd_holder == bd_may_claim)
43917 + else if (whole->bd_holder == (void *)bd_may_claim)
43918 return true; /* is a partition of a device that is being partitioned */
43919 else if (whole->bd_holder != NULL)
43920 return false; /* is a partition of a held device */
43921 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43922 index d986824..af1befd 100644
43923 --- a/fs/btrfs/check-integrity.c
43924 +++ b/fs/btrfs/check-integrity.c
43925 @@ -157,7 +157,7 @@ struct btrfsic_block {
43926 union {
43927 bio_end_io_t *bio;
43928 bh_end_io_t *bh;
43929 - } orig_bio_bh_end_io;
43930 + } __no_const orig_bio_bh_end_io;
43931 int submit_bio_bh_rw;
43932 u64 flush_gen; /* only valid if !never_written */
43933 };
43934 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43935 index 0639a55..7d9e07f 100644
43936 --- a/fs/btrfs/ctree.c
43937 +++ b/fs/btrfs/ctree.c
43938 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43939 free_extent_buffer(buf);
43940 add_root_to_dirty_list(root);
43941 } else {
43942 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43943 - parent_start = parent->start;
43944 - else
43945 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43946 + if (parent)
43947 + parent_start = parent->start;
43948 + else
43949 + parent_start = 0;
43950 + } else
43951 parent_start = 0;
43952
43953 WARN_ON(trans->transid != btrfs_header_generation(parent));
43954 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43955 index 892b347..b3db246 100644
43956 --- a/fs/btrfs/inode.c
43957 +++ b/fs/btrfs/inode.c
43958 @@ -6930,7 +6930,7 @@ fail:
43959 return -ENOMEM;
43960 }
43961
43962 -static int btrfs_getattr(struct vfsmount *mnt,
43963 +int btrfs_getattr(struct vfsmount *mnt,
43964 struct dentry *dentry, struct kstat *stat)
43965 {
43966 struct inode *inode = dentry->d_inode;
43967 @@ -6944,6 +6944,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43968 return 0;
43969 }
43970
43971 +EXPORT_SYMBOL(btrfs_getattr);
43972 +
43973 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43974 +{
43975 + return BTRFS_I(inode)->root->anon_dev;
43976 +}
43977 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43978 +
43979 /*
43980 * If a file is moved, it will inherit the cow and compression flags of the new
43981 * directory.
43982 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43983 index 1b36f19..5ac7360 100644
43984 --- a/fs/btrfs/ioctl.c
43985 +++ b/fs/btrfs/ioctl.c
43986 @@ -2783,9 +2783,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43987 for (i = 0; i < num_types; i++) {
43988 struct btrfs_space_info *tmp;
43989
43990 + /* Don't copy in more than we allocated */
43991 if (!slot_count)
43992 break;
43993
43994 + slot_count--;
43995 +
43996 info = NULL;
43997 rcu_read_lock();
43998 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43999 @@ -2807,15 +2810,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44000 memcpy(dest, &space, sizeof(space));
44001 dest++;
44002 space_args.total_spaces++;
44003 - slot_count--;
44004 }
44005 - if (!slot_count)
44006 - break;
44007 }
44008 up_read(&info->groups_sem);
44009 }
44010
44011 - user_dest = (struct btrfs_ioctl_space_info *)
44012 + user_dest = (struct btrfs_ioctl_space_info __user *)
44013 (arg + sizeof(struct btrfs_ioctl_space_args));
44014
44015 if (copy_to_user(user_dest, dest_orig, alloc_size))
44016 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
44017 index 8c1aae2..1e46446 100644
44018 --- a/fs/btrfs/relocation.c
44019 +++ b/fs/btrfs/relocation.c
44020 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
44021 }
44022 spin_unlock(&rc->reloc_root_tree.lock);
44023
44024 - BUG_ON((struct btrfs_root *)node->data != root);
44025 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
44026
44027 if (!del) {
44028 spin_lock(&rc->reloc_root_tree.lock);
44029 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
44030 index 622f469..e8d2d55 100644
44031 --- a/fs/cachefiles/bind.c
44032 +++ b/fs/cachefiles/bind.c
44033 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
44034 args);
44035
44036 /* start by checking things over */
44037 - ASSERT(cache->fstop_percent >= 0 &&
44038 - cache->fstop_percent < cache->fcull_percent &&
44039 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
44040 cache->fcull_percent < cache->frun_percent &&
44041 cache->frun_percent < 100);
44042
44043 - ASSERT(cache->bstop_percent >= 0 &&
44044 - cache->bstop_percent < cache->bcull_percent &&
44045 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44046 cache->bcull_percent < cache->brun_percent &&
44047 cache->brun_percent < 100);
44048
44049 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
44050 index 0a1467b..6a53245 100644
44051 --- a/fs/cachefiles/daemon.c
44052 +++ b/fs/cachefiles/daemon.c
44053 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
44054 if (n > buflen)
44055 return -EMSGSIZE;
44056
44057 - if (copy_to_user(_buffer, buffer, n) != 0)
44058 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44059 return -EFAULT;
44060
44061 return n;
44062 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44063 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44064 return -EIO;
44065
44066 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44067 + if (datalen > PAGE_SIZE - 1)
44068 return -EOPNOTSUPP;
44069
44070 /* drag the command string into the kernel so we can parse it */
44071 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44072 if (args[0] != '%' || args[1] != '\0')
44073 return -EINVAL;
44074
44075 - if (fstop < 0 || fstop >= cache->fcull_percent)
44076 + if (fstop >= cache->fcull_percent)
44077 return cachefiles_daemon_range_error(cache, args);
44078
44079 cache->fstop_percent = fstop;
44080 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44081 if (args[0] != '%' || args[1] != '\0')
44082 return -EINVAL;
44083
44084 - if (bstop < 0 || bstop >= cache->bcull_percent)
44085 + if (bstop >= cache->bcull_percent)
44086 return cachefiles_daemon_range_error(cache, args);
44087
44088 cache->bstop_percent = bstop;
44089 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44090 index bd6bc1b..b627b53 100644
44091 --- a/fs/cachefiles/internal.h
44092 +++ b/fs/cachefiles/internal.h
44093 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44094 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44095 struct rb_root active_nodes; /* active nodes (can't be culled) */
44096 rwlock_t active_lock; /* lock for active_nodes */
44097 - atomic_t gravecounter; /* graveyard uniquifier */
44098 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44099 unsigned frun_percent; /* when to stop culling (% files) */
44100 unsigned fcull_percent; /* when to start culling (% files) */
44101 unsigned fstop_percent; /* when to stop allocating (% files) */
44102 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44103 * proc.c
44104 */
44105 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44106 -extern atomic_t cachefiles_lookup_histogram[HZ];
44107 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44108 -extern atomic_t cachefiles_create_histogram[HZ];
44109 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44110 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44111 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44112
44113 extern int __init cachefiles_proc_init(void);
44114 extern void cachefiles_proc_cleanup(void);
44115 static inline
44116 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44117 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44118 {
44119 unsigned long jif = jiffies - start_jif;
44120 if (jif >= HZ)
44121 jif = HZ - 1;
44122 - atomic_inc(&histogram[jif]);
44123 + atomic_inc_unchecked(&histogram[jif]);
44124 }
44125
44126 #else
44127 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44128 index a0358c2..d6137f2 100644
44129 --- a/fs/cachefiles/namei.c
44130 +++ b/fs/cachefiles/namei.c
44131 @@ -318,7 +318,7 @@ try_again:
44132 /* first step is to make up a grave dentry in the graveyard */
44133 sprintf(nbuffer, "%08x%08x",
44134 (uint32_t) get_seconds(),
44135 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44136 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44137
44138 /* do the multiway lock magic */
44139 trap = lock_rename(cache->graveyard, dir);
44140 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44141 index eccd339..4c1d995 100644
44142 --- a/fs/cachefiles/proc.c
44143 +++ b/fs/cachefiles/proc.c
44144 @@ -14,9 +14,9 @@
44145 #include <linux/seq_file.h>
44146 #include "internal.h"
44147
44148 -atomic_t cachefiles_lookup_histogram[HZ];
44149 -atomic_t cachefiles_mkdir_histogram[HZ];
44150 -atomic_t cachefiles_create_histogram[HZ];
44151 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44152 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44153 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44154
44155 /*
44156 * display the latency histogram
44157 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44158 return 0;
44159 default:
44160 index = (unsigned long) v - 3;
44161 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44162 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44163 - z = atomic_read(&cachefiles_create_histogram[index]);
44164 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44165 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44166 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44167 if (x == 0 && y == 0 && z == 0)
44168 return 0;
44169
44170 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44171 index 0e3c092..818480e 100644
44172 --- a/fs/cachefiles/rdwr.c
44173 +++ b/fs/cachefiles/rdwr.c
44174 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44175 old_fs = get_fs();
44176 set_fs(KERNEL_DS);
44177 ret = file->f_op->write(
44178 - file, (const void __user *) data, len, &pos);
44179 + file, (const void __force_user *) data, len, &pos);
44180 set_fs(old_fs);
44181 kunmap(page);
44182 if (ret != len)
44183 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44184 index 3e8094b..cb3ff3d 100644
44185 --- a/fs/ceph/dir.c
44186 +++ b/fs/ceph/dir.c
44187 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44188 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44189 struct ceph_mds_client *mdsc = fsc->mdsc;
44190 unsigned frag = fpos_frag(filp->f_pos);
44191 - int off = fpos_off(filp->f_pos);
44192 + unsigned int off = fpos_off(filp->f_pos);
44193 int err;
44194 u32 ftype;
44195 struct ceph_mds_reply_info_parsed *rinfo;
44196 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
44197 if (nd &&
44198 (nd->flags & LOOKUP_OPEN) &&
44199 !(nd->intent.open.flags & O_CREAT)) {
44200 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
44201 + int mode = nd->intent.open.create_mode & ~current_umask();
44202 return ceph_lookup_open(dir, dentry, nd, mode, 1);
44203 }
44204
44205 diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c
44206 index cfd1ce3..6b13a74 100644
44207 --- a/fs/cifs/asn1.c
44208 +++ b/fs/cifs/asn1.c
44209 @@ -416,6 +416,9 @@ asn1_subid_decode(struct asn1_ctx *ctx, unsigned long *subid)
44210
44211 static int
44212 asn1_oid_decode(struct asn1_ctx *ctx,
44213 + unsigned char *eoc, unsigned long **oid, unsigned int *len) __size_overflow(2);
44214 +static int
44215 +asn1_oid_decode(struct asn1_ctx *ctx,
44216 unsigned char *eoc, unsigned long **oid, unsigned int *len)
44217 {
44218 unsigned long subid;
44219 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44220 index 24b3dfc..3cd5454 100644
44221 --- a/fs/cifs/cifs_debug.c
44222 +++ b/fs/cifs/cifs_debug.c
44223 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44224
44225 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44226 #ifdef CONFIG_CIFS_STATS2
44227 - atomic_set(&totBufAllocCount, 0);
44228 - atomic_set(&totSmBufAllocCount, 0);
44229 + atomic_set_unchecked(&totBufAllocCount, 0);
44230 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44231 #endif /* CONFIG_CIFS_STATS2 */
44232 spin_lock(&cifs_tcp_ses_lock);
44233 list_for_each(tmp1, &cifs_tcp_ses_list) {
44234 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44235 tcon = list_entry(tmp3,
44236 struct cifs_tcon,
44237 tcon_list);
44238 - atomic_set(&tcon->num_smbs_sent, 0);
44239 - atomic_set(&tcon->num_writes, 0);
44240 - atomic_set(&tcon->num_reads, 0);
44241 - atomic_set(&tcon->num_oplock_brks, 0);
44242 - atomic_set(&tcon->num_opens, 0);
44243 - atomic_set(&tcon->num_posixopens, 0);
44244 - atomic_set(&tcon->num_posixmkdirs, 0);
44245 - atomic_set(&tcon->num_closes, 0);
44246 - atomic_set(&tcon->num_deletes, 0);
44247 - atomic_set(&tcon->num_mkdirs, 0);
44248 - atomic_set(&tcon->num_rmdirs, 0);
44249 - atomic_set(&tcon->num_renames, 0);
44250 - atomic_set(&tcon->num_t2renames, 0);
44251 - atomic_set(&tcon->num_ffirst, 0);
44252 - atomic_set(&tcon->num_fnext, 0);
44253 - atomic_set(&tcon->num_fclose, 0);
44254 - atomic_set(&tcon->num_hardlinks, 0);
44255 - atomic_set(&tcon->num_symlinks, 0);
44256 - atomic_set(&tcon->num_locks, 0);
44257 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44258 + atomic_set_unchecked(&tcon->num_writes, 0);
44259 + atomic_set_unchecked(&tcon->num_reads, 0);
44260 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
44261 + atomic_set_unchecked(&tcon->num_opens, 0);
44262 + atomic_set_unchecked(&tcon->num_posixopens, 0);
44263 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
44264 + atomic_set_unchecked(&tcon->num_closes, 0);
44265 + atomic_set_unchecked(&tcon->num_deletes, 0);
44266 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
44267 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
44268 + atomic_set_unchecked(&tcon->num_renames, 0);
44269 + atomic_set_unchecked(&tcon->num_t2renames, 0);
44270 + atomic_set_unchecked(&tcon->num_ffirst, 0);
44271 + atomic_set_unchecked(&tcon->num_fnext, 0);
44272 + atomic_set_unchecked(&tcon->num_fclose, 0);
44273 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
44274 + atomic_set_unchecked(&tcon->num_symlinks, 0);
44275 + atomic_set_unchecked(&tcon->num_locks, 0);
44276 }
44277 }
44278 }
44279 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44280 smBufAllocCount.counter, cifs_min_small);
44281 #ifdef CONFIG_CIFS_STATS2
44282 seq_printf(m, "Total Large %d Small %d Allocations\n",
44283 - atomic_read(&totBufAllocCount),
44284 - atomic_read(&totSmBufAllocCount));
44285 + atomic_read_unchecked(&totBufAllocCount),
44286 + atomic_read_unchecked(&totSmBufAllocCount));
44287 #endif /* CONFIG_CIFS_STATS2 */
44288
44289 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44290 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44291 if (tcon->need_reconnect)
44292 seq_puts(m, "\tDISCONNECTED ");
44293 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
44294 - atomic_read(&tcon->num_smbs_sent),
44295 - atomic_read(&tcon->num_oplock_brks));
44296 + atomic_read_unchecked(&tcon->num_smbs_sent),
44297 + atomic_read_unchecked(&tcon->num_oplock_brks));
44298 seq_printf(m, "\nReads: %d Bytes: %lld",
44299 - atomic_read(&tcon->num_reads),
44300 + atomic_read_unchecked(&tcon->num_reads),
44301 (long long)(tcon->bytes_read));
44302 seq_printf(m, "\nWrites: %d Bytes: %lld",
44303 - atomic_read(&tcon->num_writes),
44304 + atomic_read_unchecked(&tcon->num_writes),
44305 (long long)(tcon->bytes_written));
44306 seq_printf(m, "\nFlushes: %d",
44307 - atomic_read(&tcon->num_flushes));
44308 + atomic_read_unchecked(&tcon->num_flushes));
44309 seq_printf(m, "\nLocks: %d HardLinks: %d "
44310 "Symlinks: %d",
44311 - atomic_read(&tcon->num_locks),
44312 - atomic_read(&tcon->num_hardlinks),
44313 - atomic_read(&tcon->num_symlinks));
44314 + atomic_read_unchecked(&tcon->num_locks),
44315 + atomic_read_unchecked(&tcon->num_hardlinks),
44316 + atomic_read_unchecked(&tcon->num_symlinks));
44317 seq_printf(m, "\nOpens: %d Closes: %d "
44318 "Deletes: %d",
44319 - atomic_read(&tcon->num_opens),
44320 - atomic_read(&tcon->num_closes),
44321 - atomic_read(&tcon->num_deletes));
44322 + atomic_read_unchecked(&tcon->num_opens),
44323 + atomic_read_unchecked(&tcon->num_closes),
44324 + atomic_read_unchecked(&tcon->num_deletes));
44325 seq_printf(m, "\nPosix Opens: %d "
44326 "Posix Mkdirs: %d",
44327 - atomic_read(&tcon->num_posixopens),
44328 - atomic_read(&tcon->num_posixmkdirs));
44329 + atomic_read_unchecked(&tcon->num_posixopens),
44330 + atomic_read_unchecked(&tcon->num_posixmkdirs));
44331 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44332 - atomic_read(&tcon->num_mkdirs),
44333 - atomic_read(&tcon->num_rmdirs));
44334 + atomic_read_unchecked(&tcon->num_mkdirs),
44335 + atomic_read_unchecked(&tcon->num_rmdirs));
44336 seq_printf(m, "\nRenames: %d T2 Renames %d",
44337 - atomic_read(&tcon->num_renames),
44338 - atomic_read(&tcon->num_t2renames));
44339 + atomic_read_unchecked(&tcon->num_renames),
44340 + atomic_read_unchecked(&tcon->num_t2renames));
44341 seq_printf(m, "\nFindFirst: %d FNext %d "
44342 "FClose %d",
44343 - atomic_read(&tcon->num_ffirst),
44344 - atomic_read(&tcon->num_fnext),
44345 - atomic_read(&tcon->num_fclose));
44346 + atomic_read_unchecked(&tcon->num_ffirst),
44347 + atomic_read_unchecked(&tcon->num_fnext),
44348 + atomic_read_unchecked(&tcon->num_fclose));
44349 }
44350 }
44351 }
44352 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44353 index 6ee1cb4..8443157 100644
44354 --- a/fs/cifs/cifsfs.c
44355 +++ b/fs/cifs/cifsfs.c
44356 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
44357 cifs_req_cachep = kmem_cache_create("cifs_request",
44358 CIFSMaxBufSize +
44359 MAX_CIFS_HDR_SIZE, 0,
44360 - SLAB_HWCACHE_ALIGN, NULL);
44361 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44362 if (cifs_req_cachep == NULL)
44363 return -ENOMEM;
44364
44365 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
44366 efficient to alloc 1 per page off the slab compared to 17K (5page)
44367 alloc of large cifs buffers even when page debugging is on */
44368 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44369 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44370 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44371 NULL);
44372 if (cifs_sm_req_cachep == NULL) {
44373 mempool_destroy(cifs_req_poolp);
44374 @@ -1101,8 +1101,8 @@ init_cifs(void)
44375 atomic_set(&bufAllocCount, 0);
44376 atomic_set(&smBufAllocCount, 0);
44377 #ifdef CONFIG_CIFS_STATS2
44378 - atomic_set(&totBufAllocCount, 0);
44379 - atomic_set(&totSmBufAllocCount, 0);
44380 + atomic_set_unchecked(&totBufAllocCount, 0);
44381 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44382 #endif /* CONFIG_CIFS_STATS2 */
44383
44384 atomic_set(&midCount, 0);
44385 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44386 index d47d20a..77e8b33 100644
44387 --- a/fs/cifs/cifsglob.h
44388 +++ b/fs/cifs/cifsglob.h
44389 @@ -388,28 +388,28 @@ struct cifs_tcon {
44390 __u16 Flags; /* optional support bits */
44391 enum statusEnum tidStatus;
44392 #ifdef CONFIG_CIFS_STATS
44393 - atomic_t num_smbs_sent;
44394 - atomic_t num_writes;
44395 - atomic_t num_reads;
44396 - atomic_t num_flushes;
44397 - atomic_t num_oplock_brks;
44398 - atomic_t num_opens;
44399 - atomic_t num_closes;
44400 - atomic_t num_deletes;
44401 - atomic_t num_mkdirs;
44402 - atomic_t num_posixopens;
44403 - atomic_t num_posixmkdirs;
44404 - atomic_t num_rmdirs;
44405 - atomic_t num_renames;
44406 - atomic_t num_t2renames;
44407 - atomic_t num_ffirst;
44408 - atomic_t num_fnext;
44409 - atomic_t num_fclose;
44410 - atomic_t num_hardlinks;
44411 - atomic_t num_symlinks;
44412 - atomic_t num_locks;
44413 - atomic_t num_acl_get;
44414 - atomic_t num_acl_set;
44415 + atomic_unchecked_t num_smbs_sent;
44416 + atomic_unchecked_t num_writes;
44417 + atomic_unchecked_t num_reads;
44418 + atomic_unchecked_t num_flushes;
44419 + atomic_unchecked_t num_oplock_brks;
44420 + atomic_unchecked_t num_opens;
44421 + atomic_unchecked_t num_closes;
44422 + atomic_unchecked_t num_deletes;
44423 + atomic_unchecked_t num_mkdirs;
44424 + atomic_unchecked_t num_posixopens;
44425 + atomic_unchecked_t num_posixmkdirs;
44426 + atomic_unchecked_t num_rmdirs;
44427 + atomic_unchecked_t num_renames;
44428 + atomic_unchecked_t num_t2renames;
44429 + atomic_unchecked_t num_ffirst;
44430 + atomic_unchecked_t num_fnext;
44431 + atomic_unchecked_t num_fclose;
44432 + atomic_unchecked_t num_hardlinks;
44433 + atomic_unchecked_t num_symlinks;
44434 + atomic_unchecked_t num_locks;
44435 + atomic_unchecked_t num_acl_get;
44436 + atomic_unchecked_t num_acl_set;
44437 #ifdef CONFIG_CIFS_STATS2
44438 unsigned long long time_writes;
44439 unsigned long long time_reads;
44440 @@ -624,7 +624,7 @@ convert_delimiter(char *path, char delim)
44441 }
44442
44443 #ifdef CONFIG_CIFS_STATS
44444 -#define cifs_stats_inc atomic_inc
44445 +#define cifs_stats_inc atomic_inc_unchecked
44446
44447 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44448 unsigned int bytes)
44449 @@ -983,8 +983,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44450 /* Various Debug counters */
44451 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44452 #ifdef CONFIG_CIFS_STATS2
44453 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44454 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44455 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44456 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44457 #endif
44458 GLOBAL_EXTERN atomic_t smBufAllocCount;
44459 GLOBAL_EXTERN atomic_t midCount;
44460 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44461 index 6b0e064..94e6c3c 100644
44462 --- a/fs/cifs/link.c
44463 +++ b/fs/cifs/link.c
44464 @@ -600,7 +600,7 @@ symlink_exit:
44465
44466 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44467 {
44468 - char *p = nd_get_link(nd);
44469 + const char *p = nd_get_link(nd);
44470 if (!IS_ERR(p))
44471 kfree(p);
44472 }
44473 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44474 index 703ef5c..2a44ed5 100644
44475 --- a/fs/cifs/misc.c
44476 +++ b/fs/cifs/misc.c
44477 @@ -156,7 +156,7 @@ cifs_buf_get(void)
44478 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
44479 atomic_inc(&bufAllocCount);
44480 #ifdef CONFIG_CIFS_STATS2
44481 - atomic_inc(&totBufAllocCount);
44482 + atomic_inc_unchecked(&totBufAllocCount);
44483 #endif /* CONFIG_CIFS_STATS2 */
44484 }
44485
44486 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
44487 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44488 atomic_inc(&smBufAllocCount);
44489 #ifdef CONFIG_CIFS_STATS2
44490 - atomic_inc(&totSmBufAllocCount);
44491 + atomic_inc_unchecked(&totSmBufAllocCount);
44492 #endif /* CONFIG_CIFS_STATS2 */
44493
44494 }
44495 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44496 index 6901578..d402eb5 100644
44497 --- a/fs/coda/cache.c
44498 +++ b/fs/coda/cache.c
44499 @@ -24,7 +24,7 @@
44500 #include "coda_linux.h"
44501 #include "coda_cache.h"
44502
44503 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44504 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44505
44506 /* replace or extend an acl cache hit */
44507 void coda_cache_enter(struct inode *inode, int mask)
44508 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44509 struct coda_inode_info *cii = ITOC(inode);
44510
44511 spin_lock(&cii->c_lock);
44512 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44513 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44514 if (cii->c_uid != current_fsuid()) {
44515 cii->c_uid = current_fsuid();
44516 cii->c_cached_perm = mask;
44517 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44518 {
44519 struct coda_inode_info *cii = ITOC(inode);
44520 spin_lock(&cii->c_lock);
44521 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44522 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44523 spin_unlock(&cii->c_lock);
44524 }
44525
44526 /* remove all acl caches */
44527 void coda_cache_clear_all(struct super_block *sb)
44528 {
44529 - atomic_inc(&permission_epoch);
44530 + atomic_inc_unchecked(&permission_epoch);
44531 }
44532
44533
44534 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44535 spin_lock(&cii->c_lock);
44536 hit = (mask & cii->c_cached_perm) == mask &&
44537 cii->c_uid == current_fsuid() &&
44538 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44539 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44540 spin_unlock(&cii->c_lock);
44541
44542 return hit;
44543 diff --git a/fs/compat.c b/fs/compat.c
44544 index 07880ba..3fb2862 100644
44545 --- a/fs/compat.c
44546 +++ b/fs/compat.c
44547 @@ -491,7 +491,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44548
44549 set_fs(KERNEL_DS);
44550 /* The __user pointer cast is valid because of the set_fs() */
44551 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44552 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44553 set_fs(oldfs);
44554 /* truncating is ok because it's a user address */
44555 if (!ret)
44556 @@ -549,7 +549,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44557 goto out;
44558
44559 ret = -EINVAL;
44560 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44561 + if (nr_segs > UIO_MAXIOV)
44562 goto out;
44563 if (nr_segs > fast_segs) {
44564 ret = -ENOMEM;
44565 @@ -832,6 +832,7 @@ struct compat_old_linux_dirent {
44566
44567 struct compat_readdir_callback {
44568 struct compat_old_linux_dirent __user *dirent;
44569 + struct file * file;
44570 int result;
44571 };
44572
44573 @@ -849,6 +850,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44574 buf->result = -EOVERFLOW;
44575 return -EOVERFLOW;
44576 }
44577 +
44578 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44579 + return 0;
44580 +
44581 buf->result++;
44582 dirent = buf->dirent;
44583 if (!access_ok(VERIFY_WRITE, dirent,
44584 @@ -881,6 +886,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44585
44586 buf.result = 0;
44587 buf.dirent = dirent;
44588 + buf.file = file;
44589
44590 error = vfs_readdir(file, compat_fillonedir, &buf);
44591 if (buf.result)
44592 @@ -901,6 +907,7 @@ struct compat_linux_dirent {
44593 struct compat_getdents_callback {
44594 struct compat_linux_dirent __user *current_dir;
44595 struct compat_linux_dirent __user *previous;
44596 + struct file * file;
44597 int count;
44598 int error;
44599 };
44600 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44601 buf->error = -EOVERFLOW;
44602 return -EOVERFLOW;
44603 }
44604 +
44605 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44606 + return 0;
44607 +
44608 dirent = buf->previous;
44609 if (dirent) {
44610 if (__put_user(offset, &dirent->d_off))
44611 @@ -969,6 +980,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44612 buf.previous = NULL;
44613 buf.count = count;
44614 buf.error = 0;
44615 + buf.file = file;
44616
44617 error = vfs_readdir(file, compat_filldir, &buf);
44618 if (error >= 0)
44619 @@ -990,6 +1002,7 @@ out:
44620 struct compat_getdents_callback64 {
44621 struct linux_dirent64 __user *current_dir;
44622 struct linux_dirent64 __user *previous;
44623 + struct file * file;
44624 int count;
44625 int error;
44626 };
44627 @@ -1006,6 +1019,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44628 buf->error = -EINVAL; /* only used if we fail.. */
44629 if (reclen > buf->count)
44630 return -EINVAL;
44631 +
44632 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44633 + return 0;
44634 +
44635 dirent = buf->previous;
44636
44637 if (dirent) {
44638 @@ -1057,13 +1074,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44639 buf.previous = NULL;
44640 buf.count = count;
44641 buf.error = 0;
44642 + buf.file = file;
44643
44644 error = vfs_readdir(file, compat_filldir64, &buf);
44645 if (error >= 0)
44646 error = buf.error;
44647 lastdirent = buf.previous;
44648 if (lastdirent) {
44649 - typeof(lastdirent->d_off) d_off = file->f_pos;
44650 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44651 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44652 error = -EFAULT;
44653 else
44654 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44655 index 112e45a..b59845b 100644
44656 --- a/fs/compat_binfmt_elf.c
44657 +++ b/fs/compat_binfmt_elf.c
44658 @@ -30,11 +30,13 @@
44659 #undef elf_phdr
44660 #undef elf_shdr
44661 #undef elf_note
44662 +#undef elf_dyn
44663 #undef elf_addr_t
44664 #define elfhdr elf32_hdr
44665 #define elf_phdr elf32_phdr
44666 #define elf_shdr elf32_shdr
44667 #define elf_note elf32_note
44668 +#define elf_dyn Elf32_Dyn
44669 #define elf_addr_t Elf32_Addr
44670
44671 /*
44672 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44673 index a26bea1..ae23e72 100644
44674 --- a/fs/compat_ioctl.c
44675 +++ b/fs/compat_ioctl.c
44676 @@ -211,6 +211,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44677
44678 err = get_user(palp, &up->palette);
44679 err |= get_user(length, &up->length);
44680 + if (err)
44681 + return -EFAULT;
44682
44683 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44684 err = put_user(compat_ptr(palp), &up_native->palette);
44685 @@ -622,7 +624,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44686 return -EFAULT;
44687 if (__get_user(udata, &ss32->iomem_base))
44688 return -EFAULT;
44689 - ss.iomem_base = compat_ptr(udata);
44690 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44691 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44692 __get_user(ss.port_high, &ss32->port_high))
44693 return -EFAULT;
44694 @@ -797,7 +799,7 @@ static int compat_ioctl_preallocate(struct file *file,
44695 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44696 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44697 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44698 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44699 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44700 return -EFAULT;
44701
44702 return ioctl_preallocate(file, p);
44703 @@ -1611,8 +1613,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44704 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44705 {
44706 unsigned int a, b;
44707 - a = *(unsigned int *)p;
44708 - b = *(unsigned int *)q;
44709 + a = *(const unsigned int *)p;
44710 + b = *(const unsigned int *)q;
44711 if (a > b)
44712 return 1;
44713 if (a < b)
44714 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44715 index 5ddd7eb..c18bf04 100644
44716 --- a/fs/configfs/dir.c
44717 +++ b/fs/configfs/dir.c
44718 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44719 }
44720 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44721 struct configfs_dirent *next;
44722 - const char * name;
44723 + const unsigned char * name;
44724 + char d_name[sizeof(next->s_dentry->d_iname)];
44725 int len;
44726 struct inode *inode = NULL;
44727
44728 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44729 continue;
44730
44731 name = configfs_get_name(next);
44732 - len = strlen(name);
44733 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44734 + len = next->s_dentry->d_name.len;
44735 + memcpy(d_name, name, len);
44736 + name = d_name;
44737 + } else
44738 + len = strlen(name);
44739
44740 /*
44741 * We'll have a dentry and an inode for
44742 diff --git a/fs/configfs/file.c b/fs/configfs/file.c
44743 index 2b6cb23..d76e879 100644
44744 --- a/fs/configfs/file.c
44745 +++ b/fs/configfs/file.c
44746 @@ -135,6 +135,8 @@ out:
44747 */
44748
44749 static int
44750 +fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count) __size_overflow(3);
44751 +static int
44752 fill_write_buffer(struct configfs_buffer * buffer, const char __user * buf, size_t count)
44753 {
44754 int error;
44755 diff --git a/fs/dcache.c b/fs/dcache.c
44756 index 2576d14..0cec38d 100644
44757 --- a/fs/dcache.c
44758 +++ b/fs/dcache.c
44759 @@ -105,10 +105,10 @@ static unsigned int d_hash_shift __read_mostly;
44760 static struct hlist_bl_head *dentry_hashtable __read_mostly;
44761
44762 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
44763 - unsigned long hash)
44764 + unsigned int hash)
44765 {
44766 - hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
44767 - hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS);
44768 + hash += (unsigned long) parent / L1_CACHE_BYTES;
44769 + hash = hash + (hash >> D_HASHBITS);
44770 return dentry_hashtable + (hash & D_HASHMASK);
44771 }
44772
44773 @@ -3067,7 +3067,7 @@ void __init vfs_caches_init(unsigned long mempages)
44774 mempages -= reserve;
44775
44776 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44777 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44778 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44779
44780 dcache_init();
44781 inode_init();
44782 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44783 index 956d5dd..e755e04 100644
44784 --- a/fs/debugfs/inode.c
44785 +++ b/fs/debugfs/inode.c
44786 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44787 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44788 {
44789 return debugfs_create_file(name,
44790 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44791 + S_IFDIR | S_IRWXU,
44792 +#else
44793 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44794 +#endif
44795 parent, NULL, NULL);
44796 }
44797 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44798 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44799 index ab35b11..b30af66 100644
44800 --- a/fs/ecryptfs/inode.c
44801 +++ b/fs/ecryptfs/inode.c
44802 @@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44803 old_fs = get_fs();
44804 set_fs(get_ds());
44805 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44806 - (char __user *)lower_buf,
44807 + (char __force_user *)lower_buf,
44808 lower_bufsiz);
44809 set_fs(old_fs);
44810 if (rc < 0)
44811 @@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44812 }
44813 old_fs = get_fs();
44814 set_fs(get_ds());
44815 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
44816 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
44817 set_fs(old_fs);
44818 if (rc < 0) {
44819 kfree(buf);
44820 @@ -733,7 +733,7 @@ out:
44821 static void
44822 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44823 {
44824 - char *buf = nd_get_link(nd);
44825 + const char *buf = nd_get_link(nd);
44826 if (!IS_ERR(buf)) {
44827 /* Free the char* */
44828 kfree(buf);
44829 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44830 index 3a06f40..f7af544 100644
44831 --- a/fs/ecryptfs/miscdev.c
44832 +++ b/fs/ecryptfs/miscdev.c
44833 @@ -345,7 +345,7 @@ check_list:
44834 goto out_unlock_msg_ctx;
44835 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44836 if (msg_ctx->msg) {
44837 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44838 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44839 goto out_unlock_msg_ctx;
44840 i += packet_length_size;
44841 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44842 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44843 index b2a34a1..162fa69 100644
44844 --- a/fs/ecryptfs/read_write.c
44845 +++ b/fs/ecryptfs/read_write.c
44846 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44847 return -EIO;
44848 fs_save = get_fs();
44849 set_fs(get_ds());
44850 - rc = vfs_write(lower_file, data, size, &offset);
44851 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44852 set_fs(fs_save);
44853 mark_inode_dirty_sync(ecryptfs_inode);
44854 return rc;
44855 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44856 return -EIO;
44857 fs_save = get_fs();
44858 set_fs(get_ds());
44859 - rc = vfs_read(lower_file, data, size, &offset);
44860 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44861 set_fs(fs_save);
44862 return rc;
44863 }
44864 diff --git a/fs/exec.c b/fs/exec.c
44865 index ae42277..32c9035 100644
44866 --- a/fs/exec.c
44867 +++ b/fs/exec.c
44868 @@ -55,6 +55,13 @@
44869 #include <linux/pipe_fs_i.h>
44870 #include <linux/oom.h>
44871 #include <linux/compat.h>
44872 +#include <linux/random.h>
44873 +#include <linux/seq_file.h>
44874 +
44875 +#ifdef CONFIG_PAX_REFCOUNT
44876 +#include <linux/kallsyms.h>
44877 +#include <linux/kdebug.h>
44878 +#endif
44879
44880 #include <asm/uaccess.h>
44881 #include <asm/mmu_context.h>
44882 @@ -63,6 +70,15 @@
44883 #include <trace/events/task.h>
44884 #include "internal.h"
44885
44886 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
44887 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
44888 +#endif
44889 +
44890 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44891 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44892 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44893 +#endif
44894 +
44895 int core_uses_pid;
44896 char core_pattern[CORENAME_MAX_SIZE] = "core";
44897 unsigned int core_pipe_limit;
44898 @@ -72,7 +88,7 @@ struct core_name {
44899 char *corename;
44900 int used, size;
44901 };
44902 -static atomic_t call_count = ATOMIC_INIT(1);
44903 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44904
44905 /* The maximal length of core_pattern is also specified in sysctl.c */
44906
44907 @@ -190,18 +206,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44908 int write)
44909 {
44910 struct page *page;
44911 - int ret;
44912
44913 -#ifdef CONFIG_STACK_GROWSUP
44914 - if (write) {
44915 - ret = expand_downwards(bprm->vma, pos);
44916 - if (ret < 0)
44917 - return NULL;
44918 - }
44919 -#endif
44920 - ret = get_user_pages(current, bprm->mm, pos,
44921 - 1, write, 1, &page, NULL);
44922 - if (ret <= 0)
44923 + if (0 > expand_downwards(bprm->vma, pos))
44924 + return NULL;
44925 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44926 return NULL;
44927
44928 if (write) {
44929 @@ -217,6 +225,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44930 if (size <= ARG_MAX)
44931 return page;
44932
44933 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44934 + // only allow 512KB for argv+env on suid/sgid binaries
44935 + // to prevent easy ASLR exhaustion
44936 + if (((bprm->cred->euid != current_euid()) ||
44937 + (bprm->cred->egid != current_egid())) &&
44938 + (size > (512 * 1024))) {
44939 + put_page(page);
44940 + return NULL;
44941 + }
44942 +#endif
44943 +
44944 /*
44945 * Limit to 1/4-th the stack size for the argv+env strings.
44946 * This ensures that:
44947 @@ -276,6 +295,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44948 vma->vm_end = STACK_TOP_MAX;
44949 vma->vm_start = vma->vm_end - PAGE_SIZE;
44950 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44951 +
44952 +#ifdef CONFIG_PAX_SEGMEXEC
44953 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44954 +#endif
44955 +
44956 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44957 INIT_LIST_HEAD(&vma->anon_vma_chain);
44958
44959 @@ -290,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44960 mm->stack_vm = mm->total_vm = 1;
44961 up_write(&mm->mmap_sem);
44962 bprm->p = vma->vm_end - sizeof(void *);
44963 +
44964 +#ifdef CONFIG_PAX_RANDUSTACK
44965 + if (randomize_va_space)
44966 + bprm->p ^= random32() & ~PAGE_MASK;
44967 +#endif
44968 +
44969 return 0;
44970 err:
44971 up_write(&mm->mmap_sem);
44972 @@ -398,19 +428,7 @@ err:
44973 return err;
44974 }
44975
44976 -struct user_arg_ptr {
44977 -#ifdef CONFIG_COMPAT
44978 - bool is_compat;
44979 -#endif
44980 - union {
44981 - const char __user *const __user *native;
44982 -#ifdef CONFIG_COMPAT
44983 - compat_uptr_t __user *compat;
44984 -#endif
44985 - } ptr;
44986 -};
44987 -
44988 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44989 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44990 {
44991 const char __user *native;
44992
44993 @@ -419,14 +437,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44994 compat_uptr_t compat;
44995
44996 if (get_user(compat, argv.ptr.compat + nr))
44997 - return ERR_PTR(-EFAULT);
44998 + return (const char __force_user *)ERR_PTR(-EFAULT);
44999
45000 return compat_ptr(compat);
45001 }
45002 #endif
45003
45004 if (get_user(native, argv.ptr.native + nr))
45005 - return ERR_PTR(-EFAULT);
45006 + return (const char __force_user *)ERR_PTR(-EFAULT);
45007
45008 return native;
45009 }
45010 @@ -445,7 +463,7 @@ static int count(struct user_arg_ptr argv, int max)
45011 if (!p)
45012 break;
45013
45014 - if (IS_ERR(p))
45015 + if (IS_ERR((const char __force_kernel *)p))
45016 return -EFAULT;
45017
45018 if (i++ >= max)
45019 @@ -479,7 +497,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45020
45021 ret = -EFAULT;
45022 str = get_user_arg_ptr(argv, argc);
45023 - if (IS_ERR(str))
45024 + if (IS_ERR((const char __force_kernel *)str))
45025 goto out;
45026
45027 len = strnlen_user(str, MAX_ARG_STRLEN);
45028 @@ -561,7 +579,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45029 int r;
45030 mm_segment_t oldfs = get_fs();
45031 struct user_arg_ptr argv = {
45032 - .ptr.native = (const char __user *const __user *)__argv,
45033 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45034 };
45035
45036 set_fs(KERNEL_DS);
45037 @@ -596,7 +614,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45038 unsigned long new_end = old_end - shift;
45039 struct mmu_gather tlb;
45040
45041 - BUG_ON(new_start > new_end);
45042 + if (new_start >= new_end || new_start < mmap_min_addr)
45043 + return -ENOMEM;
45044
45045 /*
45046 * ensure there are no vmas between where we want to go
45047 @@ -605,6 +624,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45048 if (vma != find_vma(mm, new_start))
45049 return -EFAULT;
45050
45051 +#ifdef CONFIG_PAX_SEGMEXEC
45052 + BUG_ON(pax_find_mirror_vma(vma));
45053 +#endif
45054 +
45055 /*
45056 * cover the whole range: [new_start, old_end)
45057 */
45058 @@ -685,10 +708,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45059 stack_top = arch_align_stack(stack_top);
45060 stack_top = PAGE_ALIGN(stack_top);
45061
45062 - if (unlikely(stack_top < mmap_min_addr) ||
45063 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45064 - return -ENOMEM;
45065 -
45066 stack_shift = vma->vm_end - stack_top;
45067
45068 bprm->p -= stack_shift;
45069 @@ -700,8 +719,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45070 bprm->exec -= stack_shift;
45071
45072 down_write(&mm->mmap_sem);
45073 +
45074 + /* Move stack pages down in memory. */
45075 + if (stack_shift) {
45076 + ret = shift_arg_pages(vma, stack_shift);
45077 + if (ret)
45078 + goto out_unlock;
45079 + }
45080 +
45081 vm_flags = VM_STACK_FLAGS;
45082
45083 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45084 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45085 + vm_flags &= ~VM_EXEC;
45086 +
45087 +#ifdef CONFIG_PAX_MPROTECT
45088 + if (mm->pax_flags & MF_PAX_MPROTECT)
45089 + vm_flags &= ~VM_MAYEXEC;
45090 +#endif
45091 +
45092 + }
45093 +#endif
45094 +
45095 /*
45096 * Adjust stack execute permissions; explicitly enable for
45097 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45098 @@ -720,13 +759,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45099 goto out_unlock;
45100 BUG_ON(prev != vma);
45101
45102 - /* Move stack pages down in memory. */
45103 - if (stack_shift) {
45104 - ret = shift_arg_pages(vma, stack_shift);
45105 - if (ret)
45106 - goto out_unlock;
45107 - }
45108 -
45109 /* mprotect_fixup is overkill to remove the temporary stack flags */
45110 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45111
45112 @@ -807,7 +839,7 @@ int kernel_read(struct file *file, loff_t offset,
45113 old_fs = get_fs();
45114 set_fs(get_ds());
45115 /* The cast to a user pointer is valid due to the set_fs() */
45116 - result = vfs_read(file, (void __user *)addr, count, &pos);
45117 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45118 set_fs(old_fs);
45119 return result;
45120 }
45121 @@ -1255,7 +1287,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45122 }
45123 rcu_read_unlock();
45124
45125 - if (p->fs->users > n_fs) {
45126 + if (atomic_read(&p->fs->users) > n_fs) {
45127 bprm->unsafe |= LSM_UNSAFE_SHARE;
45128 } else {
45129 res = -EAGAIN;
45130 @@ -1450,6 +1482,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45131
45132 EXPORT_SYMBOL(search_binary_handler);
45133
45134 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45135 +static DEFINE_PER_CPU(u64, exec_counter);
45136 +static int __init init_exec_counters(void)
45137 +{
45138 + unsigned int cpu;
45139 +
45140 + for_each_possible_cpu(cpu) {
45141 + per_cpu(exec_counter, cpu) = (u64)cpu;
45142 + }
45143 +
45144 + return 0;
45145 +}
45146 +early_initcall(init_exec_counters);
45147 +static inline void increment_exec_counter(void)
45148 +{
45149 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45150 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45151 +}
45152 +#else
45153 +static inline void increment_exec_counter(void) {}
45154 +#endif
45155 +
45156 /*
45157 * sys_execve() executes a new program.
45158 */
45159 @@ -1458,6 +1512,11 @@ static int do_execve_common(const char *filename,
45160 struct user_arg_ptr envp,
45161 struct pt_regs *regs)
45162 {
45163 +#ifdef CONFIG_GRKERNSEC
45164 + struct file *old_exec_file;
45165 + struct acl_subject_label *old_acl;
45166 + struct rlimit old_rlim[RLIM_NLIMITS];
45167 +#endif
45168 struct linux_binprm *bprm;
45169 struct file *file;
45170 struct files_struct *displaced;
45171 @@ -1465,6 +1524,8 @@ static int do_execve_common(const char *filename,
45172 int retval;
45173 const struct cred *cred = current_cred();
45174
45175 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45176 +
45177 /*
45178 * We move the actual failure in case of RLIMIT_NPROC excess from
45179 * set*uid() to execve() because too many poorly written programs
45180 @@ -1505,12 +1566,27 @@ static int do_execve_common(const char *filename,
45181 if (IS_ERR(file))
45182 goto out_unmark;
45183
45184 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45185 + retval = -EPERM;
45186 + goto out_file;
45187 + }
45188 +
45189 sched_exec();
45190
45191 bprm->file = file;
45192 bprm->filename = filename;
45193 bprm->interp = filename;
45194
45195 + if (gr_process_user_ban()) {
45196 + retval = -EPERM;
45197 + goto out_file;
45198 + }
45199 +
45200 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45201 + retval = -EACCES;
45202 + goto out_file;
45203 + }
45204 +
45205 retval = bprm_mm_init(bprm);
45206 if (retval)
45207 goto out_file;
45208 @@ -1527,24 +1603,65 @@ static int do_execve_common(const char *filename,
45209 if (retval < 0)
45210 goto out;
45211
45212 +#ifdef CONFIG_GRKERNSEC
45213 + old_acl = current->acl;
45214 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45215 + old_exec_file = current->exec_file;
45216 + get_file(file);
45217 + current->exec_file = file;
45218 +#endif
45219 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45220 + /* limit suid stack to 8MB
45221 + we saved the old limits above and will restore them if this exec fails
45222 + */
45223 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45224 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45225 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45226 +#endif
45227 +
45228 + if (!gr_tpe_allow(file)) {
45229 + retval = -EACCES;
45230 + goto out_fail;
45231 + }
45232 +
45233 + if (gr_check_crash_exec(file)) {
45234 + retval = -EACCES;
45235 + goto out_fail;
45236 + }
45237 +
45238 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45239 + bprm->unsafe);
45240 + if (retval < 0)
45241 + goto out_fail;
45242 +
45243 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45244 if (retval < 0)
45245 - goto out;
45246 + goto out_fail;
45247
45248 bprm->exec = bprm->p;
45249 retval = copy_strings(bprm->envc, envp, bprm);
45250 if (retval < 0)
45251 - goto out;
45252 + goto out_fail;
45253
45254 retval = copy_strings(bprm->argc, argv, bprm);
45255 if (retval < 0)
45256 - goto out;
45257 + goto out_fail;
45258 +
45259 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45260 +
45261 + gr_handle_exec_args(bprm, argv);
45262
45263 retval = search_binary_handler(bprm,regs);
45264 if (retval < 0)
45265 - goto out;
45266 + goto out_fail;
45267 +#ifdef CONFIG_GRKERNSEC
45268 + if (old_exec_file)
45269 + fput(old_exec_file);
45270 +#endif
45271
45272 /* execve succeeded */
45273 +
45274 + increment_exec_counter();
45275 current->fs->in_exec = 0;
45276 current->in_execve = 0;
45277 acct_update_integrals(current);
45278 @@ -1553,6 +1670,14 @@ static int do_execve_common(const char *filename,
45279 put_files_struct(displaced);
45280 return retval;
45281
45282 +out_fail:
45283 +#ifdef CONFIG_GRKERNSEC
45284 + current->acl = old_acl;
45285 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45286 + fput(current->exec_file);
45287 + current->exec_file = old_exec_file;
45288 +#endif
45289 +
45290 out:
45291 if (bprm->mm) {
45292 acct_arg_size(bprm, 0);
45293 @@ -1626,7 +1751,7 @@ static int expand_corename(struct core_name *cn)
45294 {
45295 char *old_corename = cn->corename;
45296
45297 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45298 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45299 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45300
45301 if (!cn->corename) {
45302 @@ -1723,7 +1848,7 @@ static int format_corename(struct core_name *cn, long signr)
45303 int pid_in_pattern = 0;
45304 int err = 0;
45305
45306 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45307 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45308 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45309 cn->used = 0;
45310
45311 @@ -1820,6 +1945,228 @@ out:
45312 return ispipe;
45313 }
45314
45315 +int pax_check_flags(unsigned long *flags)
45316 +{
45317 + int retval = 0;
45318 +
45319 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45320 + if (*flags & MF_PAX_SEGMEXEC)
45321 + {
45322 + *flags &= ~MF_PAX_SEGMEXEC;
45323 + retval = -EINVAL;
45324 + }
45325 +#endif
45326 +
45327 + if ((*flags & MF_PAX_PAGEEXEC)
45328 +
45329 +#ifdef CONFIG_PAX_PAGEEXEC
45330 + && (*flags & MF_PAX_SEGMEXEC)
45331 +#endif
45332 +
45333 + )
45334 + {
45335 + *flags &= ~MF_PAX_PAGEEXEC;
45336 + retval = -EINVAL;
45337 + }
45338 +
45339 + if ((*flags & MF_PAX_MPROTECT)
45340 +
45341 +#ifdef CONFIG_PAX_MPROTECT
45342 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45343 +#endif
45344 +
45345 + )
45346 + {
45347 + *flags &= ~MF_PAX_MPROTECT;
45348 + retval = -EINVAL;
45349 + }
45350 +
45351 + if ((*flags & MF_PAX_EMUTRAMP)
45352 +
45353 +#ifdef CONFIG_PAX_EMUTRAMP
45354 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45355 +#endif
45356 +
45357 + )
45358 + {
45359 + *flags &= ~MF_PAX_EMUTRAMP;
45360 + retval = -EINVAL;
45361 + }
45362 +
45363 + return retval;
45364 +}
45365 +
45366 +EXPORT_SYMBOL(pax_check_flags);
45367 +
45368 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45369 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45370 +{
45371 + struct task_struct *tsk = current;
45372 + struct mm_struct *mm = current->mm;
45373 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45374 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45375 + char *path_exec = NULL;
45376 + char *path_fault = NULL;
45377 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45378 +
45379 + if (buffer_exec && buffer_fault) {
45380 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45381 +
45382 + down_read(&mm->mmap_sem);
45383 + vma = mm->mmap;
45384 + while (vma && (!vma_exec || !vma_fault)) {
45385 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45386 + vma_exec = vma;
45387 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45388 + vma_fault = vma;
45389 + vma = vma->vm_next;
45390 + }
45391 + if (vma_exec) {
45392 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45393 + if (IS_ERR(path_exec))
45394 + path_exec = "<path too long>";
45395 + else {
45396 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45397 + if (path_exec) {
45398 + *path_exec = 0;
45399 + path_exec = buffer_exec;
45400 + } else
45401 + path_exec = "<path too long>";
45402 + }
45403 + }
45404 + if (vma_fault) {
45405 + start = vma_fault->vm_start;
45406 + end = vma_fault->vm_end;
45407 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45408 + if (vma_fault->vm_file) {
45409 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45410 + if (IS_ERR(path_fault))
45411 + path_fault = "<path too long>";
45412 + else {
45413 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45414 + if (path_fault) {
45415 + *path_fault = 0;
45416 + path_fault = buffer_fault;
45417 + } else
45418 + path_fault = "<path too long>";
45419 + }
45420 + } else
45421 + path_fault = "<anonymous mapping>";
45422 + }
45423 + up_read(&mm->mmap_sem);
45424 + }
45425 + if (tsk->signal->curr_ip)
45426 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45427 + else
45428 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45429 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45430 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45431 + task_uid(tsk), task_euid(tsk), pc, sp);
45432 + free_page((unsigned long)buffer_exec);
45433 + free_page((unsigned long)buffer_fault);
45434 + pax_report_insns(regs, pc, sp);
45435 + do_coredump(SIGKILL, SIGKILL, regs);
45436 +}
45437 +#endif
45438 +
45439 +#ifdef CONFIG_PAX_REFCOUNT
45440 +void pax_report_refcount_overflow(struct pt_regs *regs)
45441 +{
45442 + if (current->signal->curr_ip)
45443 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45444 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45445 + else
45446 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45447 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45448 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45449 + show_regs(regs);
45450 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45451 +}
45452 +#endif
45453 +
45454 +#ifdef CONFIG_PAX_USERCOPY
45455 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45456 +int object_is_on_stack(const void *obj, unsigned long len)
45457 +{
45458 + const void * const stack = task_stack_page(current);
45459 + const void * const stackend = stack + THREAD_SIZE;
45460 +
45461 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45462 + const void *frame = NULL;
45463 + const void *oldframe;
45464 +#endif
45465 +
45466 + if (obj + len < obj)
45467 + return -1;
45468 +
45469 + if (obj + len <= stack || stackend <= obj)
45470 + return 0;
45471 +
45472 + if (obj < stack || stackend < obj + len)
45473 + return -1;
45474 +
45475 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45476 + oldframe = __builtin_frame_address(1);
45477 + if (oldframe)
45478 + frame = __builtin_frame_address(2);
45479 + /*
45480 + low ----------------------------------------------> high
45481 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45482 + ^----------------^
45483 + allow copies only within here
45484 + */
45485 + while (stack <= frame && frame < stackend) {
45486 + /* if obj + len extends past the last frame, this
45487 + check won't pass and the next frame will be 0,
45488 + causing us to bail out and correctly report
45489 + the copy as invalid
45490 + */
45491 + if (obj + len <= frame)
45492 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45493 + oldframe = frame;
45494 + frame = *(const void * const *)frame;
45495 + }
45496 + return -1;
45497 +#else
45498 + return 1;
45499 +#endif
45500 +}
45501 +
45502 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45503 +{
45504 + if (current->signal->curr_ip)
45505 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45506 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45507 + else
45508 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45509 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45510 + dump_stack();
45511 + gr_handle_kernel_exploit();
45512 + do_group_exit(SIGKILL);
45513 +}
45514 +#endif
45515 +
45516 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45517 +void pax_track_stack(void)
45518 +{
45519 + unsigned long sp = (unsigned long)&sp;
45520 + if (sp < current_thread_info()->lowest_stack &&
45521 + sp > (unsigned long)task_stack_page(current))
45522 + current_thread_info()->lowest_stack = sp;
45523 +}
45524 +EXPORT_SYMBOL(pax_track_stack);
45525 +#endif
45526 +
45527 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45528 +void report_size_overflow(const char *file, unsigned int line, const char *func)
45529 +{
45530 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
45531 + dump_stack();
45532 + do_group_exit(SIGKILL);
45533 +}
45534 +EXPORT_SYMBOL(report_size_overflow);
45535 +#endif
45536 +
45537 static int zap_process(struct task_struct *start, int exit_code)
45538 {
45539 struct task_struct *t;
45540 @@ -2017,17 +2364,17 @@ static void wait_for_dump_helpers(struct file *file)
45541 pipe = file->f_path.dentry->d_inode->i_pipe;
45542
45543 pipe_lock(pipe);
45544 - pipe->readers++;
45545 - pipe->writers--;
45546 + atomic_inc(&pipe->readers);
45547 + atomic_dec(&pipe->writers);
45548
45549 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45550 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45551 wake_up_interruptible_sync(&pipe->wait);
45552 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45553 pipe_wait(pipe);
45554 }
45555
45556 - pipe->readers--;
45557 - pipe->writers++;
45558 + atomic_dec(&pipe->readers);
45559 + atomic_inc(&pipe->writers);
45560 pipe_unlock(pipe);
45561
45562 }
45563 @@ -2088,7 +2435,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45564 int retval = 0;
45565 int flag = 0;
45566 int ispipe;
45567 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45568 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45569 struct coredump_params cprm = {
45570 .signr = signr,
45571 .regs = regs,
45572 @@ -2103,6 +2450,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45573
45574 audit_core_dumps(signr);
45575
45576 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45577 + gr_handle_brute_attach(current, cprm.mm_flags);
45578 +
45579 binfmt = mm->binfmt;
45580 if (!binfmt || !binfmt->core_dump)
45581 goto fail;
45582 @@ -2170,7 +2520,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45583 }
45584 cprm.limit = RLIM_INFINITY;
45585
45586 - dump_count = atomic_inc_return(&core_dump_count);
45587 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45588 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45589 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45590 task_tgid_vnr(current), current->comm);
45591 @@ -2197,6 +2547,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45592 } else {
45593 struct inode *inode;
45594
45595 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45596 +
45597 if (cprm.limit < binfmt->min_coredump)
45598 goto fail_unlock;
45599
45600 @@ -2240,7 +2592,7 @@ close_fail:
45601 filp_close(cprm.file, NULL);
45602 fail_dropcount:
45603 if (ispipe)
45604 - atomic_dec(&core_dump_count);
45605 + atomic_dec_unchecked(&core_dump_count);
45606 fail_unlock:
45607 kfree(cn.corename);
45608 fail_corename:
45609 @@ -2259,7 +2611,7 @@ fail:
45610 */
45611 int dump_write(struct file *file, const void *addr, int nr)
45612 {
45613 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45614 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45615 }
45616 EXPORT_SYMBOL(dump_write);
45617
45618 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45619 index a8cbe1b..fed04cb 100644
45620 --- a/fs/ext2/balloc.c
45621 +++ b/fs/ext2/balloc.c
45622 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45623
45624 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45625 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45626 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45627 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
45628 sbi->s_resuid != current_fsuid() &&
45629 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45630 return 0;
45631 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45632 index a203892..4e64db5 100644
45633 --- a/fs/ext3/balloc.c
45634 +++ b/fs/ext3/balloc.c
45635 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45636
45637 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45638 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45639 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45640 + if (free_blocks < root_blocks + 1 &&
45641 !use_reservation && sbi->s_resuid != current_fsuid() &&
45642 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
45643 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
45644 + !capable_nolog(CAP_SYS_RESOURCE)) {
45645 return 0;
45646 }
45647 return 1;
45648 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45649 index f9e2cd8..bfdc476 100644
45650 --- a/fs/ext4/balloc.c
45651 +++ b/fs/ext4/balloc.c
45652 @@ -438,8 +438,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45653 /* Hm, nope. Are (enough) root reserved clusters available? */
45654 if (sbi->s_resuid == current_fsuid() ||
45655 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
45656 - capable(CAP_SYS_RESOURCE) ||
45657 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45658 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45659 + capable_nolog(CAP_SYS_RESOURCE)) {
45660
45661 if (free_clusters >= (nclusters + dirty_clusters))
45662 return 1;
45663 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45664 index 9983ba8..2a5272c 100644
45665 --- a/fs/ext4/ext4.h
45666 +++ b/fs/ext4/ext4.h
45667 @@ -1217,19 +1217,19 @@ struct ext4_sb_info {
45668 unsigned long s_mb_last_start;
45669
45670 /* stats for buddy allocator */
45671 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45672 - atomic_t s_bal_success; /* we found long enough chunks */
45673 - atomic_t s_bal_allocated; /* in blocks */
45674 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45675 - atomic_t s_bal_goals; /* goal hits */
45676 - atomic_t s_bal_breaks; /* too long searches */
45677 - atomic_t s_bal_2orders; /* 2^order hits */
45678 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45679 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45680 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45681 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45682 + atomic_unchecked_t s_bal_goals; /* goal hits */
45683 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45684 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45685 spinlock_t s_bal_lock;
45686 unsigned long s_mb_buddies_generated;
45687 unsigned long long s_mb_generation_time;
45688 - atomic_t s_mb_lost_chunks;
45689 - atomic_t s_mb_preallocated;
45690 - atomic_t s_mb_discarded;
45691 + atomic_unchecked_t s_mb_lost_chunks;
45692 + atomic_unchecked_t s_mb_preallocated;
45693 + atomic_unchecked_t s_mb_discarded;
45694 atomic_t s_lock_busy;
45695
45696 /* locality groups */
45697 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45698 index cb990b2..4820141 100644
45699 --- a/fs/ext4/mballoc.c
45700 +++ b/fs/ext4/mballoc.c
45701 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45702 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45703
45704 if (EXT4_SB(sb)->s_mb_stats)
45705 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45706 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45707
45708 break;
45709 }
45710 @@ -2088,7 +2088,7 @@ repeat:
45711 ac->ac_status = AC_STATUS_CONTINUE;
45712 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45713 cr = 3;
45714 - atomic_inc(&sbi->s_mb_lost_chunks);
45715 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45716 goto repeat;
45717 }
45718 }
45719 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
45720 if (sbi->s_mb_stats) {
45721 ext4_msg(sb, KERN_INFO,
45722 "mballoc: %u blocks %u reqs (%u success)",
45723 - atomic_read(&sbi->s_bal_allocated),
45724 - atomic_read(&sbi->s_bal_reqs),
45725 - atomic_read(&sbi->s_bal_success));
45726 + atomic_read_unchecked(&sbi->s_bal_allocated),
45727 + atomic_read_unchecked(&sbi->s_bal_reqs),
45728 + atomic_read_unchecked(&sbi->s_bal_success));
45729 ext4_msg(sb, KERN_INFO,
45730 "mballoc: %u extents scanned, %u goal hits, "
45731 "%u 2^N hits, %u breaks, %u lost",
45732 - atomic_read(&sbi->s_bal_ex_scanned),
45733 - atomic_read(&sbi->s_bal_goals),
45734 - atomic_read(&sbi->s_bal_2orders),
45735 - atomic_read(&sbi->s_bal_breaks),
45736 - atomic_read(&sbi->s_mb_lost_chunks));
45737 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45738 + atomic_read_unchecked(&sbi->s_bal_goals),
45739 + atomic_read_unchecked(&sbi->s_bal_2orders),
45740 + atomic_read_unchecked(&sbi->s_bal_breaks),
45741 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45742 ext4_msg(sb, KERN_INFO,
45743 "mballoc: %lu generated and it took %Lu",
45744 sbi->s_mb_buddies_generated,
45745 sbi->s_mb_generation_time);
45746 ext4_msg(sb, KERN_INFO,
45747 "mballoc: %u preallocated, %u discarded",
45748 - atomic_read(&sbi->s_mb_preallocated),
45749 - atomic_read(&sbi->s_mb_discarded));
45750 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45751 + atomic_read_unchecked(&sbi->s_mb_discarded));
45752 }
45753
45754 free_percpu(sbi->s_locality_groups);
45755 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45756 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45757
45758 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45759 - atomic_inc(&sbi->s_bal_reqs);
45760 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45761 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45762 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45763 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45764 - atomic_inc(&sbi->s_bal_success);
45765 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45766 + atomic_inc_unchecked(&sbi->s_bal_success);
45767 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45768 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45769 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45770 - atomic_inc(&sbi->s_bal_goals);
45771 + atomic_inc_unchecked(&sbi->s_bal_goals);
45772 if (ac->ac_found > sbi->s_mb_max_to_scan)
45773 - atomic_inc(&sbi->s_bal_breaks);
45774 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45775 }
45776
45777 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45778 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45779 trace_ext4_mb_new_inode_pa(ac, pa);
45780
45781 ext4_mb_use_inode_pa(ac, pa);
45782 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45783 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45784
45785 ei = EXT4_I(ac->ac_inode);
45786 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45787 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45788 trace_ext4_mb_new_group_pa(ac, pa);
45789
45790 ext4_mb_use_group_pa(ac, pa);
45791 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45792 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45793
45794 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45795 lg = ac->ac_lg;
45796 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45797 * from the bitmap and continue.
45798 */
45799 }
45800 - atomic_add(free, &sbi->s_mb_discarded);
45801 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45802
45803 return err;
45804 }
45805 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45806 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45807 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45808 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45809 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45810 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45811 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45812
45813 return 0;
45814 diff --git a/fs/fcntl.c b/fs/fcntl.c
45815 index 22764c7..86372c9 100644
45816 --- a/fs/fcntl.c
45817 +++ b/fs/fcntl.c
45818 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45819 if (err)
45820 return err;
45821
45822 + if (gr_handle_chroot_fowner(pid, type))
45823 + return -ENOENT;
45824 + if (gr_check_protected_task_fowner(pid, type))
45825 + return -EACCES;
45826 +
45827 f_modown(filp, pid, type, force);
45828 return 0;
45829 }
45830 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45831
45832 static int f_setown_ex(struct file *filp, unsigned long arg)
45833 {
45834 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45835 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45836 struct f_owner_ex owner;
45837 struct pid *pid;
45838 int type;
45839 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45840
45841 static int f_getown_ex(struct file *filp, unsigned long arg)
45842 {
45843 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45844 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45845 struct f_owner_ex owner;
45846 int ret = 0;
45847
45848 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45849 switch (cmd) {
45850 case F_DUPFD:
45851 case F_DUPFD_CLOEXEC:
45852 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45853 if (arg >= rlimit(RLIMIT_NOFILE))
45854 break;
45855 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45856 diff --git a/fs/fifo.c b/fs/fifo.c
45857 index b1a524d..4ee270e 100644
45858 --- a/fs/fifo.c
45859 +++ b/fs/fifo.c
45860 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45861 */
45862 filp->f_op = &read_pipefifo_fops;
45863 pipe->r_counter++;
45864 - if (pipe->readers++ == 0)
45865 + if (atomic_inc_return(&pipe->readers) == 1)
45866 wake_up_partner(inode);
45867
45868 - if (!pipe->writers) {
45869 + if (!atomic_read(&pipe->writers)) {
45870 if ((filp->f_flags & O_NONBLOCK)) {
45871 /* suppress POLLHUP until we have
45872 * seen a writer */
45873 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45874 * errno=ENXIO when there is no process reading the FIFO.
45875 */
45876 ret = -ENXIO;
45877 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45878 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45879 goto err;
45880
45881 filp->f_op = &write_pipefifo_fops;
45882 pipe->w_counter++;
45883 - if (!pipe->writers++)
45884 + if (atomic_inc_return(&pipe->writers) == 1)
45885 wake_up_partner(inode);
45886
45887 - if (!pipe->readers) {
45888 + if (!atomic_read(&pipe->readers)) {
45889 wait_for_partner(inode, &pipe->r_counter);
45890 if (signal_pending(current))
45891 goto err_wr;
45892 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45893 */
45894 filp->f_op = &rdwr_pipefifo_fops;
45895
45896 - pipe->readers++;
45897 - pipe->writers++;
45898 + atomic_inc(&pipe->readers);
45899 + atomic_inc(&pipe->writers);
45900 pipe->r_counter++;
45901 pipe->w_counter++;
45902 - if (pipe->readers == 1 || pipe->writers == 1)
45903 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45904 wake_up_partner(inode);
45905 break;
45906
45907 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45908 return 0;
45909
45910 err_rd:
45911 - if (!--pipe->readers)
45912 + if (atomic_dec_and_test(&pipe->readers))
45913 wake_up_interruptible(&pipe->wait);
45914 ret = -ERESTARTSYS;
45915 goto err;
45916
45917 err_wr:
45918 - if (!--pipe->writers)
45919 + if (atomic_dec_and_test(&pipe->writers))
45920 wake_up_interruptible(&pipe->wait);
45921 ret = -ERESTARTSYS;
45922 goto err;
45923
45924 err:
45925 - if (!pipe->readers && !pipe->writers)
45926 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45927 free_pipe_info(inode);
45928
45929 err_nocleanup:
45930 diff --git a/fs/file.c b/fs/file.c
45931 index 4c6992d..104cdea 100644
45932 --- a/fs/file.c
45933 +++ b/fs/file.c
45934 @@ -15,6 +15,7 @@
45935 #include <linux/slab.h>
45936 #include <linux/vmalloc.h>
45937 #include <linux/file.h>
45938 +#include <linux/security.h>
45939 #include <linux/fdtable.h>
45940 #include <linux/bitops.h>
45941 #include <linux/interrupt.h>
45942 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
45943 * N.B. For clone tasks sharing a files structure, this test
45944 * will limit the total number of files that can be opened.
45945 */
45946 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45947 if (nr >= rlimit(RLIMIT_NOFILE))
45948 return -EMFILE;
45949
45950 diff --git a/fs/filesystems.c b/fs/filesystems.c
45951 index 96f2428..f5eeb8e 100644
45952 --- a/fs/filesystems.c
45953 +++ b/fs/filesystems.c
45954 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45955 int len = dot ? dot - name : strlen(name);
45956
45957 fs = __get_fs_type(name, len);
45958 +
45959 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45960 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45961 +#else
45962 if (!fs && (request_module("%.*s", len, name) == 0))
45963 +#endif
45964 fs = __get_fs_type(name, len);
45965
45966 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45967 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45968 index 78b519c..a8b4979 100644
45969 --- a/fs/fs_struct.c
45970 +++ b/fs/fs_struct.c
45971 @@ -4,6 +4,7 @@
45972 #include <linux/path.h>
45973 #include <linux/slab.h>
45974 #include <linux/fs_struct.h>
45975 +#include <linux/grsecurity.h>
45976 #include "internal.h"
45977
45978 static inline void path_get_longterm(struct path *path)
45979 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45980 old_root = fs->root;
45981 fs->root = *path;
45982 path_get_longterm(path);
45983 + gr_set_chroot_entries(current, path);
45984 write_seqcount_end(&fs->seq);
45985 spin_unlock(&fs->lock);
45986 if (old_root.dentry)
45987 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45988 && fs->root.mnt == old_root->mnt) {
45989 path_get_longterm(new_root);
45990 fs->root = *new_root;
45991 + gr_set_chroot_entries(p, new_root);
45992 count++;
45993 }
45994 if (fs->pwd.dentry == old_root->dentry
45995 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
45996 spin_lock(&fs->lock);
45997 write_seqcount_begin(&fs->seq);
45998 tsk->fs = NULL;
45999 - kill = !--fs->users;
46000 + gr_clear_chroot_entries(tsk);
46001 + kill = !atomic_dec_return(&fs->users);
46002 write_seqcount_end(&fs->seq);
46003 spin_unlock(&fs->lock);
46004 task_unlock(tsk);
46005 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46006 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46007 /* We don't need to lock fs - think why ;-) */
46008 if (fs) {
46009 - fs->users = 1;
46010 + atomic_set(&fs->users, 1);
46011 fs->in_exec = 0;
46012 spin_lock_init(&fs->lock);
46013 seqcount_init(&fs->seq);
46014 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46015 spin_lock(&old->lock);
46016 fs->root = old->root;
46017 path_get_longterm(&fs->root);
46018 + /* instead of calling gr_set_chroot_entries here,
46019 + we call it from every caller of this function
46020 + */
46021 fs->pwd = old->pwd;
46022 path_get_longterm(&fs->pwd);
46023 spin_unlock(&old->lock);
46024 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
46025
46026 task_lock(current);
46027 spin_lock(&fs->lock);
46028 - kill = !--fs->users;
46029 + kill = !atomic_dec_return(&fs->users);
46030 current->fs = new_fs;
46031 + gr_set_chroot_entries(current, &new_fs->root);
46032 spin_unlock(&fs->lock);
46033 task_unlock(current);
46034
46035 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46036
46037 int current_umask(void)
46038 {
46039 - return current->fs->umask;
46040 + return current->fs->umask | gr_acl_umask();
46041 }
46042 EXPORT_SYMBOL(current_umask);
46043
46044 /* to be mentioned only in INIT_TASK */
46045 struct fs_struct init_fs = {
46046 - .users = 1,
46047 + .users = ATOMIC_INIT(1),
46048 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46049 .seq = SEQCNT_ZERO,
46050 .umask = 0022,
46051 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
46052 task_lock(current);
46053
46054 spin_lock(&init_fs.lock);
46055 - init_fs.users++;
46056 + atomic_inc(&init_fs.users);
46057 spin_unlock(&init_fs.lock);
46058
46059 spin_lock(&fs->lock);
46060 current->fs = &init_fs;
46061 - kill = !--fs->users;
46062 + gr_set_chroot_entries(current, &current->fs->root);
46063 + kill = !atomic_dec_return(&fs->users);
46064 spin_unlock(&fs->lock);
46065
46066 task_unlock(current);
46067 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46068 index 9905350..02eaec4 100644
46069 --- a/fs/fscache/cookie.c
46070 +++ b/fs/fscache/cookie.c
46071 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46072 parent ? (char *) parent->def->name : "<no-parent>",
46073 def->name, netfs_data);
46074
46075 - fscache_stat(&fscache_n_acquires);
46076 + fscache_stat_unchecked(&fscache_n_acquires);
46077
46078 /* if there's no parent cookie, then we don't create one here either */
46079 if (!parent) {
46080 - fscache_stat(&fscache_n_acquires_null);
46081 + fscache_stat_unchecked(&fscache_n_acquires_null);
46082 _leave(" [no parent]");
46083 return NULL;
46084 }
46085 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46086 /* allocate and initialise a cookie */
46087 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46088 if (!cookie) {
46089 - fscache_stat(&fscache_n_acquires_oom);
46090 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46091 _leave(" [ENOMEM]");
46092 return NULL;
46093 }
46094 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46095
46096 switch (cookie->def->type) {
46097 case FSCACHE_COOKIE_TYPE_INDEX:
46098 - fscache_stat(&fscache_n_cookie_index);
46099 + fscache_stat_unchecked(&fscache_n_cookie_index);
46100 break;
46101 case FSCACHE_COOKIE_TYPE_DATAFILE:
46102 - fscache_stat(&fscache_n_cookie_data);
46103 + fscache_stat_unchecked(&fscache_n_cookie_data);
46104 break;
46105 default:
46106 - fscache_stat(&fscache_n_cookie_special);
46107 + fscache_stat_unchecked(&fscache_n_cookie_special);
46108 break;
46109 }
46110
46111 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46112 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46113 atomic_dec(&parent->n_children);
46114 __fscache_cookie_put(cookie);
46115 - fscache_stat(&fscache_n_acquires_nobufs);
46116 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46117 _leave(" = NULL");
46118 return NULL;
46119 }
46120 }
46121
46122 - fscache_stat(&fscache_n_acquires_ok);
46123 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46124 _leave(" = %p", cookie);
46125 return cookie;
46126 }
46127 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46128 cache = fscache_select_cache_for_object(cookie->parent);
46129 if (!cache) {
46130 up_read(&fscache_addremove_sem);
46131 - fscache_stat(&fscache_n_acquires_no_cache);
46132 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46133 _leave(" = -ENOMEDIUM [no cache]");
46134 return -ENOMEDIUM;
46135 }
46136 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46137 object = cache->ops->alloc_object(cache, cookie);
46138 fscache_stat_d(&fscache_n_cop_alloc_object);
46139 if (IS_ERR(object)) {
46140 - fscache_stat(&fscache_n_object_no_alloc);
46141 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46142 ret = PTR_ERR(object);
46143 goto error;
46144 }
46145
46146 - fscache_stat(&fscache_n_object_alloc);
46147 + fscache_stat_unchecked(&fscache_n_object_alloc);
46148
46149 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46150
46151 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46152 struct fscache_object *object;
46153 struct hlist_node *_p;
46154
46155 - fscache_stat(&fscache_n_updates);
46156 + fscache_stat_unchecked(&fscache_n_updates);
46157
46158 if (!cookie) {
46159 - fscache_stat(&fscache_n_updates_null);
46160 + fscache_stat_unchecked(&fscache_n_updates_null);
46161 _leave(" [no cookie]");
46162 return;
46163 }
46164 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46165 struct fscache_object *object;
46166 unsigned long event;
46167
46168 - fscache_stat(&fscache_n_relinquishes);
46169 + fscache_stat_unchecked(&fscache_n_relinquishes);
46170 if (retire)
46171 - fscache_stat(&fscache_n_relinquishes_retire);
46172 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46173
46174 if (!cookie) {
46175 - fscache_stat(&fscache_n_relinquishes_null);
46176 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46177 _leave(" [no cookie]");
46178 return;
46179 }
46180 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46181
46182 /* wait for the cookie to finish being instantiated (or to fail) */
46183 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46184 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46185 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46186 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46187 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46188 }
46189 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46190 index f6aad48..88dcf26 100644
46191 --- a/fs/fscache/internal.h
46192 +++ b/fs/fscache/internal.h
46193 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46194 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46195 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46196
46197 -extern atomic_t fscache_n_op_pend;
46198 -extern atomic_t fscache_n_op_run;
46199 -extern atomic_t fscache_n_op_enqueue;
46200 -extern atomic_t fscache_n_op_deferred_release;
46201 -extern atomic_t fscache_n_op_release;
46202 -extern atomic_t fscache_n_op_gc;
46203 -extern atomic_t fscache_n_op_cancelled;
46204 -extern atomic_t fscache_n_op_rejected;
46205 +extern atomic_unchecked_t fscache_n_op_pend;
46206 +extern atomic_unchecked_t fscache_n_op_run;
46207 +extern atomic_unchecked_t fscache_n_op_enqueue;
46208 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46209 +extern atomic_unchecked_t fscache_n_op_release;
46210 +extern atomic_unchecked_t fscache_n_op_gc;
46211 +extern atomic_unchecked_t fscache_n_op_cancelled;
46212 +extern atomic_unchecked_t fscache_n_op_rejected;
46213
46214 -extern atomic_t fscache_n_attr_changed;
46215 -extern atomic_t fscache_n_attr_changed_ok;
46216 -extern atomic_t fscache_n_attr_changed_nobufs;
46217 -extern atomic_t fscache_n_attr_changed_nomem;
46218 -extern atomic_t fscache_n_attr_changed_calls;
46219 +extern atomic_unchecked_t fscache_n_attr_changed;
46220 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46221 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46222 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46223 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46224
46225 -extern atomic_t fscache_n_allocs;
46226 -extern atomic_t fscache_n_allocs_ok;
46227 -extern atomic_t fscache_n_allocs_wait;
46228 -extern atomic_t fscache_n_allocs_nobufs;
46229 -extern atomic_t fscache_n_allocs_intr;
46230 -extern atomic_t fscache_n_allocs_object_dead;
46231 -extern atomic_t fscache_n_alloc_ops;
46232 -extern atomic_t fscache_n_alloc_op_waits;
46233 +extern atomic_unchecked_t fscache_n_allocs;
46234 +extern atomic_unchecked_t fscache_n_allocs_ok;
46235 +extern atomic_unchecked_t fscache_n_allocs_wait;
46236 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46237 +extern atomic_unchecked_t fscache_n_allocs_intr;
46238 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46239 +extern atomic_unchecked_t fscache_n_alloc_ops;
46240 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46241
46242 -extern atomic_t fscache_n_retrievals;
46243 -extern atomic_t fscache_n_retrievals_ok;
46244 -extern atomic_t fscache_n_retrievals_wait;
46245 -extern atomic_t fscache_n_retrievals_nodata;
46246 -extern atomic_t fscache_n_retrievals_nobufs;
46247 -extern atomic_t fscache_n_retrievals_intr;
46248 -extern atomic_t fscache_n_retrievals_nomem;
46249 -extern atomic_t fscache_n_retrievals_object_dead;
46250 -extern atomic_t fscache_n_retrieval_ops;
46251 -extern atomic_t fscache_n_retrieval_op_waits;
46252 +extern atomic_unchecked_t fscache_n_retrievals;
46253 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46254 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46255 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46256 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46257 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46258 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46259 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46260 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46261 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46262
46263 -extern atomic_t fscache_n_stores;
46264 -extern atomic_t fscache_n_stores_ok;
46265 -extern atomic_t fscache_n_stores_again;
46266 -extern atomic_t fscache_n_stores_nobufs;
46267 -extern atomic_t fscache_n_stores_oom;
46268 -extern atomic_t fscache_n_store_ops;
46269 -extern atomic_t fscache_n_store_calls;
46270 -extern atomic_t fscache_n_store_pages;
46271 -extern atomic_t fscache_n_store_radix_deletes;
46272 -extern atomic_t fscache_n_store_pages_over_limit;
46273 +extern atomic_unchecked_t fscache_n_stores;
46274 +extern atomic_unchecked_t fscache_n_stores_ok;
46275 +extern atomic_unchecked_t fscache_n_stores_again;
46276 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46277 +extern atomic_unchecked_t fscache_n_stores_oom;
46278 +extern atomic_unchecked_t fscache_n_store_ops;
46279 +extern atomic_unchecked_t fscache_n_store_calls;
46280 +extern atomic_unchecked_t fscache_n_store_pages;
46281 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46282 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46283
46284 -extern atomic_t fscache_n_store_vmscan_not_storing;
46285 -extern atomic_t fscache_n_store_vmscan_gone;
46286 -extern atomic_t fscache_n_store_vmscan_busy;
46287 -extern atomic_t fscache_n_store_vmscan_cancelled;
46288 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46289 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46290 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46291 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46292
46293 -extern atomic_t fscache_n_marks;
46294 -extern atomic_t fscache_n_uncaches;
46295 +extern atomic_unchecked_t fscache_n_marks;
46296 +extern atomic_unchecked_t fscache_n_uncaches;
46297
46298 -extern atomic_t fscache_n_acquires;
46299 -extern atomic_t fscache_n_acquires_null;
46300 -extern atomic_t fscache_n_acquires_no_cache;
46301 -extern atomic_t fscache_n_acquires_ok;
46302 -extern atomic_t fscache_n_acquires_nobufs;
46303 -extern atomic_t fscache_n_acquires_oom;
46304 +extern atomic_unchecked_t fscache_n_acquires;
46305 +extern atomic_unchecked_t fscache_n_acquires_null;
46306 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46307 +extern atomic_unchecked_t fscache_n_acquires_ok;
46308 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46309 +extern atomic_unchecked_t fscache_n_acquires_oom;
46310
46311 -extern atomic_t fscache_n_updates;
46312 -extern atomic_t fscache_n_updates_null;
46313 -extern atomic_t fscache_n_updates_run;
46314 +extern atomic_unchecked_t fscache_n_updates;
46315 +extern atomic_unchecked_t fscache_n_updates_null;
46316 +extern atomic_unchecked_t fscache_n_updates_run;
46317
46318 -extern atomic_t fscache_n_relinquishes;
46319 -extern atomic_t fscache_n_relinquishes_null;
46320 -extern atomic_t fscache_n_relinquishes_waitcrt;
46321 -extern atomic_t fscache_n_relinquishes_retire;
46322 +extern atomic_unchecked_t fscache_n_relinquishes;
46323 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46324 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46325 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46326
46327 -extern atomic_t fscache_n_cookie_index;
46328 -extern atomic_t fscache_n_cookie_data;
46329 -extern atomic_t fscache_n_cookie_special;
46330 +extern atomic_unchecked_t fscache_n_cookie_index;
46331 +extern atomic_unchecked_t fscache_n_cookie_data;
46332 +extern atomic_unchecked_t fscache_n_cookie_special;
46333
46334 -extern atomic_t fscache_n_object_alloc;
46335 -extern atomic_t fscache_n_object_no_alloc;
46336 -extern atomic_t fscache_n_object_lookups;
46337 -extern atomic_t fscache_n_object_lookups_negative;
46338 -extern atomic_t fscache_n_object_lookups_positive;
46339 -extern atomic_t fscache_n_object_lookups_timed_out;
46340 -extern atomic_t fscache_n_object_created;
46341 -extern atomic_t fscache_n_object_avail;
46342 -extern atomic_t fscache_n_object_dead;
46343 +extern atomic_unchecked_t fscache_n_object_alloc;
46344 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46345 +extern atomic_unchecked_t fscache_n_object_lookups;
46346 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46347 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46348 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46349 +extern atomic_unchecked_t fscache_n_object_created;
46350 +extern atomic_unchecked_t fscache_n_object_avail;
46351 +extern atomic_unchecked_t fscache_n_object_dead;
46352
46353 -extern atomic_t fscache_n_checkaux_none;
46354 -extern atomic_t fscache_n_checkaux_okay;
46355 -extern atomic_t fscache_n_checkaux_update;
46356 -extern atomic_t fscache_n_checkaux_obsolete;
46357 +extern atomic_unchecked_t fscache_n_checkaux_none;
46358 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46359 +extern atomic_unchecked_t fscache_n_checkaux_update;
46360 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46361
46362 extern atomic_t fscache_n_cop_alloc_object;
46363 extern atomic_t fscache_n_cop_lookup_object;
46364 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46365 atomic_inc(stat);
46366 }
46367
46368 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46369 +{
46370 + atomic_inc_unchecked(stat);
46371 +}
46372 +
46373 static inline void fscache_stat_d(atomic_t *stat)
46374 {
46375 atomic_dec(stat);
46376 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46377
46378 #define __fscache_stat(stat) (NULL)
46379 #define fscache_stat(stat) do {} while (0)
46380 +#define fscache_stat_unchecked(stat) do {} while (0)
46381 #define fscache_stat_d(stat) do {} while (0)
46382 #endif
46383
46384 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46385 index b6b897c..0ffff9c 100644
46386 --- a/fs/fscache/object.c
46387 +++ b/fs/fscache/object.c
46388 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46389 /* update the object metadata on disk */
46390 case FSCACHE_OBJECT_UPDATING:
46391 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46392 - fscache_stat(&fscache_n_updates_run);
46393 + fscache_stat_unchecked(&fscache_n_updates_run);
46394 fscache_stat(&fscache_n_cop_update_object);
46395 object->cache->ops->update_object(object);
46396 fscache_stat_d(&fscache_n_cop_update_object);
46397 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46398 spin_lock(&object->lock);
46399 object->state = FSCACHE_OBJECT_DEAD;
46400 spin_unlock(&object->lock);
46401 - fscache_stat(&fscache_n_object_dead);
46402 + fscache_stat_unchecked(&fscache_n_object_dead);
46403 goto terminal_transit;
46404
46405 /* handle the parent cache of this object being withdrawn from
46406 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46407 spin_lock(&object->lock);
46408 object->state = FSCACHE_OBJECT_DEAD;
46409 spin_unlock(&object->lock);
46410 - fscache_stat(&fscache_n_object_dead);
46411 + fscache_stat_unchecked(&fscache_n_object_dead);
46412 goto terminal_transit;
46413
46414 /* complain about the object being woken up once it is
46415 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46416 parent->cookie->def->name, cookie->def->name,
46417 object->cache->tag->name);
46418
46419 - fscache_stat(&fscache_n_object_lookups);
46420 + fscache_stat_unchecked(&fscache_n_object_lookups);
46421 fscache_stat(&fscache_n_cop_lookup_object);
46422 ret = object->cache->ops->lookup_object(object);
46423 fscache_stat_d(&fscache_n_cop_lookup_object);
46424 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46425 if (ret == -ETIMEDOUT) {
46426 /* probably stuck behind another object, so move this one to
46427 * the back of the queue */
46428 - fscache_stat(&fscache_n_object_lookups_timed_out);
46429 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46430 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46431 }
46432
46433 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46434
46435 spin_lock(&object->lock);
46436 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46437 - fscache_stat(&fscache_n_object_lookups_negative);
46438 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46439
46440 /* transit here to allow write requests to begin stacking up
46441 * and read requests to begin returning ENODATA */
46442 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46443 * result, in which case there may be data available */
46444 spin_lock(&object->lock);
46445 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46446 - fscache_stat(&fscache_n_object_lookups_positive);
46447 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46448
46449 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46450
46451 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46452 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46453 } else {
46454 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46455 - fscache_stat(&fscache_n_object_created);
46456 + fscache_stat_unchecked(&fscache_n_object_created);
46457
46458 object->state = FSCACHE_OBJECT_AVAILABLE;
46459 spin_unlock(&object->lock);
46460 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46461 fscache_enqueue_dependents(object);
46462
46463 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46464 - fscache_stat(&fscache_n_object_avail);
46465 + fscache_stat_unchecked(&fscache_n_object_avail);
46466
46467 _leave("");
46468 }
46469 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46470 enum fscache_checkaux result;
46471
46472 if (!object->cookie->def->check_aux) {
46473 - fscache_stat(&fscache_n_checkaux_none);
46474 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46475 return FSCACHE_CHECKAUX_OKAY;
46476 }
46477
46478 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46479 switch (result) {
46480 /* entry okay as is */
46481 case FSCACHE_CHECKAUX_OKAY:
46482 - fscache_stat(&fscache_n_checkaux_okay);
46483 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46484 break;
46485
46486 /* entry requires update */
46487 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46488 - fscache_stat(&fscache_n_checkaux_update);
46489 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46490 break;
46491
46492 /* entry requires deletion */
46493 case FSCACHE_CHECKAUX_OBSOLETE:
46494 - fscache_stat(&fscache_n_checkaux_obsolete);
46495 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46496 break;
46497
46498 default:
46499 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46500 index 30afdfa..2256596 100644
46501 --- a/fs/fscache/operation.c
46502 +++ b/fs/fscache/operation.c
46503 @@ -17,7 +17,7 @@
46504 #include <linux/slab.h>
46505 #include "internal.h"
46506
46507 -atomic_t fscache_op_debug_id;
46508 +atomic_unchecked_t fscache_op_debug_id;
46509 EXPORT_SYMBOL(fscache_op_debug_id);
46510
46511 /**
46512 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46513 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46514 ASSERTCMP(atomic_read(&op->usage), >, 0);
46515
46516 - fscache_stat(&fscache_n_op_enqueue);
46517 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46518 switch (op->flags & FSCACHE_OP_TYPE) {
46519 case FSCACHE_OP_ASYNC:
46520 _debug("queue async");
46521 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46522 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46523 if (op->processor)
46524 fscache_enqueue_operation(op);
46525 - fscache_stat(&fscache_n_op_run);
46526 + fscache_stat_unchecked(&fscache_n_op_run);
46527 }
46528
46529 /*
46530 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46531 if (object->n_ops > 1) {
46532 atomic_inc(&op->usage);
46533 list_add_tail(&op->pend_link, &object->pending_ops);
46534 - fscache_stat(&fscache_n_op_pend);
46535 + fscache_stat_unchecked(&fscache_n_op_pend);
46536 } else if (!list_empty(&object->pending_ops)) {
46537 atomic_inc(&op->usage);
46538 list_add_tail(&op->pend_link, &object->pending_ops);
46539 - fscache_stat(&fscache_n_op_pend);
46540 + fscache_stat_unchecked(&fscache_n_op_pend);
46541 fscache_start_operations(object);
46542 } else {
46543 ASSERTCMP(object->n_in_progress, ==, 0);
46544 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46545 object->n_exclusive++; /* reads and writes must wait */
46546 atomic_inc(&op->usage);
46547 list_add_tail(&op->pend_link, &object->pending_ops);
46548 - fscache_stat(&fscache_n_op_pend);
46549 + fscache_stat_unchecked(&fscache_n_op_pend);
46550 ret = 0;
46551 } else {
46552 /* not allowed to submit ops in any other state */
46553 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46554 if (object->n_exclusive > 0) {
46555 atomic_inc(&op->usage);
46556 list_add_tail(&op->pend_link, &object->pending_ops);
46557 - fscache_stat(&fscache_n_op_pend);
46558 + fscache_stat_unchecked(&fscache_n_op_pend);
46559 } else if (!list_empty(&object->pending_ops)) {
46560 atomic_inc(&op->usage);
46561 list_add_tail(&op->pend_link, &object->pending_ops);
46562 - fscache_stat(&fscache_n_op_pend);
46563 + fscache_stat_unchecked(&fscache_n_op_pend);
46564 fscache_start_operations(object);
46565 } else {
46566 ASSERTCMP(object->n_exclusive, ==, 0);
46567 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46568 object->n_ops++;
46569 atomic_inc(&op->usage);
46570 list_add_tail(&op->pend_link, &object->pending_ops);
46571 - fscache_stat(&fscache_n_op_pend);
46572 + fscache_stat_unchecked(&fscache_n_op_pend);
46573 ret = 0;
46574 } else if (object->state == FSCACHE_OBJECT_DYING ||
46575 object->state == FSCACHE_OBJECT_LC_DYING ||
46576 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46577 - fscache_stat(&fscache_n_op_rejected);
46578 + fscache_stat_unchecked(&fscache_n_op_rejected);
46579 ret = -ENOBUFS;
46580 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46581 fscache_report_unexpected_submission(object, op, ostate);
46582 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46583
46584 ret = -EBUSY;
46585 if (!list_empty(&op->pend_link)) {
46586 - fscache_stat(&fscache_n_op_cancelled);
46587 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46588 list_del_init(&op->pend_link);
46589 object->n_ops--;
46590 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46591 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46592 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46593 BUG();
46594
46595 - fscache_stat(&fscache_n_op_release);
46596 + fscache_stat_unchecked(&fscache_n_op_release);
46597
46598 if (op->release) {
46599 op->release(op);
46600 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46601 * lock, and defer it otherwise */
46602 if (!spin_trylock(&object->lock)) {
46603 _debug("defer put");
46604 - fscache_stat(&fscache_n_op_deferred_release);
46605 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46606
46607 cache = object->cache;
46608 spin_lock(&cache->op_gc_list_lock);
46609 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46610
46611 _debug("GC DEFERRED REL OBJ%x OP%x",
46612 object->debug_id, op->debug_id);
46613 - fscache_stat(&fscache_n_op_gc);
46614 + fscache_stat_unchecked(&fscache_n_op_gc);
46615
46616 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46617
46618 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46619 index 3f7a59b..cf196cc 100644
46620 --- a/fs/fscache/page.c
46621 +++ b/fs/fscache/page.c
46622 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46623 val = radix_tree_lookup(&cookie->stores, page->index);
46624 if (!val) {
46625 rcu_read_unlock();
46626 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46627 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46628 __fscache_uncache_page(cookie, page);
46629 return true;
46630 }
46631 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46632 spin_unlock(&cookie->stores_lock);
46633
46634 if (xpage) {
46635 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46636 - fscache_stat(&fscache_n_store_radix_deletes);
46637 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46638 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46639 ASSERTCMP(xpage, ==, page);
46640 } else {
46641 - fscache_stat(&fscache_n_store_vmscan_gone);
46642 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46643 }
46644
46645 wake_up_bit(&cookie->flags, 0);
46646 @@ -107,7 +107,7 @@ page_busy:
46647 /* we might want to wait here, but that could deadlock the allocator as
46648 * the work threads writing to the cache may all end up sleeping
46649 * on memory allocation */
46650 - fscache_stat(&fscache_n_store_vmscan_busy);
46651 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46652 return false;
46653 }
46654 EXPORT_SYMBOL(__fscache_maybe_release_page);
46655 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46656 FSCACHE_COOKIE_STORING_TAG);
46657 if (!radix_tree_tag_get(&cookie->stores, page->index,
46658 FSCACHE_COOKIE_PENDING_TAG)) {
46659 - fscache_stat(&fscache_n_store_radix_deletes);
46660 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46661 xpage = radix_tree_delete(&cookie->stores, page->index);
46662 }
46663 spin_unlock(&cookie->stores_lock);
46664 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46665
46666 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46667
46668 - fscache_stat(&fscache_n_attr_changed_calls);
46669 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46670
46671 if (fscache_object_is_active(object)) {
46672 fscache_stat(&fscache_n_cop_attr_changed);
46673 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46674
46675 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46676
46677 - fscache_stat(&fscache_n_attr_changed);
46678 + fscache_stat_unchecked(&fscache_n_attr_changed);
46679
46680 op = kzalloc(sizeof(*op), GFP_KERNEL);
46681 if (!op) {
46682 - fscache_stat(&fscache_n_attr_changed_nomem);
46683 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46684 _leave(" = -ENOMEM");
46685 return -ENOMEM;
46686 }
46687 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46688 if (fscache_submit_exclusive_op(object, op) < 0)
46689 goto nobufs;
46690 spin_unlock(&cookie->lock);
46691 - fscache_stat(&fscache_n_attr_changed_ok);
46692 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46693 fscache_put_operation(op);
46694 _leave(" = 0");
46695 return 0;
46696 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46697 nobufs:
46698 spin_unlock(&cookie->lock);
46699 kfree(op);
46700 - fscache_stat(&fscache_n_attr_changed_nobufs);
46701 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46702 _leave(" = %d", -ENOBUFS);
46703 return -ENOBUFS;
46704 }
46705 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46706 /* allocate a retrieval operation and attempt to submit it */
46707 op = kzalloc(sizeof(*op), GFP_NOIO);
46708 if (!op) {
46709 - fscache_stat(&fscache_n_retrievals_nomem);
46710 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46711 return NULL;
46712 }
46713
46714 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46715 return 0;
46716 }
46717
46718 - fscache_stat(&fscache_n_retrievals_wait);
46719 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46720
46721 jif = jiffies;
46722 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46723 fscache_wait_bit_interruptible,
46724 TASK_INTERRUPTIBLE) != 0) {
46725 - fscache_stat(&fscache_n_retrievals_intr);
46726 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46727 _leave(" = -ERESTARTSYS");
46728 return -ERESTARTSYS;
46729 }
46730 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46731 */
46732 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46733 struct fscache_retrieval *op,
46734 - atomic_t *stat_op_waits,
46735 - atomic_t *stat_object_dead)
46736 + atomic_unchecked_t *stat_op_waits,
46737 + atomic_unchecked_t *stat_object_dead)
46738 {
46739 int ret;
46740
46741 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46742 goto check_if_dead;
46743
46744 _debug(">>> WT");
46745 - fscache_stat(stat_op_waits);
46746 + fscache_stat_unchecked(stat_op_waits);
46747 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46748 fscache_wait_bit_interruptible,
46749 TASK_INTERRUPTIBLE) < 0) {
46750 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46751
46752 check_if_dead:
46753 if (unlikely(fscache_object_is_dead(object))) {
46754 - fscache_stat(stat_object_dead);
46755 + fscache_stat_unchecked(stat_object_dead);
46756 return -ENOBUFS;
46757 }
46758 return 0;
46759 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46760
46761 _enter("%p,%p,,,", cookie, page);
46762
46763 - fscache_stat(&fscache_n_retrievals);
46764 + fscache_stat_unchecked(&fscache_n_retrievals);
46765
46766 if (hlist_empty(&cookie->backing_objects))
46767 goto nobufs;
46768 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46769 goto nobufs_unlock;
46770 spin_unlock(&cookie->lock);
46771
46772 - fscache_stat(&fscache_n_retrieval_ops);
46773 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46774
46775 /* pin the netfs read context in case we need to do the actual netfs
46776 * read because we've encountered a cache read failure */
46777 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46778
46779 error:
46780 if (ret == -ENOMEM)
46781 - fscache_stat(&fscache_n_retrievals_nomem);
46782 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46783 else if (ret == -ERESTARTSYS)
46784 - fscache_stat(&fscache_n_retrievals_intr);
46785 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46786 else if (ret == -ENODATA)
46787 - fscache_stat(&fscache_n_retrievals_nodata);
46788 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46789 else if (ret < 0)
46790 - fscache_stat(&fscache_n_retrievals_nobufs);
46791 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46792 else
46793 - fscache_stat(&fscache_n_retrievals_ok);
46794 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46795
46796 fscache_put_retrieval(op);
46797 _leave(" = %d", ret);
46798 @@ -429,7 +429,7 @@ nobufs_unlock:
46799 spin_unlock(&cookie->lock);
46800 kfree(op);
46801 nobufs:
46802 - fscache_stat(&fscache_n_retrievals_nobufs);
46803 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46804 _leave(" = -ENOBUFS");
46805 return -ENOBUFS;
46806 }
46807 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46808
46809 _enter("%p,,%d,,,", cookie, *nr_pages);
46810
46811 - fscache_stat(&fscache_n_retrievals);
46812 + fscache_stat_unchecked(&fscache_n_retrievals);
46813
46814 if (hlist_empty(&cookie->backing_objects))
46815 goto nobufs;
46816 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46817 goto nobufs_unlock;
46818 spin_unlock(&cookie->lock);
46819
46820 - fscache_stat(&fscache_n_retrieval_ops);
46821 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46822
46823 /* pin the netfs read context in case we need to do the actual netfs
46824 * read because we've encountered a cache read failure */
46825 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46826
46827 error:
46828 if (ret == -ENOMEM)
46829 - fscache_stat(&fscache_n_retrievals_nomem);
46830 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46831 else if (ret == -ERESTARTSYS)
46832 - fscache_stat(&fscache_n_retrievals_intr);
46833 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46834 else if (ret == -ENODATA)
46835 - fscache_stat(&fscache_n_retrievals_nodata);
46836 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46837 else if (ret < 0)
46838 - fscache_stat(&fscache_n_retrievals_nobufs);
46839 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46840 else
46841 - fscache_stat(&fscache_n_retrievals_ok);
46842 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46843
46844 fscache_put_retrieval(op);
46845 _leave(" = %d", ret);
46846 @@ -545,7 +545,7 @@ nobufs_unlock:
46847 spin_unlock(&cookie->lock);
46848 kfree(op);
46849 nobufs:
46850 - fscache_stat(&fscache_n_retrievals_nobufs);
46851 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46852 _leave(" = -ENOBUFS");
46853 return -ENOBUFS;
46854 }
46855 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46856
46857 _enter("%p,%p,,,", cookie, page);
46858
46859 - fscache_stat(&fscache_n_allocs);
46860 + fscache_stat_unchecked(&fscache_n_allocs);
46861
46862 if (hlist_empty(&cookie->backing_objects))
46863 goto nobufs;
46864 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46865 goto nobufs_unlock;
46866 spin_unlock(&cookie->lock);
46867
46868 - fscache_stat(&fscache_n_alloc_ops);
46869 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46870
46871 ret = fscache_wait_for_retrieval_activation(
46872 object, op,
46873 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46874
46875 error:
46876 if (ret == -ERESTARTSYS)
46877 - fscache_stat(&fscache_n_allocs_intr);
46878 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46879 else if (ret < 0)
46880 - fscache_stat(&fscache_n_allocs_nobufs);
46881 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46882 else
46883 - fscache_stat(&fscache_n_allocs_ok);
46884 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46885
46886 fscache_put_retrieval(op);
46887 _leave(" = %d", ret);
46888 @@ -625,7 +625,7 @@ nobufs_unlock:
46889 spin_unlock(&cookie->lock);
46890 kfree(op);
46891 nobufs:
46892 - fscache_stat(&fscache_n_allocs_nobufs);
46893 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46894 _leave(" = -ENOBUFS");
46895 return -ENOBUFS;
46896 }
46897 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46898
46899 spin_lock(&cookie->stores_lock);
46900
46901 - fscache_stat(&fscache_n_store_calls);
46902 + fscache_stat_unchecked(&fscache_n_store_calls);
46903
46904 /* find a page to store */
46905 page = NULL;
46906 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46907 page = results[0];
46908 _debug("gang %d [%lx]", n, page->index);
46909 if (page->index > op->store_limit) {
46910 - fscache_stat(&fscache_n_store_pages_over_limit);
46911 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46912 goto superseded;
46913 }
46914
46915 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46916 spin_unlock(&cookie->stores_lock);
46917 spin_unlock(&object->lock);
46918
46919 - fscache_stat(&fscache_n_store_pages);
46920 + fscache_stat_unchecked(&fscache_n_store_pages);
46921 fscache_stat(&fscache_n_cop_write_page);
46922 ret = object->cache->ops->write_page(op, page);
46923 fscache_stat_d(&fscache_n_cop_write_page);
46924 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46925 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46926 ASSERT(PageFsCache(page));
46927
46928 - fscache_stat(&fscache_n_stores);
46929 + fscache_stat_unchecked(&fscache_n_stores);
46930
46931 op = kzalloc(sizeof(*op), GFP_NOIO);
46932 if (!op)
46933 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46934 spin_unlock(&cookie->stores_lock);
46935 spin_unlock(&object->lock);
46936
46937 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46938 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46939 op->store_limit = object->store_limit;
46940
46941 if (fscache_submit_op(object, &op->op) < 0)
46942 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46943
46944 spin_unlock(&cookie->lock);
46945 radix_tree_preload_end();
46946 - fscache_stat(&fscache_n_store_ops);
46947 - fscache_stat(&fscache_n_stores_ok);
46948 + fscache_stat_unchecked(&fscache_n_store_ops);
46949 + fscache_stat_unchecked(&fscache_n_stores_ok);
46950
46951 /* the work queue now carries its own ref on the object */
46952 fscache_put_operation(&op->op);
46953 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46954 return 0;
46955
46956 already_queued:
46957 - fscache_stat(&fscache_n_stores_again);
46958 + fscache_stat_unchecked(&fscache_n_stores_again);
46959 already_pending:
46960 spin_unlock(&cookie->stores_lock);
46961 spin_unlock(&object->lock);
46962 spin_unlock(&cookie->lock);
46963 radix_tree_preload_end();
46964 kfree(op);
46965 - fscache_stat(&fscache_n_stores_ok);
46966 + fscache_stat_unchecked(&fscache_n_stores_ok);
46967 _leave(" = 0");
46968 return 0;
46969
46970 @@ -851,14 +851,14 @@ nobufs:
46971 spin_unlock(&cookie->lock);
46972 radix_tree_preload_end();
46973 kfree(op);
46974 - fscache_stat(&fscache_n_stores_nobufs);
46975 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46976 _leave(" = -ENOBUFS");
46977 return -ENOBUFS;
46978
46979 nomem_free:
46980 kfree(op);
46981 nomem:
46982 - fscache_stat(&fscache_n_stores_oom);
46983 + fscache_stat_unchecked(&fscache_n_stores_oom);
46984 _leave(" = -ENOMEM");
46985 return -ENOMEM;
46986 }
46987 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46988 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46989 ASSERTCMP(page, !=, NULL);
46990
46991 - fscache_stat(&fscache_n_uncaches);
46992 + fscache_stat_unchecked(&fscache_n_uncaches);
46993
46994 /* cache withdrawal may beat us to it */
46995 if (!PageFsCache(page))
46996 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46997 unsigned long loop;
46998
46999 #ifdef CONFIG_FSCACHE_STATS
47000 - atomic_add(pagevec->nr, &fscache_n_marks);
47001 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47002 #endif
47003
47004 for (loop = 0; loop < pagevec->nr; loop++) {
47005 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47006 index 4765190..2a067f2 100644
47007 --- a/fs/fscache/stats.c
47008 +++ b/fs/fscache/stats.c
47009 @@ -18,95 +18,95 @@
47010 /*
47011 * operation counters
47012 */
47013 -atomic_t fscache_n_op_pend;
47014 -atomic_t fscache_n_op_run;
47015 -atomic_t fscache_n_op_enqueue;
47016 -atomic_t fscache_n_op_requeue;
47017 -atomic_t fscache_n_op_deferred_release;
47018 -atomic_t fscache_n_op_release;
47019 -atomic_t fscache_n_op_gc;
47020 -atomic_t fscache_n_op_cancelled;
47021 -atomic_t fscache_n_op_rejected;
47022 +atomic_unchecked_t fscache_n_op_pend;
47023 +atomic_unchecked_t fscache_n_op_run;
47024 +atomic_unchecked_t fscache_n_op_enqueue;
47025 +atomic_unchecked_t fscache_n_op_requeue;
47026 +atomic_unchecked_t fscache_n_op_deferred_release;
47027 +atomic_unchecked_t fscache_n_op_release;
47028 +atomic_unchecked_t fscache_n_op_gc;
47029 +atomic_unchecked_t fscache_n_op_cancelled;
47030 +atomic_unchecked_t fscache_n_op_rejected;
47031
47032 -atomic_t fscache_n_attr_changed;
47033 -atomic_t fscache_n_attr_changed_ok;
47034 -atomic_t fscache_n_attr_changed_nobufs;
47035 -atomic_t fscache_n_attr_changed_nomem;
47036 -atomic_t fscache_n_attr_changed_calls;
47037 +atomic_unchecked_t fscache_n_attr_changed;
47038 +atomic_unchecked_t fscache_n_attr_changed_ok;
47039 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47040 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47041 +atomic_unchecked_t fscache_n_attr_changed_calls;
47042
47043 -atomic_t fscache_n_allocs;
47044 -atomic_t fscache_n_allocs_ok;
47045 -atomic_t fscache_n_allocs_wait;
47046 -atomic_t fscache_n_allocs_nobufs;
47047 -atomic_t fscache_n_allocs_intr;
47048 -atomic_t fscache_n_allocs_object_dead;
47049 -atomic_t fscache_n_alloc_ops;
47050 -atomic_t fscache_n_alloc_op_waits;
47051 +atomic_unchecked_t fscache_n_allocs;
47052 +atomic_unchecked_t fscache_n_allocs_ok;
47053 +atomic_unchecked_t fscache_n_allocs_wait;
47054 +atomic_unchecked_t fscache_n_allocs_nobufs;
47055 +atomic_unchecked_t fscache_n_allocs_intr;
47056 +atomic_unchecked_t fscache_n_allocs_object_dead;
47057 +atomic_unchecked_t fscache_n_alloc_ops;
47058 +atomic_unchecked_t fscache_n_alloc_op_waits;
47059
47060 -atomic_t fscache_n_retrievals;
47061 -atomic_t fscache_n_retrievals_ok;
47062 -atomic_t fscache_n_retrievals_wait;
47063 -atomic_t fscache_n_retrievals_nodata;
47064 -atomic_t fscache_n_retrievals_nobufs;
47065 -atomic_t fscache_n_retrievals_intr;
47066 -atomic_t fscache_n_retrievals_nomem;
47067 -atomic_t fscache_n_retrievals_object_dead;
47068 -atomic_t fscache_n_retrieval_ops;
47069 -atomic_t fscache_n_retrieval_op_waits;
47070 +atomic_unchecked_t fscache_n_retrievals;
47071 +atomic_unchecked_t fscache_n_retrievals_ok;
47072 +atomic_unchecked_t fscache_n_retrievals_wait;
47073 +atomic_unchecked_t fscache_n_retrievals_nodata;
47074 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47075 +atomic_unchecked_t fscache_n_retrievals_intr;
47076 +atomic_unchecked_t fscache_n_retrievals_nomem;
47077 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47078 +atomic_unchecked_t fscache_n_retrieval_ops;
47079 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47080
47081 -atomic_t fscache_n_stores;
47082 -atomic_t fscache_n_stores_ok;
47083 -atomic_t fscache_n_stores_again;
47084 -atomic_t fscache_n_stores_nobufs;
47085 -atomic_t fscache_n_stores_oom;
47086 -atomic_t fscache_n_store_ops;
47087 -atomic_t fscache_n_store_calls;
47088 -atomic_t fscache_n_store_pages;
47089 -atomic_t fscache_n_store_radix_deletes;
47090 -atomic_t fscache_n_store_pages_over_limit;
47091 +atomic_unchecked_t fscache_n_stores;
47092 +atomic_unchecked_t fscache_n_stores_ok;
47093 +atomic_unchecked_t fscache_n_stores_again;
47094 +atomic_unchecked_t fscache_n_stores_nobufs;
47095 +atomic_unchecked_t fscache_n_stores_oom;
47096 +atomic_unchecked_t fscache_n_store_ops;
47097 +atomic_unchecked_t fscache_n_store_calls;
47098 +atomic_unchecked_t fscache_n_store_pages;
47099 +atomic_unchecked_t fscache_n_store_radix_deletes;
47100 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47101
47102 -atomic_t fscache_n_store_vmscan_not_storing;
47103 -atomic_t fscache_n_store_vmscan_gone;
47104 -atomic_t fscache_n_store_vmscan_busy;
47105 -atomic_t fscache_n_store_vmscan_cancelled;
47106 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47107 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47108 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47109 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47110
47111 -atomic_t fscache_n_marks;
47112 -atomic_t fscache_n_uncaches;
47113 +atomic_unchecked_t fscache_n_marks;
47114 +atomic_unchecked_t fscache_n_uncaches;
47115
47116 -atomic_t fscache_n_acquires;
47117 -atomic_t fscache_n_acquires_null;
47118 -atomic_t fscache_n_acquires_no_cache;
47119 -atomic_t fscache_n_acquires_ok;
47120 -atomic_t fscache_n_acquires_nobufs;
47121 -atomic_t fscache_n_acquires_oom;
47122 +atomic_unchecked_t fscache_n_acquires;
47123 +atomic_unchecked_t fscache_n_acquires_null;
47124 +atomic_unchecked_t fscache_n_acquires_no_cache;
47125 +atomic_unchecked_t fscache_n_acquires_ok;
47126 +atomic_unchecked_t fscache_n_acquires_nobufs;
47127 +atomic_unchecked_t fscache_n_acquires_oom;
47128
47129 -atomic_t fscache_n_updates;
47130 -atomic_t fscache_n_updates_null;
47131 -atomic_t fscache_n_updates_run;
47132 +atomic_unchecked_t fscache_n_updates;
47133 +atomic_unchecked_t fscache_n_updates_null;
47134 +atomic_unchecked_t fscache_n_updates_run;
47135
47136 -atomic_t fscache_n_relinquishes;
47137 -atomic_t fscache_n_relinquishes_null;
47138 -atomic_t fscache_n_relinquishes_waitcrt;
47139 -atomic_t fscache_n_relinquishes_retire;
47140 +atomic_unchecked_t fscache_n_relinquishes;
47141 +atomic_unchecked_t fscache_n_relinquishes_null;
47142 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47143 +atomic_unchecked_t fscache_n_relinquishes_retire;
47144
47145 -atomic_t fscache_n_cookie_index;
47146 -atomic_t fscache_n_cookie_data;
47147 -atomic_t fscache_n_cookie_special;
47148 +atomic_unchecked_t fscache_n_cookie_index;
47149 +atomic_unchecked_t fscache_n_cookie_data;
47150 +atomic_unchecked_t fscache_n_cookie_special;
47151
47152 -atomic_t fscache_n_object_alloc;
47153 -atomic_t fscache_n_object_no_alloc;
47154 -atomic_t fscache_n_object_lookups;
47155 -atomic_t fscache_n_object_lookups_negative;
47156 -atomic_t fscache_n_object_lookups_positive;
47157 -atomic_t fscache_n_object_lookups_timed_out;
47158 -atomic_t fscache_n_object_created;
47159 -atomic_t fscache_n_object_avail;
47160 -atomic_t fscache_n_object_dead;
47161 +atomic_unchecked_t fscache_n_object_alloc;
47162 +atomic_unchecked_t fscache_n_object_no_alloc;
47163 +atomic_unchecked_t fscache_n_object_lookups;
47164 +atomic_unchecked_t fscache_n_object_lookups_negative;
47165 +atomic_unchecked_t fscache_n_object_lookups_positive;
47166 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47167 +atomic_unchecked_t fscache_n_object_created;
47168 +atomic_unchecked_t fscache_n_object_avail;
47169 +atomic_unchecked_t fscache_n_object_dead;
47170
47171 -atomic_t fscache_n_checkaux_none;
47172 -atomic_t fscache_n_checkaux_okay;
47173 -atomic_t fscache_n_checkaux_update;
47174 -atomic_t fscache_n_checkaux_obsolete;
47175 +atomic_unchecked_t fscache_n_checkaux_none;
47176 +atomic_unchecked_t fscache_n_checkaux_okay;
47177 +atomic_unchecked_t fscache_n_checkaux_update;
47178 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47179
47180 atomic_t fscache_n_cop_alloc_object;
47181 atomic_t fscache_n_cop_lookup_object;
47182 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47183 seq_puts(m, "FS-Cache statistics\n");
47184
47185 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47186 - atomic_read(&fscache_n_cookie_index),
47187 - atomic_read(&fscache_n_cookie_data),
47188 - atomic_read(&fscache_n_cookie_special));
47189 + atomic_read_unchecked(&fscache_n_cookie_index),
47190 + atomic_read_unchecked(&fscache_n_cookie_data),
47191 + atomic_read_unchecked(&fscache_n_cookie_special));
47192
47193 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47194 - atomic_read(&fscache_n_object_alloc),
47195 - atomic_read(&fscache_n_object_no_alloc),
47196 - atomic_read(&fscache_n_object_avail),
47197 - atomic_read(&fscache_n_object_dead));
47198 + atomic_read_unchecked(&fscache_n_object_alloc),
47199 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47200 + atomic_read_unchecked(&fscache_n_object_avail),
47201 + atomic_read_unchecked(&fscache_n_object_dead));
47202 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47203 - atomic_read(&fscache_n_checkaux_none),
47204 - atomic_read(&fscache_n_checkaux_okay),
47205 - atomic_read(&fscache_n_checkaux_update),
47206 - atomic_read(&fscache_n_checkaux_obsolete));
47207 + atomic_read_unchecked(&fscache_n_checkaux_none),
47208 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47209 + atomic_read_unchecked(&fscache_n_checkaux_update),
47210 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47211
47212 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47213 - atomic_read(&fscache_n_marks),
47214 - atomic_read(&fscache_n_uncaches));
47215 + atomic_read_unchecked(&fscache_n_marks),
47216 + atomic_read_unchecked(&fscache_n_uncaches));
47217
47218 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47219 " oom=%u\n",
47220 - atomic_read(&fscache_n_acquires),
47221 - atomic_read(&fscache_n_acquires_null),
47222 - atomic_read(&fscache_n_acquires_no_cache),
47223 - atomic_read(&fscache_n_acquires_ok),
47224 - atomic_read(&fscache_n_acquires_nobufs),
47225 - atomic_read(&fscache_n_acquires_oom));
47226 + atomic_read_unchecked(&fscache_n_acquires),
47227 + atomic_read_unchecked(&fscache_n_acquires_null),
47228 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47229 + atomic_read_unchecked(&fscache_n_acquires_ok),
47230 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47231 + atomic_read_unchecked(&fscache_n_acquires_oom));
47232
47233 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47234 - atomic_read(&fscache_n_object_lookups),
47235 - atomic_read(&fscache_n_object_lookups_negative),
47236 - atomic_read(&fscache_n_object_lookups_positive),
47237 - atomic_read(&fscache_n_object_created),
47238 - atomic_read(&fscache_n_object_lookups_timed_out));
47239 + atomic_read_unchecked(&fscache_n_object_lookups),
47240 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47241 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47242 + atomic_read_unchecked(&fscache_n_object_created),
47243 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47244
47245 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47246 - atomic_read(&fscache_n_updates),
47247 - atomic_read(&fscache_n_updates_null),
47248 - atomic_read(&fscache_n_updates_run));
47249 + atomic_read_unchecked(&fscache_n_updates),
47250 + atomic_read_unchecked(&fscache_n_updates_null),
47251 + atomic_read_unchecked(&fscache_n_updates_run));
47252
47253 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47254 - atomic_read(&fscache_n_relinquishes),
47255 - atomic_read(&fscache_n_relinquishes_null),
47256 - atomic_read(&fscache_n_relinquishes_waitcrt),
47257 - atomic_read(&fscache_n_relinquishes_retire));
47258 + atomic_read_unchecked(&fscache_n_relinquishes),
47259 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47260 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47261 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47262
47263 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47264 - atomic_read(&fscache_n_attr_changed),
47265 - atomic_read(&fscache_n_attr_changed_ok),
47266 - atomic_read(&fscache_n_attr_changed_nobufs),
47267 - atomic_read(&fscache_n_attr_changed_nomem),
47268 - atomic_read(&fscache_n_attr_changed_calls));
47269 + atomic_read_unchecked(&fscache_n_attr_changed),
47270 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47271 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47272 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47273 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47274
47275 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47276 - atomic_read(&fscache_n_allocs),
47277 - atomic_read(&fscache_n_allocs_ok),
47278 - atomic_read(&fscache_n_allocs_wait),
47279 - atomic_read(&fscache_n_allocs_nobufs),
47280 - atomic_read(&fscache_n_allocs_intr));
47281 + atomic_read_unchecked(&fscache_n_allocs),
47282 + atomic_read_unchecked(&fscache_n_allocs_ok),
47283 + atomic_read_unchecked(&fscache_n_allocs_wait),
47284 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47285 + atomic_read_unchecked(&fscache_n_allocs_intr));
47286 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47287 - atomic_read(&fscache_n_alloc_ops),
47288 - atomic_read(&fscache_n_alloc_op_waits),
47289 - atomic_read(&fscache_n_allocs_object_dead));
47290 + atomic_read_unchecked(&fscache_n_alloc_ops),
47291 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47292 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47293
47294 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47295 " int=%u oom=%u\n",
47296 - atomic_read(&fscache_n_retrievals),
47297 - atomic_read(&fscache_n_retrievals_ok),
47298 - atomic_read(&fscache_n_retrievals_wait),
47299 - atomic_read(&fscache_n_retrievals_nodata),
47300 - atomic_read(&fscache_n_retrievals_nobufs),
47301 - atomic_read(&fscache_n_retrievals_intr),
47302 - atomic_read(&fscache_n_retrievals_nomem));
47303 + atomic_read_unchecked(&fscache_n_retrievals),
47304 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47305 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47306 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47307 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47308 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47309 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47310 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47311 - atomic_read(&fscache_n_retrieval_ops),
47312 - atomic_read(&fscache_n_retrieval_op_waits),
47313 - atomic_read(&fscache_n_retrievals_object_dead));
47314 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47315 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47316 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47317
47318 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47319 - atomic_read(&fscache_n_stores),
47320 - atomic_read(&fscache_n_stores_ok),
47321 - atomic_read(&fscache_n_stores_again),
47322 - atomic_read(&fscache_n_stores_nobufs),
47323 - atomic_read(&fscache_n_stores_oom));
47324 + atomic_read_unchecked(&fscache_n_stores),
47325 + atomic_read_unchecked(&fscache_n_stores_ok),
47326 + atomic_read_unchecked(&fscache_n_stores_again),
47327 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47328 + atomic_read_unchecked(&fscache_n_stores_oom));
47329 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47330 - atomic_read(&fscache_n_store_ops),
47331 - atomic_read(&fscache_n_store_calls),
47332 - atomic_read(&fscache_n_store_pages),
47333 - atomic_read(&fscache_n_store_radix_deletes),
47334 - atomic_read(&fscache_n_store_pages_over_limit));
47335 + atomic_read_unchecked(&fscache_n_store_ops),
47336 + atomic_read_unchecked(&fscache_n_store_calls),
47337 + atomic_read_unchecked(&fscache_n_store_pages),
47338 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47339 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47340
47341 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47342 - atomic_read(&fscache_n_store_vmscan_not_storing),
47343 - atomic_read(&fscache_n_store_vmscan_gone),
47344 - atomic_read(&fscache_n_store_vmscan_busy),
47345 - atomic_read(&fscache_n_store_vmscan_cancelled));
47346 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47347 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47348 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47349 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47350
47351 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47352 - atomic_read(&fscache_n_op_pend),
47353 - atomic_read(&fscache_n_op_run),
47354 - atomic_read(&fscache_n_op_enqueue),
47355 - atomic_read(&fscache_n_op_cancelled),
47356 - atomic_read(&fscache_n_op_rejected));
47357 + atomic_read_unchecked(&fscache_n_op_pend),
47358 + atomic_read_unchecked(&fscache_n_op_run),
47359 + atomic_read_unchecked(&fscache_n_op_enqueue),
47360 + atomic_read_unchecked(&fscache_n_op_cancelled),
47361 + atomic_read_unchecked(&fscache_n_op_rejected));
47362 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47363 - atomic_read(&fscache_n_op_deferred_release),
47364 - atomic_read(&fscache_n_op_release),
47365 - atomic_read(&fscache_n_op_gc));
47366 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47367 + atomic_read_unchecked(&fscache_n_op_release),
47368 + atomic_read_unchecked(&fscache_n_op_gc));
47369
47370 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47371 atomic_read(&fscache_n_cop_alloc_object),
47372 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47373 index 3426521..3b75162 100644
47374 --- a/fs/fuse/cuse.c
47375 +++ b/fs/fuse/cuse.c
47376 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
47377 INIT_LIST_HEAD(&cuse_conntbl[i]);
47378
47379 /* inherit and extend fuse_dev_operations */
47380 - cuse_channel_fops = fuse_dev_operations;
47381 - cuse_channel_fops.owner = THIS_MODULE;
47382 - cuse_channel_fops.open = cuse_channel_open;
47383 - cuse_channel_fops.release = cuse_channel_release;
47384 + pax_open_kernel();
47385 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47386 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47387 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47388 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47389 + pax_close_kernel();
47390
47391 cuse_class = class_create(THIS_MODULE, "cuse");
47392 if (IS_ERR(cuse_class))
47393 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47394 index 5f3368a..8306426 100644
47395 --- a/fs/fuse/dev.c
47396 +++ b/fs/fuse/dev.c
47397 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47398 ret = 0;
47399 pipe_lock(pipe);
47400
47401 - if (!pipe->readers) {
47402 + if (!atomic_read(&pipe->readers)) {
47403 send_sig(SIGPIPE, current, 0);
47404 if (!ret)
47405 ret = -EPIPE;
47406 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47407 index 2066328..f5add3b 100644
47408 --- a/fs/fuse/dir.c
47409 +++ b/fs/fuse/dir.c
47410 @@ -1175,7 +1175,7 @@ static char *read_link(struct dentry *dentry)
47411 return link;
47412 }
47413
47414 -static void free_link(char *link)
47415 +static void free_link(const char *link)
47416 {
47417 if (!IS_ERR(link))
47418 free_page((unsigned long) link);
47419 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47420 index 5698746..6086012 100644
47421 --- a/fs/gfs2/inode.c
47422 +++ b/fs/gfs2/inode.c
47423 @@ -1487,7 +1487,7 @@ out:
47424
47425 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47426 {
47427 - char *s = nd_get_link(nd);
47428 + const char *s = nd_get_link(nd);
47429 if (!IS_ERR(s))
47430 kfree(s);
47431 }
47432 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47433 index c60267e..193d9e4 100644
47434 --- a/fs/hugetlbfs/inode.c
47435 +++ b/fs/hugetlbfs/inode.c
47436 @@ -902,7 +902,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47437 .kill_sb = kill_litter_super,
47438 };
47439
47440 -static struct vfsmount *hugetlbfs_vfsmount;
47441 +struct vfsmount *hugetlbfs_vfsmount;
47442
47443 static int can_do_hugetlb_shm(void)
47444 {
47445 diff --git a/fs/inode.c b/fs/inode.c
47446 index 83ab215..8842101 100644
47447 --- a/fs/inode.c
47448 +++ b/fs/inode.c
47449 @@ -870,8 +870,8 @@ unsigned int get_next_ino(void)
47450
47451 #ifdef CONFIG_SMP
47452 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47453 - static atomic_t shared_last_ino;
47454 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47455 + static atomic_unchecked_t shared_last_ino;
47456 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47457
47458 res = next - LAST_INO_BATCH;
47459 }
47460 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47461 index eafb8d3..f423d37 100644
47462 --- a/fs/jffs2/erase.c
47463 +++ b/fs/jffs2/erase.c
47464 @@ -438,7 +438,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47465 struct jffs2_unknown_node marker = {
47466 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47467 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47468 - .totlen = cpu_to_je32(c->cleanmarker_size)
47469 + .totlen = cpu_to_je32(c->cleanmarker_size),
47470 + .hdr_crc = cpu_to_je32(0)
47471 };
47472
47473 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47474 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47475 index 30e8f47..21f600c 100644
47476 --- a/fs/jffs2/wbuf.c
47477 +++ b/fs/jffs2/wbuf.c
47478 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47479 {
47480 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47481 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47482 - .totlen = constant_cpu_to_je32(8)
47483 + .totlen = constant_cpu_to_je32(8),
47484 + .hdr_crc = constant_cpu_to_je32(0)
47485 };
47486
47487 /*
47488 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47489 index 682bca6..86b8e6e 100644
47490 --- a/fs/jfs/super.c
47491 +++ b/fs/jfs/super.c
47492 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
47493
47494 jfs_inode_cachep =
47495 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47496 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47497 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47498 init_once);
47499 if (jfs_inode_cachep == NULL)
47500 return -ENOMEM;
47501 diff --git a/fs/libfs.c b/fs/libfs.c
47502 index 5b2dbb3..7442d54 100644
47503 --- a/fs/libfs.c
47504 +++ b/fs/libfs.c
47505 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47506
47507 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47508 struct dentry *next;
47509 + char d_name[sizeof(next->d_iname)];
47510 + const unsigned char *name;
47511 +
47512 next = list_entry(p, struct dentry, d_u.d_child);
47513 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47514 if (!simple_positive(next)) {
47515 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47516
47517 spin_unlock(&next->d_lock);
47518 spin_unlock(&dentry->d_lock);
47519 - if (filldir(dirent, next->d_name.name,
47520 + name = next->d_name.name;
47521 + if (name == next->d_iname) {
47522 + memcpy(d_name, name, next->d_name.len);
47523 + name = d_name;
47524 + }
47525 + if (filldir(dirent, name,
47526 next->d_name.len, filp->f_pos,
47527 next->d_inode->i_ino,
47528 dt_type(next->d_inode)) < 0)
47529 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47530 index 8392cb8..80d6193 100644
47531 --- a/fs/lockd/clntproc.c
47532 +++ b/fs/lockd/clntproc.c
47533 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47534 /*
47535 * Cookie counter for NLM requests
47536 */
47537 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47538 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47539
47540 void nlmclnt_next_cookie(struct nlm_cookie *c)
47541 {
47542 - u32 cookie = atomic_inc_return(&nlm_cookie);
47543 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47544
47545 memcpy(c->data, &cookie, 4);
47546 c->len=4;
47547 diff --git a/fs/locks.c b/fs/locks.c
47548 index 0d68f1f..f216b79 100644
47549 --- a/fs/locks.c
47550 +++ b/fs/locks.c
47551 @@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
47552 return;
47553
47554 if (filp->f_op && filp->f_op->flock) {
47555 - struct file_lock fl = {
47556 + struct file_lock flock = {
47557 .fl_pid = current->tgid,
47558 .fl_file = filp,
47559 .fl_flags = FL_FLOCK,
47560 .fl_type = F_UNLCK,
47561 .fl_end = OFFSET_MAX,
47562 };
47563 - filp->f_op->flock(filp, F_SETLKW, &fl);
47564 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47565 - fl.fl_ops->fl_release_private(&fl);
47566 + filp->f_op->flock(filp, F_SETLKW, &flock);
47567 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47568 + flock.fl_ops->fl_release_private(&flock);
47569 }
47570
47571 lock_flocks();
47572 diff --git a/fs/namei.c b/fs/namei.c
47573 index 46ea9cc..c7cf3a3 100644
47574 --- a/fs/namei.c
47575 +++ b/fs/namei.c
47576 @@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
47577 if (ret != -EACCES)
47578 return ret;
47579
47580 +#ifdef CONFIG_GRKERNSEC
47581 + /* we'll block if we have to log due to a denied capability use */
47582 + if (mask & MAY_NOT_BLOCK)
47583 + return -ECHILD;
47584 +#endif
47585 +
47586 if (S_ISDIR(inode->i_mode)) {
47587 /* DACs are overridable for directories */
47588 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
47589 - return 0;
47590 if (!(mask & MAY_WRITE))
47591 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
47592 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
47593 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
47594 return 0;
47595 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
47596 + return 0;
47597 return -EACCES;
47598 }
47599 /*
47600 + * Searching includes executable on directories, else just read.
47601 + */
47602 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47603 + if (mask == MAY_READ)
47604 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
47605 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
47606 + return 0;
47607 +
47608 + /*
47609 * Read/write DACs are always overridable.
47610 * Executable DACs are overridable when there is
47611 * at least one exec bit set.
47612 @@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
47613 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
47614 return 0;
47615
47616 - /*
47617 - * Searching includes executable on directories, else just read.
47618 - */
47619 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47620 - if (mask == MAY_READ)
47621 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
47622 - return 0;
47623 -
47624 return -EACCES;
47625 }
47626
47627 @@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47628 return error;
47629 }
47630
47631 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47632 + dentry->d_inode, dentry, nd->path.mnt)) {
47633 + error = -EACCES;
47634 + *p = ERR_PTR(error); /* no ->put_link(), please */
47635 + path_put(&nd->path);
47636 + return error;
47637 + }
47638 +
47639 nd->last_type = LAST_BIND;
47640 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47641 error = PTR_ERR(*p);
47642 if (!IS_ERR(*p)) {
47643 - char *s = nd_get_link(nd);
47644 + const char *s = nd_get_link(nd);
47645 error = 0;
47646 if (s)
47647 error = __vfs_follow_link(nd, s);
47648 @@ -1650,6 +1666,21 @@ static int path_lookupat(int dfd, const char *name,
47649 if (!err)
47650 err = complete_walk(nd);
47651
47652 + if (!(nd->flags & LOOKUP_PARENT)) {
47653 +#ifdef CONFIG_GRKERNSEC
47654 + if (flags & LOOKUP_RCU) {
47655 + if (!err)
47656 + path_put(&nd->path);
47657 + err = -ECHILD;
47658 + } else
47659 +#endif
47660 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47661 + if (!err)
47662 + path_put(&nd->path);
47663 + err = -ENOENT;
47664 + }
47665 + }
47666 +
47667 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47668 if (!nd->inode->i_op->lookup) {
47669 path_put(&nd->path);
47670 @@ -1677,6 +1708,15 @@ static int do_path_lookup(int dfd, const char *name,
47671 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47672
47673 if (likely(!retval)) {
47674 + if (*name != '/' && nd->path.dentry && nd->inode) {
47675 +#ifdef CONFIG_GRKERNSEC
47676 + if (flags & LOOKUP_RCU)
47677 + return -ECHILD;
47678 +#endif
47679 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47680 + return -ENOENT;
47681 + }
47682 +
47683 if (unlikely(!audit_dummy_context())) {
47684 if (nd->path.dentry && nd->inode)
47685 audit_inode(name, nd->path.dentry);
47686 @@ -2071,6 +2111,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47687 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47688 return -EPERM;
47689
47690 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47691 + return -EPERM;
47692 + if (gr_handle_rawio(inode))
47693 + return -EPERM;
47694 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47695 + return -EACCES;
47696 +
47697 return 0;
47698 }
47699
47700 @@ -2132,6 +2179,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47701 error = complete_walk(nd);
47702 if (error)
47703 return ERR_PTR(error);
47704 +#ifdef CONFIG_GRKERNSEC
47705 + if (nd->flags & LOOKUP_RCU) {
47706 + error = -ECHILD;
47707 + goto exit;
47708 + }
47709 +#endif
47710 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47711 + error = -ENOENT;
47712 + goto exit;
47713 + }
47714 audit_inode(pathname, nd->path.dentry);
47715 if (open_flag & O_CREAT) {
47716 error = -EISDIR;
47717 @@ -2142,6 +2199,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47718 error = complete_walk(nd);
47719 if (error)
47720 return ERR_PTR(error);
47721 +#ifdef CONFIG_GRKERNSEC
47722 + if (nd->flags & LOOKUP_RCU) {
47723 + error = -ECHILD;
47724 + goto exit;
47725 + }
47726 +#endif
47727 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47728 + error = -ENOENT;
47729 + goto exit;
47730 + }
47731 audit_inode(pathname, dir);
47732 goto ok;
47733 }
47734 @@ -2163,6 +2230,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47735 error = complete_walk(nd);
47736 if (error)
47737 return ERR_PTR(error);
47738 +#ifdef CONFIG_GRKERNSEC
47739 + if (nd->flags & LOOKUP_RCU) {
47740 + error = -ECHILD;
47741 + goto exit;
47742 + }
47743 +#endif
47744 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47745 + error = -ENOENT;
47746 + goto exit;
47747 + }
47748
47749 error = -ENOTDIR;
47750 if (nd->flags & LOOKUP_DIRECTORY) {
47751 @@ -2203,6 +2280,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47752 /* Negative dentry, just create the file */
47753 if (!dentry->d_inode) {
47754 umode_t mode = op->mode;
47755 +
47756 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47757 + error = -EACCES;
47758 + goto exit_mutex_unlock;
47759 + }
47760 +
47761 if (!IS_POSIXACL(dir->d_inode))
47762 mode &= ~current_umask();
47763 /*
47764 @@ -2226,6 +2309,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47765 error = vfs_create(dir->d_inode, dentry, mode, nd);
47766 if (error)
47767 goto exit_mutex_unlock;
47768 + else
47769 + gr_handle_create(path->dentry, path->mnt);
47770 mutex_unlock(&dir->d_inode->i_mutex);
47771 dput(nd->path.dentry);
47772 nd->path.dentry = dentry;
47773 @@ -2235,6 +2320,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47774 /*
47775 * It already exists.
47776 */
47777 +
47778 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47779 + error = -ENOENT;
47780 + goto exit_mutex_unlock;
47781 + }
47782 +
47783 + /* only check if O_CREAT is specified, all other checks need to go
47784 + into may_open */
47785 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47786 + error = -EACCES;
47787 + goto exit_mutex_unlock;
47788 + }
47789 +
47790 mutex_unlock(&dir->d_inode->i_mutex);
47791 audit_inode(pathname, path->dentry);
47792
47793 @@ -2447,6 +2545,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47794 *path = nd.path;
47795 return dentry;
47796 eexist:
47797 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47798 + dput(dentry);
47799 + dentry = ERR_PTR(-ENOENT);
47800 + goto fail;
47801 + }
47802 dput(dentry);
47803 dentry = ERR_PTR(-EEXIST);
47804 fail:
47805 @@ -2469,6 +2572,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47806 }
47807 EXPORT_SYMBOL(user_path_create);
47808
47809 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47810 +{
47811 + char *tmp = getname(pathname);
47812 + struct dentry *res;
47813 + if (IS_ERR(tmp))
47814 + return ERR_CAST(tmp);
47815 + res = kern_path_create(dfd, tmp, path, is_dir);
47816 + if (IS_ERR(res))
47817 + putname(tmp);
47818 + else
47819 + *to = tmp;
47820 + return res;
47821 +}
47822 +
47823 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47824 {
47825 int error = may_create(dir, dentry);
47826 @@ -2536,6 +2653,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47827 error = mnt_want_write(path.mnt);
47828 if (error)
47829 goto out_dput;
47830 +
47831 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47832 + error = -EPERM;
47833 + goto out_drop_write;
47834 + }
47835 +
47836 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47837 + error = -EACCES;
47838 + goto out_drop_write;
47839 + }
47840 +
47841 error = security_path_mknod(&path, dentry, mode, dev);
47842 if (error)
47843 goto out_drop_write;
47844 @@ -2553,6 +2681,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47845 }
47846 out_drop_write:
47847 mnt_drop_write(path.mnt);
47848 +
47849 + if (!error)
47850 + gr_handle_create(dentry, path.mnt);
47851 out_dput:
47852 dput(dentry);
47853 mutex_unlock(&path.dentry->d_inode->i_mutex);
47854 @@ -2602,12 +2733,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47855 error = mnt_want_write(path.mnt);
47856 if (error)
47857 goto out_dput;
47858 +
47859 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47860 + error = -EACCES;
47861 + goto out_drop_write;
47862 + }
47863 +
47864 error = security_path_mkdir(&path, dentry, mode);
47865 if (error)
47866 goto out_drop_write;
47867 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47868 out_drop_write:
47869 mnt_drop_write(path.mnt);
47870 +
47871 + if (!error)
47872 + gr_handle_create(dentry, path.mnt);
47873 out_dput:
47874 dput(dentry);
47875 mutex_unlock(&path.dentry->d_inode->i_mutex);
47876 @@ -2687,6 +2827,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47877 char * name;
47878 struct dentry *dentry;
47879 struct nameidata nd;
47880 + ino_t saved_ino = 0;
47881 + dev_t saved_dev = 0;
47882
47883 error = user_path_parent(dfd, pathname, &nd, &name);
47884 if (error)
47885 @@ -2715,6 +2857,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47886 error = -ENOENT;
47887 goto exit3;
47888 }
47889 +
47890 + saved_ino = dentry->d_inode->i_ino;
47891 + saved_dev = gr_get_dev_from_dentry(dentry);
47892 +
47893 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47894 + error = -EACCES;
47895 + goto exit3;
47896 + }
47897 +
47898 error = mnt_want_write(nd.path.mnt);
47899 if (error)
47900 goto exit3;
47901 @@ -2722,6 +2873,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47902 if (error)
47903 goto exit4;
47904 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47905 + if (!error && (saved_dev || saved_ino))
47906 + gr_handle_delete(saved_ino, saved_dev);
47907 exit4:
47908 mnt_drop_write(nd.path.mnt);
47909 exit3:
47910 @@ -2784,6 +2937,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47911 struct dentry *dentry;
47912 struct nameidata nd;
47913 struct inode *inode = NULL;
47914 + ino_t saved_ino = 0;
47915 + dev_t saved_dev = 0;
47916
47917 error = user_path_parent(dfd, pathname, &nd, &name);
47918 if (error)
47919 @@ -2806,6 +2961,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47920 if (!inode)
47921 goto slashes;
47922 ihold(inode);
47923 +
47924 + if (inode->i_nlink <= 1) {
47925 + saved_ino = inode->i_ino;
47926 + saved_dev = gr_get_dev_from_dentry(dentry);
47927 + }
47928 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47929 + error = -EACCES;
47930 + goto exit2;
47931 + }
47932 +
47933 error = mnt_want_write(nd.path.mnt);
47934 if (error)
47935 goto exit2;
47936 @@ -2813,6 +2978,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47937 if (error)
47938 goto exit3;
47939 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47940 + if (!error && (saved_ino || saved_dev))
47941 + gr_handle_delete(saved_ino, saved_dev);
47942 exit3:
47943 mnt_drop_write(nd.path.mnt);
47944 exit2:
47945 @@ -2888,10 +3055,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47946 error = mnt_want_write(path.mnt);
47947 if (error)
47948 goto out_dput;
47949 +
47950 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47951 + error = -EACCES;
47952 + goto out_drop_write;
47953 + }
47954 +
47955 error = security_path_symlink(&path, dentry, from);
47956 if (error)
47957 goto out_drop_write;
47958 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47959 + if (!error)
47960 + gr_handle_create(dentry, path.mnt);
47961 out_drop_write:
47962 mnt_drop_write(path.mnt);
47963 out_dput:
47964 @@ -2963,6 +3138,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47965 {
47966 struct dentry *new_dentry;
47967 struct path old_path, new_path;
47968 + char *to = NULL;
47969 int how = 0;
47970 int error;
47971
47972 @@ -2986,7 +3162,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47973 if (error)
47974 return error;
47975
47976 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47977 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47978 error = PTR_ERR(new_dentry);
47979 if (IS_ERR(new_dentry))
47980 goto out;
47981 @@ -2997,13 +3173,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47982 error = mnt_want_write(new_path.mnt);
47983 if (error)
47984 goto out_dput;
47985 +
47986 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47987 + old_path.dentry->d_inode,
47988 + old_path.dentry->d_inode->i_mode, to)) {
47989 + error = -EACCES;
47990 + goto out_drop_write;
47991 + }
47992 +
47993 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47994 + old_path.dentry, old_path.mnt, to)) {
47995 + error = -EACCES;
47996 + goto out_drop_write;
47997 + }
47998 +
47999 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48000 if (error)
48001 goto out_drop_write;
48002 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48003 + if (!error)
48004 + gr_handle_create(new_dentry, new_path.mnt);
48005 out_drop_write:
48006 mnt_drop_write(new_path.mnt);
48007 out_dput:
48008 + putname(to);
48009 dput(new_dentry);
48010 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
48011 path_put(&new_path);
48012 @@ -3231,6 +3424,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48013 if (new_dentry == trap)
48014 goto exit5;
48015
48016 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48017 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48018 + to);
48019 + if (error)
48020 + goto exit5;
48021 +
48022 error = mnt_want_write(oldnd.path.mnt);
48023 if (error)
48024 goto exit5;
48025 @@ -3240,6 +3439,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48026 goto exit6;
48027 error = vfs_rename(old_dir->d_inode, old_dentry,
48028 new_dir->d_inode, new_dentry);
48029 + if (!error)
48030 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48031 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48032 exit6:
48033 mnt_drop_write(oldnd.path.mnt);
48034 exit5:
48035 @@ -3265,6 +3467,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48036
48037 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48038 {
48039 + char tmpbuf[64];
48040 + const char *newlink;
48041 int len;
48042
48043 len = PTR_ERR(link);
48044 @@ -3274,7 +3478,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48045 len = strlen(link);
48046 if (len > (unsigned) buflen)
48047 len = buflen;
48048 - if (copy_to_user(buffer, link, len))
48049 +
48050 + if (len < sizeof(tmpbuf)) {
48051 + memcpy(tmpbuf, link, len);
48052 + newlink = tmpbuf;
48053 + } else
48054 + newlink = link;
48055 +
48056 + if (copy_to_user(buffer, newlink, len))
48057 len = -EFAULT;
48058 out:
48059 return len;
48060 diff --git a/fs/namespace.c b/fs/namespace.c
48061 index e608199..9609cb9 100644
48062 --- a/fs/namespace.c
48063 +++ b/fs/namespace.c
48064 @@ -1155,6 +1155,9 @@ static int do_umount(struct mount *mnt, int flags)
48065 if (!(sb->s_flags & MS_RDONLY))
48066 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48067 up_write(&sb->s_umount);
48068 +
48069 + gr_log_remount(mnt->mnt_devname, retval);
48070 +
48071 return retval;
48072 }
48073
48074 @@ -1174,6 +1177,9 @@ static int do_umount(struct mount *mnt, int flags)
48075 br_write_unlock(vfsmount_lock);
48076 up_write(&namespace_sem);
48077 release_mounts(&umount_list);
48078 +
48079 + gr_log_unmount(mnt->mnt_devname, retval);
48080 +
48081 return retval;
48082 }
48083
48084 @@ -2175,6 +2181,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48085 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48086 MS_STRICTATIME);
48087
48088 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48089 + retval = -EPERM;
48090 + goto dput_out;
48091 + }
48092 +
48093 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48094 + retval = -EPERM;
48095 + goto dput_out;
48096 + }
48097 +
48098 if (flags & MS_REMOUNT)
48099 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48100 data_page);
48101 @@ -2189,6 +2205,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48102 dev_name, data_page);
48103 dput_out:
48104 path_put(&path);
48105 +
48106 + gr_log_mount(dev_name, dir_name, retval);
48107 +
48108 return retval;
48109 }
48110
48111 @@ -2470,6 +2489,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48112 if (error)
48113 goto out2;
48114
48115 + if (gr_handle_chroot_pivot()) {
48116 + error = -EPERM;
48117 + goto out2;
48118 + }
48119 +
48120 get_fs_root(current->fs, &root);
48121 error = lock_mount(&old);
48122 if (error)
48123 diff --git a/fs/ncpfs/ncplib_kernel.h b/fs/ncpfs/ncplib_kernel.h
48124 index 32c0658..b1c2045e 100644
48125 --- a/fs/ncpfs/ncplib_kernel.h
48126 +++ b/fs/ncpfs/ncplib_kernel.h
48127 @@ -130,7 +130,7 @@ static inline int ncp_is_nfs_extras(struct ncp_server* server, unsigned int voln
48128 int ncp__io2vol(struct ncp_server *, unsigned char *, unsigned int *,
48129 const unsigned char *, unsigned int, int);
48130 int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
48131 - const unsigned char *, unsigned int, int);
48132 + const unsigned char *, unsigned int, int) __size_overflow(5);
48133
48134 #define NCP_ESC ':'
48135 #define NCP_IO_TABLE(sb) (NCP_SBP(sb)->nls_io)
48136 @@ -146,7 +146,7 @@ int ncp__vol2io(struct ncp_server *, unsigned char *, unsigned int *,
48137 int ncp__io2vol(unsigned char *, unsigned int *,
48138 const unsigned char *, unsigned int, int);
48139 int ncp__vol2io(unsigned char *, unsigned int *,
48140 - const unsigned char *, unsigned int, int);
48141 + const unsigned char *, unsigned int, int) __size_overflow(5);
48142
48143 #define NCP_IO_TABLE(sb) NULL
48144 #define ncp_tolower(t, c) tolower(c)
48145 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48146 index f649fba..236bf92 100644
48147 --- a/fs/nfs/inode.c
48148 +++ b/fs/nfs/inode.c
48149 @@ -151,7 +151,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
48150 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
48151 nfsi->attrtimeo_timestamp = jiffies;
48152
48153 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
48154 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
48155 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
48156 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
48157 else
48158 @@ -1003,16 +1003,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48159 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48160 }
48161
48162 -static atomic_long_t nfs_attr_generation_counter;
48163 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48164
48165 static unsigned long nfs_read_attr_generation_counter(void)
48166 {
48167 - return atomic_long_read(&nfs_attr_generation_counter);
48168 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48169 }
48170
48171 unsigned long nfs_inc_attr_generation_counter(void)
48172 {
48173 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48174 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48175 }
48176
48177 void nfs_fattr_init(struct nfs_fattr *fattr)
48178 diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
48179 index 2612223..e0ab779 100644
48180 --- a/fs/nfs/nfs4proc.c
48181 +++ b/fs/nfs/nfs4proc.c
48182 @@ -3588,19 +3588,23 @@ static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t bu
48183 if (npages == 0)
48184 npages = 1;
48185
48186 + /* Add an extra page to handle the bitmap returned */
48187 + npages++;
48188 +
48189 for (i = 0; i < npages; i++) {
48190 pages[i] = alloc_page(GFP_KERNEL);
48191 if (!pages[i])
48192 goto out_free;
48193 }
48194 - if (npages > 1) {
48195 - /* for decoding across pages */
48196 - res.acl_scratch = alloc_page(GFP_KERNEL);
48197 - if (!res.acl_scratch)
48198 - goto out_free;
48199 - }
48200 +
48201 + /* for decoding across pages */
48202 + res.acl_scratch = alloc_page(GFP_KERNEL);
48203 + if (!res.acl_scratch)
48204 + goto out_free;
48205 +
48206 args.acl_len = npages * PAGE_SIZE;
48207 args.acl_pgbase = 0;
48208 +
48209 /* Let decode_getfacl know not to fail if the ACL data is larger than
48210 * the page we send as a guess */
48211 if (buf == NULL)
48212 diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
48213 index 33bd8d0..9b26eaf 100644
48214 --- a/fs/nfs/nfs4xdr.c
48215 +++ b/fs/nfs/nfs4xdr.c
48216 @@ -4975,11 +4975,19 @@ static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
48217 bitmap[3] = {0};
48218 struct kvec *iov = req->rq_rcv_buf.head;
48219 int status;
48220 + size_t page_len = xdr->buf->page_len;
48221
48222 res->acl_len = 0;
48223 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
48224 goto out;
48225 +
48226 bm_p = xdr->p;
48227 + res->acl_data_offset = be32_to_cpup(bm_p) + 2;
48228 + res->acl_data_offset <<= 2;
48229 + /* Check if the acl data starts beyond the allocated buffer */
48230 + if (res->acl_data_offset > page_len)
48231 + return -ERANGE;
48232 +
48233 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
48234 goto out;
48235 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
48236 @@ -4989,28 +4997,24 @@ static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
48237 return -EIO;
48238 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
48239 size_t hdrlen;
48240 - u32 recvd;
48241
48242 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
48243 * are stored with the acl data to handle the problem of
48244 * variable length bitmaps.*/
48245 xdr->p = bm_p;
48246 - res->acl_data_offset = be32_to_cpup(bm_p) + 2;
48247 - res->acl_data_offset <<= 2;
48248
48249 /* We ignore &savep and don't do consistency checks on
48250 * the attr length. Let userspace figure it out.... */
48251 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
48252 attrlen += res->acl_data_offset;
48253 - recvd = req->rq_rcv_buf.len - hdrlen;
48254 - if (attrlen > recvd) {
48255 + if (attrlen > page_len) {
48256 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
48257 /* getxattr interface called with a NULL buf */
48258 res->acl_len = attrlen;
48259 goto out;
48260 }
48261 - dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
48262 - attrlen, recvd);
48263 + dprintk("NFS: acl reply: attrlen %zu > page_len %u\n",
48264 + attrlen, page_len);
48265 return -EINVAL;
48266 }
48267 xdr_read_pages(xdr, attrlen);
48268 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48269 index b96fe94..a4dbece 100644
48270 --- a/fs/nfsd/vfs.c
48271 +++ b/fs/nfsd/vfs.c
48272 @@ -925,7 +925,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48273 } else {
48274 oldfs = get_fs();
48275 set_fs(KERNEL_DS);
48276 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48277 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48278 set_fs(oldfs);
48279 }
48280
48281 @@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48282
48283 /* Write the data. */
48284 oldfs = get_fs(); set_fs(KERNEL_DS);
48285 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48286 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48287 set_fs(oldfs);
48288 if (host_err < 0)
48289 goto out_nfserr;
48290 @@ -1564,7 +1564,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48291 */
48292
48293 oldfs = get_fs(); set_fs(KERNEL_DS);
48294 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
48295 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
48296 set_fs(oldfs);
48297
48298 if (host_err < 0)
48299 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48300 index 3568c8a..e0240d8 100644
48301 --- a/fs/notify/fanotify/fanotify_user.c
48302 +++ b/fs/notify/fanotify/fanotify_user.c
48303 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48304 goto out_close_fd;
48305
48306 ret = -EFAULT;
48307 - if (copy_to_user(buf, &fanotify_event_metadata,
48308 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48309 + copy_to_user(buf, &fanotify_event_metadata,
48310 fanotify_event_metadata.event_len))
48311 goto out_kill_access_response;
48312
48313 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48314 index ee18815..7aa5d01 100644
48315 --- a/fs/notify/notification.c
48316 +++ b/fs/notify/notification.c
48317 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48318 * get set to 0 so it will never get 'freed'
48319 */
48320 static struct fsnotify_event *q_overflow_event;
48321 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48322 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48323
48324 /**
48325 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48326 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48327 */
48328 u32 fsnotify_get_cookie(void)
48329 {
48330 - return atomic_inc_return(&fsnotify_sync_cookie);
48331 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48332 }
48333 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48334
48335 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48336 index 99e3610..02c1068 100644
48337 --- a/fs/ntfs/dir.c
48338 +++ b/fs/ntfs/dir.c
48339 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48340 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48341 ~(s64)(ndir->itype.index.block_size - 1)));
48342 /* Bounds checks. */
48343 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48344 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48345 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48346 "inode 0x%lx or driver bug.", vdir->i_ino);
48347 goto err_out;
48348 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48349 index c587e2d..3641eaa 100644
48350 --- a/fs/ntfs/file.c
48351 +++ b/fs/ntfs/file.c
48352 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48353 #endif /* NTFS_RW */
48354 };
48355
48356 -const struct file_operations ntfs_empty_file_ops = {};
48357 +const struct file_operations ntfs_empty_file_ops __read_only;
48358
48359 -const struct inode_operations ntfs_empty_inode_ops = {};
48360 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48361 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48362 index 210c352..a174f83 100644
48363 --- a/fs/ocfs2/localalloc.c
48364 +++ b/fs/ocfs2/localalloc.c
48365 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48366 goto bail;
48367 }
48368
48369 - atomic_inc(&osb->alloc_stats.moves);
48370 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48371
48372 bail:
48373 if (handle)
48374 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48375 index d355e6e..578d905 100644
48376 --- a/fs/ocfs2/ocfs2.h
48377 +++ b/fs/ocfs2/ocfs2.h
48378 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48379
48380 struct ocfs2_alloc_stats
48381 {
48382 - atomic_t moves;
48383 - atomic_t local_data;
48384 - atomic_t bitmap_data;
48385 - atomic_t bg_allocs;
48386 - atomic_t bg_extends;
48387 + atomic_unchecked_t moves;
48388 + atomic_unchecked_t local_data;
48389 + atomic_unchecked_t bitmap_data;
48390 + atomic_unchecked_t bg_allocs;
48391 + atomic_unchecked_t bg_extends;
48392 };
48393
48394 enum ocfs2_local_alloc_state
48395 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48396 index f169da4..9112253 100644
48397 --- a/fs/ocfs2/suballoc.c
48398 +++ b/fs/ocfs2/suballoc.c
48399 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48400 mlog_errno(status);
48401 goto bail;
48402 }
48403 - atomic_inc(&osb->alloc_stats.bg_extends);
48404 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48405
48406 /* You should never ask for this much metadata */
48407 BUG_ON(bits_wanted >
48408 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48409 mlog_errno(status);
48410 goto bail;
48411 }
48412 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48413 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48414
48415 *suballoc_loc = res.sr_bg_blkno;
48416 *suballoc_bit_start = res.sr_bit_offset;
48417 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48418 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48419 res->sr_bits);
48420
48421 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48422 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48423
48424 BUG_ON(res->sr_bits != 1);
48425
48426 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48427 mlog_errno(status);
48428 goto bail;
48429 }
48430 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48431 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48432
48433 BUG_ON(res.sr_bits != 1);
48434
48435 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48436 cluster_start,
48437 num_clusters);
48438 if (!status)
48439 - atomic_inc(&osb->alloc_stats.local_data);
48440 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48441 } else {
48442 if (min_clusters > (osb->bitmap_cpg - 1)) {
48443 /* The only paths asking for contiguousness
48444 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48445 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48446 res.sr_bg_blkno,
48447 res.sr_bit_offset);
48448 - atomic_inc(&osb->alloc_stats.bitmap_data);
48449 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48450 *num_clusters = res.sr_bits;
48451 }
48452 }
48453 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48454 index 604e12c..8426483 100644
48455 --- a/fs/ocfs2/super.c
48456 +++ b/fs/ocfs2/super.c
48457 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48458 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48459 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48460 "Stats",
48461 - atomic_read(&osb->alloc_stats.bitmap_data),
48462 - atomic_read(&osb->alloc_stats.local_data),
48463 - atomic_read(&osb->alloc_stats.bg_allocs),
48464 - atomic_read(&osb->alloc_stats.moves),
48465 - atomic_read(&osb->alloc_stats.bg_extends));
48466 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48467 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48468 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48469 + atomic_read_unchecked(&osb->alloc_stats.moves),
48470 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48471
48472 out += snprintf(buf + out, len - out,
48473 "%10s => State: %u Descriptor: %llu Size: %u bits "
48474 @@ -2117,11 +2117,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48475 spin_lock_init(&osb->osb_xattr_lock);
48476 ocfs2_init_steal_slots(osb);
48477
48478 - atomic_set(&osb->alloc_stats.moves, 0);
48479 - atomic_set(&osb->alloc_stats.local_data, 0);
48480 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48481 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48482 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48483 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48484 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48485 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48486 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48487 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48488
48489 /* Copy the blockcheck stats from the superblock probe */
48490 osb->osb_ecc_stats = *stats;
48491 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
48492 index 5d22872..523db20 100644
48493 --- a/fs/ocfs2/symlink.c
48494 +++ b/fs/ocfs2/symlink.c
48495 @@ -142,7 +142,7 @@ bail:
48496
48497 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
48498 {
48499 - char *link = nd_get_link(nd);
48500 + const char *link = nd_get_link(nd);
48501 if (!IS_ERR(link))
48502 kfree(link);
48503 }
48504 diff --git a/fs/open.c b/fs/open.c
48505 index 77becc0..aad7bd9 100644
48506 --- a/fs/open.c
48507 +++ b/fs/open.c
48508 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48509 error = locks_verify_truncate(inode, NULL, length);
48510 if (!error)
48511 error = security_path_truncate(&path);
48512 +
48513 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48514 + error = -EACCES;
48515 +
48516 if (!error)
48517 error = do_truncate(path.dentry, length, 0, NULL);
48518
48519 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48520 if (__mnt_is_readonly(path.mnt))
48521 res = -EROFS;
48522
48523 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48524 + res = -EACCES;
48525 +
48526 out_path_release:
48527 path_put(&path);
48528 out:
48529 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48530 if (error)
48531 goto dput_and_out;
48532
48533 + gr_log_chdir(path.dentry, path.mnt);
48534 +
48535 set_fs_pwd(current->fs, &path);
48536
48537 dput_and_out:
48538 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48539 goto out_putf;
48540
48541 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48542 +
48543 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48544 + error = -EPERM;
48545 +
48546 + if (!error)
48547 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48548 +
48549 if (!error)
48550 set_fs_pwd(current->fs, &file->f_path);
48551 out_putf:
48552 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48553 if (error)
48554 goto dput_and_out;
48555
48556 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48557 + goto dput_and_out;
48558 +
48559 set_fs_root(current->fs, &path);
48560 +
48561 + gr_handle_chroot_chdir(&path);
48562 +
48563 error = 0;
48564 dput_and_out:
48565 path_put(&path);
48566 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
48567 if (error)
48568 return error;
48569 mutex_lock(&inode->i_mutex);
48570 +
48571 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48572 + error = -EACCES;
48573 + goto out_unlock;
48574 + }
48575 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48576 + error = -EACCES;
48577 + goto out_unlock;
48578 + }
48579 +
48580 error = security_path_chmod(path, mode);
48581 if (error)
48582 goto out_unlock;
48583 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48584 int error;
48585 struct iattr newattrs;
48586
48587 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48588 + return -EACCES;
48589 +
48590 newattrs.ia_valid = ATTR_CTIME;
48591 if (user != (uid_t) -1) {
48592 newattrs.ia_valid |= ATTR_UID;
48593 diff --git a/fs/pipe.c b/fs/pipe.c
48594 index 82e651b..8a68573 100644
48595 --- a/fs/pipe.c
48596 +++ b/fs/pipe.c
48597 @@ -437,9 +437,9 @@ redo:
48598 }
48599 if (bufs) /* More to do? */
48600 continue;
48601 - if (!pipe->writers)
48602 + if (!atomic_read(&pipe->writers))
48603 break;
48604 - if (!pipe->waiting_writers) {
48605 + if (!atomic_read(&pipe->waiting_writers)) {
48606 /* syscall merging: Usually we must not sleep
48607 * if O_NONBLOCK is set, or if we got some data.
48608 * But if a writer sleeps in kernel space, then
48609 @@ -503,7 +503,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48610 mutex_lock(&inode->i_mutex);
48611 pipe = inode->i_pipe;
48612
48613 - if (!pipe->readers) {
48614 + if (!atomic_read(&pipe->readers)) {
48615 send_sig(SIGPIPE, current, 0);
48616 ret = -EPIPE;
48617 goto out;
48618 @@ -552,7 +552,7 @@ redo1:
48619 for (;;) {
48620 int bufs;
48621
48622 - if (!pipe->readers) {
48623 + if (!atomic_read(&pipe->readers)) {
48624 send_sig(SIGPIPE, current, 0);
48625 if (!ret)
48626 ret = -EPIPE;
48627 @@ -643,9 +643,9 @@ redo2:
48628 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48629 do_wakeup = 0;
48630 }
48631 - pipe->waiting_writers++;
48632 + atomic_inc(&pipe->waiting_writers);
48633 pipe_wait(pipe);
48634 - pipe->waiting_writers--;
48635 + atomic_dec(&pipe->waiting_writers);
48636 }
48637 out:
48638 mutex_unlock(&inode->i_mutex);
48639 @@ -712,7 +712,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48640 mask = 0;
48641 if (filp->f_mode & FMODE_READ) {
48642 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48643 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48644 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48645 mask |= POLLHUP;
48646 }
48647
48648 @@ -722,7 +722,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48649 * Most Unices do not set POLLERR for FIFOs but on Linux they
48650 * behave exactly like pipes for poll().
48651 */
48652 - if (!pipe->readers)
48653 + if (!atomic_read(&pipe->readers))
48654 mask |= POLLERR;
48655 }
48656
48657 @@ -736,10 +736,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48658
48659 mutex_lock(&inode->i_mutex);
48660 pipe = inode->i_pipe;
48661 - pipe->readers -= decr;
48662 - pipe->writers -= decw;
48663 + atomic_sub(decr, &pipe->readers);
48664 + atomic_sub(decw, &pipe->writers);
48665
48666 - if (!pipe->readers && !pipe->writers) {
48667 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48668 free_pipe_info(inode);
48669 } else {
48670 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48671 @@ -829,7 +829,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48672
48673 if (inode->i_pipe) {
48674 ret = 0;
48675 - inode->i_pipe->readers++;
48676 + atomic_inc(&inode->i_pipe->readers);
48677 }
48678
48679 mutex_unlock(&inode->i_mutex);
48680 @@ -846,7 +846,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48681
48682 if (inode->i_pipe) {
48683 ret = 0;
48684 - inode->i_pipe->writers++;
48685 + atomic_inc(&inode->i_pipe->writers);
48686 }
48687
48688 mutex_unlock(&inode->i_mutex);
48689 @@ -864,9 +864,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48690 if (inode->i_pipe) {
48691 ret = 0;
48692 if (filp->f_mode & FMODE_READ)
48693 - inode->i_pipe->readers++;
48694 + atomic_inc(&inode->i_pipe->readers);
48695 if (filp->f_mode & FMODE_WRITE)
48696 - inode->i_pipe->writers++;
48697 + atomic_inc(&inode->i_pipe->writers);
48698 }
48699
48700 mutex_unlock(&inode->i_mutex);
48701 @@ -958,7 +958,7 @@ void free_pipe_info(struct inode *inode)
48702 inode->i_pipe = NULL;
48703 }
48704
48705 -static struct vfsmount *pipe_mnt __read_mostly;
48706 +struct vfsmount *pipe_mnt __read_mostly;
48707
48708 /*
48709 * pipefs_dname() is called from d_path().
48710 @@ -988,7 +988,8 @@ static struct inode * get_pipe_inode(void)
48711 goto fail_iput;
48712 inode->i_pipe = pipe;
48713
48714 - pipe->readers = pipe->writers = 1;
48715 + atomic_set(&pipe->readers, 1);
48716 + atomic_set(&pipe->writers, 1);
48717 inode->i_fop = &rdwr_pipefifo_fops;
48718
48719 /*
48720 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48721 index 15af622..0e9f4467 100644
48722 --- a/fs/proc/Kconfig
48723 +++ b/fs/proc/Kconfig
48724 @@ -30,12 +30,12 @@ config PROC_FS
48725
48726 config PROC_KCORE
48727 bool "/proc/kcore support" if !ARM
48728 - depends on PROC_FS && MMU
48729 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48730
48731 config PROC_VMCORE
48732 bool "/proc/vmcore support"
48733 - depends on PROC_FS && CRASH_DUMP
48734 - default y
48735 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48736 + default n
48737 help
48738 Exports the dump image of crashed kernel in ELF format.
48739
48740 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48741 limited in memory.
48742
48743 config PROC_PAGE_MONITOR
48744 - default y
48745 - depends on PROC_FS && MMU
48746 + default n
48747 + depends on PROC_FS && MMU && !GRKERNSEC
48748 bool "Enable /proc page monitoring" if EXPERT
48749 help
48750 Various /proc files exist to monitor process memory utilization:
48751 diff --git a/fs/proc/array.c b/fs/proc/array.c
48752 index c602b8d..a7de642 100644
48753 --- a/fs/proc/array.c
48754 +++ b/fs/proc/array.c
48755 @@ -60,6 +60,7 @@
48756 #include <linux/tty.h>
48757 #include <linux/string.h>
48758 #include <linux/mman.h>
48759 +#include <linux/grsecurity.h>
48760 #include <linux/proc_fs.h>
48761 #include <linux/ioport.h>
48762 #include <linux/uaccess.h>
48763 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48764 seq_putc(m, '\n');
48765 }
48766
48767 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48768 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48769 +{
48770 + if (p->mm)
48771 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48772 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48773 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48774 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48775 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48776 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48777 + else
48778 + seq_printf(m, "PaX:\t-----\n");
48779 +}
48780 +#endif
48781 +
48782 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48783 struct pid *pid, struct task_struct *task)
48784 {
48785 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48786 task_cpus_allowed(m, task);
48787 cpuset_task_status_allowed(m, task);
48788 task_context_switch_counts(m, task);
48789 +
48790 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48791 + task_pax(m, task);
48792 +#endif
48793 +
48794 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48795 + task_grsec_rbac(m, task);
48796 +#endif
48797 +
48798 return 0;
48799 }
48800
48801 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48802 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48803 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48804 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48805 +#endif
48806 +
48807 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48808 struct pid *pid, struct task_struct *task, int whole)
48809 {
48810 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48811 char tcomm[sizeof(task->comm)];
48812 unsigned long flags;
48813
48814 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48815 + if (current->exec_id != m->exec_id) {
48816 + gr_log_badprocpid("stat");
48817 + return 0;
48818 + }
48819 +#endif
48820 +
48821 state = *get_task_state(task);
48822 vsize = eip = esp = 0;
48823 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48824 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48825 gtime = task->gtime;
48826 }
48827
48828 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48829 + if (PAX_RAND_FLAGS(mm)) {
48830 + eip = 0;
48831 + esp = 0;
48832 + wchan = 0;
48833 + }
48834 +#endif
48835 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48836 + wchan = 0;
48837 + eip =0;
48838 + esp =0;
48839 +#endif
48840 +
48841 /* scale priority and nice values from timeslices to -20..20 */
48842 /* to make it look like a "normal" Unix priority/nice value */
48843 priority = task_prio(task);
48844 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48845 vsize,
48846 mm ? get_mm_rss(mm) : 0,
48847 rsslim,
48848 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48849 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
48850 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
48851 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
48852 +#else
48853 mm ? (permitted ? mm->start_code : 1) : 0,
48854 mm ? (permitted ? mm->end_code : 1) : 0,
48855 (permitted && mm) ? mm->start_stack : 0,
48856 +#endif
48857 esp,
48858 eip,
48859 /* The signal information here is obsolete.
48860 @@ -536,8 +593,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48861 struct pid *pid, struct task_struct *task)
48862 {
48863 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48864 - struct mm_struct *mm = get_task_mm(task);
48865 + struct mm_struct *mm;
48866
48867 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48868 + if (current->exec_id != m->exec_id) {
48869 + gr_log_badprocpid("statm");
48870 + return 0;
48871 + }
48872 +#endif
48873 + mm = get_task_mm(task);
48874 if (mm) {
48875 size = task_statm(mm, &shared, &text, &data, &resident);
48876 mmput(mm);
48877 @@ -547,3 +611,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48878
48879 return 0;
48880 }
48881 +
48882 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48883 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48884 +{
48885 + u32 curr_ip = 0;
48886 + unsigned long flags;
48887 +
48888 + if (lock_task_sighand(task, &flags)) {
48889 + curr_ip = task->signal->curr_ip;
48890 + unlock_task_sighand(task, &flags);
48891 + }
48892 +
48893 + return sprintf(buffer, "%pI4\n", &curr_ip);
48894 +}
48895 +#endif
48896 diff --git a/fs/proc/base.c b/fs/proc/base.c
48897 index d4548dd..d101f84 100644
48898 --- a/fs/proc/base.c
48899 +++ b/fs/proc/base.c
48900 @@ -109,6 +109,14 @@ struct pid_entry {
48901 union proc_op op;
48902 };
48903
48904 +struct getdents_callback {
48905 + struct linux_dirent __user * current_dir;
48906 + struct linux_dirent __user * previous;
48907 + struct file * file;
48908 + int count;
48909 + int error;
48910 +};
48911 +
48912 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48913 .name = (NAME), \
48914 .len = sizeof(NAME) - 1, \
48915 @@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48916 if (!mm->arg_end)
48917 goto out_mm; /* Shh! No looking before we're done */
48918
48919 + if (gr_acl_handle_procpidmem(task))
48920 + goto out_mm;
48921 +
48922 len = mm->arg_end - mm->arg_start;
48923
48924 if (len > PAGE_SIZE)
48925 @@ -240,12 +251,28 @@ out:
48926 return res;
48927 }
48928
48929 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48930 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48931 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48932 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48933 +#endif
48934 +
48935 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48936 {
48937 struct mm_struct *mm = mm_for_maps(task);
48938 int res = PTR_ERR(mm);
48939 if (mm && !IS_ERR(mm)) {
48940 unsigned int nwords = 0;
48941 +
48942 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48943 + /* allow if we're currently ptracing this task */
48944 + if (PAX_RAND_FLAGS(mm) &&
48945 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48946 + mmput(mm);
48947 + return 0;
48948 + }
48949 +#endif
48950 +
48951 do {
48952 nwords += 2;
48953 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48954 @@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48955 }
48956
48957
48958 -#ifdef CONFIG_KALLSYMS
48959 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48960 /*
48961 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48962 * Returns the resolved symbol. If that fails, simply return the address.
48963 @@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
48964 mutex_unlock(&task->signal->cred_guard_mutex);
48965 }
48966
48967 -#ifdef CONFIG_STACKTRACE
48968 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48969
48970 #define MAX_STACK_TRACE_DEPTH 64
48971
48972 @@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48973 return count;
48974 }
48975
48976 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48977 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48978 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48979 {
48980 long nr;
48981 @@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48982 /************************************************************************/
48983
48984 /* permission checks */
48985 -static int proc_fd_access_allowed(struct inode *inode)
48986 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48987 {
48988 struct task_struct *task;
48989 int allowed = 0;
48990 @@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48991 */
48992 task = get_proc_task(inode);
48993 if (task) {
48994 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48995 + if (log)
48996 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48997 + else
48998 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48999 put_task_struct(task);
49000 }
49001 return allowed;
49002 @@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49003 struct task_struct *task,
49004 int hide_pid_min)
49005 {
49006 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49007 + return false;
49008 +
49009 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49010 + rcu_read_lock();
49011 + {
49012 + const struct cred *tmpcred = current_cred();
49013 + const struct cred *cred = __task_cred(task);
49014 +
49015 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49016 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49017 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
49018 +#endif
49019 + ) {
49020 + rcu_read_unlock();
49021 + return true;
49022 + }
49023 + }
49024 + rcu_read_unlock();
49025 +
49026 + if (!pid->hide_pid)
49027 + return false;
49028 +#endif
49029 +
49030 if (pid->hide_pid < hide_pid_min)
49031 return true;
49032 if (in_group_p(pid->pid_gid))
49033 return true;
49034 +
49035 return ptrace_may_access(task, PTRACE_MODE_READ);
49036 }
49037
49038 @@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49039 put_task_struct(task);
49040
49041 if (!has_perms) {
49042 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49043 + {
49044 +#else
49045 if (pid->hide_pid == 2) {
49046 +#endif
49047 /*
49048 * Let's make getdents(), stat(), and open()
49049 * consistent with each other. If a process
49050 @@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
49051 file->f_mode |= FMODE_UNSIGNED_OFFSET;
49052 file->private_data = mm;
49053
49054 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49055 + file->f_version = current->exec_id;
49056 +#endif
49057 +
49058 return 0;
49059 }
49060
49061 @@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49062 ssize_t copied;
49063 char *page;
49064
49065 +#ifdef CONFIG_GRKERNSEC
49066 + if (write)
49067 + return -EPERM;
49068 +#endif
49069 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49070 + if (file->f_version != current->exec_id) {
49071 + gr_log_badprocpid("mem");
49072 + return 0;
49073 + }
49074 +#endif
49075 +
49076 if (!mm)
49077 return 0;
49078
49079 @@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49080 if (!task)
49081 goto out_no_task;
49082
49083 + if (gr_acl_handle_procpidmem(task))
49084 + goto out;
49085 +
49086 ret = -ENOMEM;
49087 page = (char *)__get_free_page(GFP_TEMPORARY);
49088 if (!page)
49089 @@ -1434,7 +1511,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49090 path_put(&nd->path);
49091
49092 /* Are we allowed to snoop on the tasks file descriptors? */
49093 - if (!proc_fd_access_allowed(inode))
49094 + if (!proc_fd_access_allowed(inode, 0))
49095 goto out;
49096
49097 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
49098 @@ -1473,8 +1550,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49099 struct path path;
49100
49101 /* Are we allowed to snoop on the tasks file descriptors? */
49102 - if (!proc_fd_access_allowed(inode))
49103 - goto out;
49104 + /* logging this is needed for learning on chromium to work properly,
49105 + but we don't want to flood the logs from 'ps' which does a readlink
49106 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49107 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49108 + */
49109 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49110 + if (!proc_fd_access_allowed(inode,0))
49111 + goto out;
49112 + } else {
49113 + if (!proc_fd_access_allowed(inode,1))
49114 + goto out;
49115 + }
49116
49117 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49118 if (error)
49119 @@ -1539,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49120 rcu_read_lock();
49121 cred = __task_cred(task);
49122 inode->i_uid = cred->euid;
49123 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49124 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49125 +#else
49126 inode->i_gid = cred->egid;
49127 +#endif
49128 rcu_read_unlock();
49129 }
49130 security_task_to_inode(task, inode);
49131 @@ -1575,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49132 return -ENOENT;
49133 }
49134 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49135 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49136 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49137 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49138 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49139 +#endif
49140 task_dumpable(task)) {
49141 cred = __task_cred(task);
49142 stat->uid = cred->euid;
49143 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49144 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
49145 +#else
49146 stat->gid = cred->egid;
49147 +#endif
49148 }
49149 }
49150 rcu_read_unlock();
49151 @@ -1616,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
49152
49153 if (task) {
49154 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49155 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49156 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49157 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49158 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49159 +#endif
49160 task_dumpable(task)) {
49161 rcu_read_lock();
49162 cred = __task_cred(task);
49163 inode->i_uid = cred->euid;
49164 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49165 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49166 +#else
49167 inode->i_gid = cred->egid;
49168 +#endif
49169 rcu_read_unlock();
49170 } else {
49171 inode->i_uid = 0;
49172 @@ -1738,7 +1847,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49173 int fd = proc_fd(inode);
49174
49175 if (task) {
49176 - files = get_files_struct(task);
49177 + if (!gr_acl_handle_procpidmem(task))
49178 + files = get_files_struct(task);
49179 put_task_struct(task);
49180 }
49181 if (files) {
49182 @@ -2355,11 +2465,21 @@ static const struct file_operations proc_map_files_operations = {
49183 */
49184 static int proc_fd_permission(struct inode *inode, int mask)
49185 {
49186 + struct task_struct *task;
49187 int rv = generic_permission(inode, mask);
49188 - if (rv == 0)
49189 - return 0;
49190 +
49191 if (task_pid(current) == proc_pid(inode))
49192 rv = 0;
49193 +
49194 + task = get_proc_task(inode);
49195 + if (task == NULL)
49196 + return rv;
49197 +
49198 + if (gr_acl_handle_procpidmem(task))
49199 + rv = -EACCES;
49200 +
49201 + put_task_struct(task);
49202 +
49203 return rv;
49204 }
49205
49206 @@ -2469,6 +2589,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49207 if (!task)
49208 goto out_no_task;
49209
49210 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49211 + goto out;
49212 +
49213 /*
49214 * Yes, it does not scale. And it should not. Don't add
49215 * new entries into /proc/<tgid>/ without very good reasons.
49216 @@ -2513,6 +2636,9 @@ static int proc_pident_readdir(struct file *filp,
49217 if (!task)
49218 goto out_no_task;
49219
49220 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49221 + goto out;
49222 +
49223 ret = 0;
49224 i = filp->f_pos;
49225 switch (i) {
49226 @@ -2783,7 +2909,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49227 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49228 void *cookie)
49229 {
49230 - char *s = nd_get_link(nd);
49231 + const char *s = nd_get_link(nd);
49232 if (!IS_ERR(s))
49233 __putname(s);
49234 }
49235 @@ -2984,7 +3110,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49236 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49237 #endif
49238 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49239 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49240 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49241 INF("syscall", S_IRUGO, proc_pid_syscall),
49242 #endif
49243 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49244 @@ -3009,10 +3135,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49245 #ifdef CONFIG_SECURITY
49246 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49247 #endif
49248 -#ifdef CONFIG_KALLSYMS
49249 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49250 INF("wchan", S_IRUGO, proc_pid_wchan),
49251 #endif
49252 -#ifdef CONFIG_STACKTRACE
49253 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49254 ONE("stack", S_IRUGO, proc_pid_stack),
49255 #endif
49256 #ifdef CONFIG_SCHEDSTATS
49257 @@ -3046,6 +3172,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49258 #ifdef CONFIG_HARDWALL
49259 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49260 #endif
49261 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49262 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49263 +#endif
49264 };
49265
49266 static int proc_tgid_base_readdir(struct file * filp,
49267 @@ -3172,7 +3301,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49268 if (!inode)
49269 goto out;
49270
49271 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49272 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49273 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49274 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49275 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49276 +#else
49277 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49278 +#endif
49279 inode->i_op = &proc_tgid_base_inode_operations;
49280 inode->i_fop = &proc_tgid_base_operations;
49281 inode->i_flags|=S_IMMUTABLE;
49282 @@ -3214,7 +3350,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
49283 if (!task)
49284 goto out;
49285
49286 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49287 + goto out_put_task;
49288 +
49289 result = proc_pid_instantiate(dir, dentry, task, NULL);
49290 +out_put_task:
49291 put_task_struct(task);
49292 out:
49293 return result;
49294 @@ -3277,6 +3417,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49295 static int fake_filldir(void *buf, const char *name, int namelen,
49296 loff_t offset, u64 ino, unsigned d_type)
49297 {
49298 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49299 + __buf->error = -EINVAL;
49300 return 0;
49301 }
49302
49303 @@ -3343,7 +3485,7 @@ static const struct pid_entry tid_base_stuff[] = {
49304 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49305 #endif
49306 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49307 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49308 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49309 INF("syscall", S_IRUGO, proc_pid_syscall),
49310 #endif
49311 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49312 @@ -3367,10 +3509,10 @@ static const struct pid_entry tid_base_stuff[] = {
49313 #ifdef CONFIG_SECURITY
49314 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49315 #endif
49316 -#ifdef CONFIG_KALLSYMS
49317 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49318 INF("wchan", S_IRUGO, proc_pid_wchan),
49319 #endif
49320 -#ifdef CONFIG_STACKTRACE
49321 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49322 ONE("stack", S_IRUGO, proc_pid_stack),
49323 #endif
49324 #ifdef CONFIG_SCHEDSTATS
49325 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49326 index 82676e3..5f8518a 100644
49327 --- a/fs/proc/cmdline.c
49328 +++ b/fs/proc/cmdline.c
49329 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49330
49331 static int __init proc_cmdline_init(void)
49332 {
49333 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49334 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49335 +#else
49336 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49337 +#endif
49338 return 0;
49339 }
49340 module_init(proc_cmdline_init);
49341 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49342 index b143471..bb105e5 100644
49343 --- a/fs/proc/devices.c
49344 +++ b/fs/proc/devices.c
49345 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49346
49347 static int __init proc_devices_init(void)
49348 {
49349 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49350 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49351 +#else
49352 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49353 +#endif
49354 return 0;
49355 }
49356 module_init(proc_devices_init);
49357 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49358 index 84fd323..f698a32 100644
49359 --- a/fs/proc/inode.c
49360 +++ b/fs/proc/inode.c
49361 @@ -21,12 +21,18 @@
49362 #include <linux/seq_file.h>
49363 #include <linux/slab.h>
49364 #include <linux/mount.h>
49365 +#include <linux/grsecurity.h>
49366
49367 #include <asm/system.h>
49368 #include <asm/uaccess.h>
49369
49370 #include "internal.h"
49371
49372 +#ifdef CONFIG_PROC_SYSCTL
49373 +extern const struct inode_operations proc_sys_inode_operations;
49374 +extern const struct inode_operations proc_sys_dir_operations;
49375 +#endif
49376 +
49377 static void proc_evict_inode(struct inode *inode)
49378 {
49379 struct proc_dir_entry *de;
49380 @@ -52,6 +58,13 @@ static void proc_evict_inode(struct inode *inode)
49381 ns_ops = PROC_I(inode)->ns_ops;
49382 if (ns_ops && ns_ops->put)
49383 ns_ops->put(PROC_I(inode)->ns);
49384 +
49385 +#ifdef CONFIG_PROC_SYSCTL
49386 + if (inode->i_op == &proc_sys_inode_operations ||
49387 + inode->i_op == &proc_sys_dir_operations)
49388 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49389 +#endif
49390 +
49391 }
49392
49393 static struct kmem_cache * proc_inode_cachep;
49394 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49395 if (de->mode) {
49396 inode->i_mode = de->mode;
49397 inode->i_uid = de->uid;
49398 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49399 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49400 +#else
49401 inode->i_gid = de->gid;
49402 +#endif
49403 }
49404 if (de->size)
49405 inode->i_size = de->size;
49406 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49407 index 2925775..4f08fae 100644
49408 --- a/fs/proc/internal.h
49409 +++ b/fs/proc/internal.h
49410 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49411 struct pid *pid, struct task_struct *task);
49412 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49413 struct pid *pid, struct task_struct *task);
49414 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49415 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49416 +#endif
49417 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49418
49419 extern const struct file_operations proc_maps_operations;
49420 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49421 index d245cb2..f4e8498 100644
49422 --- a/fs/proc/kcore.c
49423 +++ b/fs/proc/kcore.c
49424 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49425 * the addresses in the elf_phdr on our list.
49426 */
49427 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49428 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49429 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49430 + if (tsz > buflen)
49431 tsz = buflen;
49432 -
49433 +
49434 while (buflen) {
49435 struct kcore_list *m;
49436
49437 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49438 kfree(elf_buf);
49439 } else {
49440 if (kern_addr_valid(start)) {
49441 - unsigned long n;
49442 + char *elf_buf;
49443 + mm_segment_t oldfs;
49444
49445 - n = copy_to_user(buffer, (char *)start, tsz);
49446 - /*
49447 - * We cannot distingush between fault on source
49448 - * and fault on destination. When this happens
49449 - * we clear too and hope it will trigger the
49450 - * EFAULT again.
49451 - */
49452 - if (n) {
49453 - if (clear_user(buffer + tsz - n,
49454 - n))
49455 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49456 + if (!elf_buf)
49457 + return -ENOMEM;
49458 + oldfs = get_fs();
49459 + set_fs(KERNEL_DS);
49460 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49461 + set_fs(oldfs);
49462 + if (copy_to_user(buffer, elf_buf, tsz)) {
49463 + kfree(elf_buf);
49464 return -EFAULT;
49465 + }
49466 }
49467 + set_fs(oldfs);
49468 + kfree(elf_buf);
49469 } else {
49470 if (clear_user(buffer, tsz))
49471 return -EFAULT;
49472 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49473
49474 static int open_kcore(struct inode *inode, struct file *filp)
49475 {
49476 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49477 + return -EPERM;
49478 +#endif
49479 if (!capable(CAP_SYS_RAWIO))
49480 return -EPERM;
49481 if (kcore_need_update)
49482 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49483 index 80e4645..53e5fcf 100644
49484 --- a/fs/proc/meminfo.c
49485 +++ b/fs/proc/meminfo.c
49486 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49487 vmi.used >> 10,
49488 vmi.largest_chunk >> 10
49489 #ifdef CONFIG_MEMORY_FAILURE
49490 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49491 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49492 #endif
49493 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49494 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49495 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49496 index b1822dd..df622cb 100644
49497 --- a/fs/proc/nommu.c
49498 +++ b/fs/proc/nommu.c
49499 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49500 if (len < 1)
49501 len = 1;
49502 seq_printf(m, "%*c", len, ' ');
49503 - seq_path(m, &file->f_path, "");
49504 + seq_path(m, &file->f_path, "\n\\");
49505 }
49506
49507 seq_putc(m, '\n');
49508 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49509 index 06e1cc1..177cd98 100644
49510 --- a/fs/proc/proc_net.c
49511 +++ b/fs/proc/proc_net.c
49512 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49513 struct task_struct *task;
49514 struct nsproxy *ns;
49515 struct net *net = NULL;
49516 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49517 + const struct cred *cred = current_cred();
49518 +#endif
49519 +
49520 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49521 + if (cred->fsuid)
49522 + return net;
49523 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49524 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
49525 + return net;
49526 +#endif
49527
49528 rcu_read_lock();
49529 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49530 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49531 index 53c3bce..10ad159 100644
49532 --- a/fs/proc/proc_sysctl.c
49533 +++ b/fs/proc/proc_sysctl.c
49534 @@ -9,11 +9,13 @@
49535 #include <linux/namei.h>
49536 #include "internal.h"
49537
49538 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
49539 +
49540 static const struct dentry_operations proc_sys_dentry_operations;
49541 static const struct file_operations proc_sys_file_operations;
49542 -static const struct inode_operations proc_sys_inode_operations;
49543 +const struct inode_operations proc_sys_inode_operations;
49544 static const struct file_operations proc_sys_dir_file_operations;
49545 -static const struct inode_operations proc_sys_dir_operations;
49546 +const struct inode_operations proc_sys_dir_operations;
49547
49548 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49549 {
49550 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49551
49552 err = NULL;
49553 d_set_d_op(dentry, &proc_sys_dentry_operations);
49554 +
49555 + gr_handle_proc_create(dentry, inode);
49556 +
49557 d_add(dentry, inode);
49558
49559 + if (gr_handle_sysctl(p, MAY_EXEC))
49560 + err = ERR_PTR(-ENOENT);
49561 +
49562 out:
49563 sysctl_head_finish(head);
49564 return err;
49565 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49566 if (!table->proc_handler)
49567 goto out;
49568
49569 +#ifdef CONFIG_GRKERNSEC
49570 + error = -EPERM;
49571 + if (write && !capable(CAP_SYS_ADMIN))
49572 + goto out;
49573 +#endif
49574 +
49575 /* careful: calling conventions are nasty here */
49576 res = count;
49577 error = table->proc_handler(table, write, buf, &res, ppos);
49578 @@ -260,6 +274,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49579 return -ENOMEM;
49580 } else {
49581 d_set_d_op(child, &proc_sys_dentry_operations);
49582 +
49583 + gr_handle_proc_create(child, inode);
49584 +
49585 d_add(child, inode);
49586 }
49587 } else {
49588 @@ -288,6 +305,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49589 if (*pos < file->f_pos)
49590 continue;
49591
49592 + if (gr_handle_sysctl(table, 0))
49593 + continue;
49594 +
49595 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
49596 if (res)
49597 return res;
49598 @@ -413,6 +433,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49599 if (IS_ERR(head))
49600 return PTR_ERR(head);
49601
49602 + if (table && gr_handle_sysctl(table, MAY_EXEC))
49603 + return -ENOENT;
49604 +
49605 generic_fillattr(inode, stat);
49606 if (table)
49607 stat->mode = (stat->mode & S_IFMT) | table->mode;
49608 @@ -435,13 +458,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49609 .llseek = generic_file_llseek,
49610 };
49611
49612 -static const struct inode_operations proc_sys_inode_operations = {
49613 +const struct inode_operations proc_sys_inode_operations = {
49614 .permission = proc_sys_permission,
49615 .setattr = proc_sys_setattr,
49616 .getattr = proc_sys_getattr,
49617 };
49618
49619 -static const struct inode_operations proc_sys_dir_operations = {
49620 +const struct inode_operations proc_sys_dir_operations = {
49621 .lookup = proc_sys_lookup,
49622 .permission = proc_sys_permission,
49623 .setattr = proc_sys_setattr,
49624 diff --git a/fs/proc/root.c b/fs/proc/root.c
49625 index 46a15d8..335631a 100644
49626 --- a/fs/proc/root.c
49627 +++ b/fs/proc/root.c
49628 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49629 #ifdef CONFIG_PROC_DEVICETREE
49630 proc_device_tree_init();
49631 #endif
49632 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49633 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49634 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49635 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49636 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49637 +#endif
49638 +#else
49639 proc_mkdir("bus", NULL);
49640 +#endif
49641 proc_sys_init();
49642 }
49643
49644 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49645 index 3efa725..23c925b 100644
49646 --- a/fs/proc/task_mmu.c
49647 +++ b/fs/proc/task_mmu.c
49648 @@ -11,6 +11,7 @@
49649 #include <linux/rmap.h>
49650 #include <linux/swap.h>
49651 #include <linux/swapops.h>
49652 +#include <linux/grsecurity.h>
49653
49654 #include <asm/elf.h>
49655 #include <asm/uaccess.h>
49656 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49657 "VmExe:\t%8lu kB\n"
49658 "VmLib:\t%8lu kB\n"
49659 "VmPTE:\t%8lu kB\n"
49660 - "VmSwap:\t%8lu kB\n",
49661 - hiwater_vm << (PAGE_SHIFT-10),
49662 + "VmSwap:\t%8lu kB\n"
49663 +
49664 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49665 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49666 +#endif
49667 +
49668 + ,hiwater_vm << (PAGE_SHIFT-10),
49669 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49670 mm->locked_vm << (PAGE_SHIFT-10),
49671 mm->pinned_vm << (PAGE_SHIFT-10),
49672 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49673 data << (PAGE_SHIFT-10),
49674 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49675 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49676 - swap << (PAGE_SHIFT-10));
49677 + swap << (PAGE_SHIFT-10)
49678 +
49679 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49680 + , mm->context.user_cs_base, mm->context.user_cs_limit
49681 +#endif
49682 +
49683 + );
49684 }
49685
49686 unsigned long task_vsize(struct mm_struct *mm)
49687 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
49688 return ret;
49689 }
49690
49691 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49692 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49693 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49694 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49695 +#endif
49696 +
49697 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49698 {
49699 struct mm_struct *mm = vma->vm_mm;
49700 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49701 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49702 }
49703
49704 - /* We don't show the stack guard page in /proc/maps */
49705 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49706 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49707 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49708 +#else
49709 start = vma->vm_start;
49710 - if (stack_guard_page_start(vma, start))
49711 - start += PAGE_SIZE;
49712 end = vma->vm_end;
49713 - if (stack_guard_page_end(vma, end))
49714 - end -= PAGE_SIZE;
49715 +#endif
49716
49717 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49718 start,
49719 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49720 flags & VM_WRITE ? 'w' : '-',
49721 flags & VM_EXEC ? 'x' : '-',
49722 flags & VM_MAYSHARE ? 's' : 'p',
49723 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49724 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49725 +#else
49726 pgoff,
49727 +#endif
49728 MAJOR(dev), MINOR(dev), ino, &len);
49729
49730 /*
49731 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49732 */
49733 if (file) {
49734 pad_len_spaces(m, len);
49735 - seq_path(m, &file->f_path, "\n");
49736 + seq_path(m, &file->f_path, "\n\\");
49737 } else {
49738 const char *name = arch_vma_name(vma);
49739 if (!name) {
49740 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
49741 if (vma->vm_start <= mm->brk &&
49742 vma->vm_end >= mm->start_brk) {
49743 name = "[heap]";
49744 - } else if (vma->vm_start <= mm->start_stack &&
49745 - vma->vm_end >= mm->start_stack) {
49746 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49747 + (vma->vm_start <= mm->start_stack &&
49748 + vma->vm_end >= mm->start_stack)) {
49749 name = "[stack]";
49750 }
49751 } else {
49752 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
49753 struct proc_maps_private *priv = m->private;
49754 struct task_struct *task = priv->task;
49755
49756 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49757 + if (current->exec_id != m->exec_id) {
49758 + gr_log_badprocpid("maps");
49759 + return 0;
49760 + }
49761 +#endif
49762 +
49763 show_map_vma(m, vma);
49764
49765 if (m->count < m->size) /* vma is copied successfully */
49766 @@ -437,12 +467,23 @@ static int show_smap(struct seq_file *m, void *v)
49767 .private = &mss,
49768 };
49769
49770 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49771 + if (current->exec_id != m->exec_id) {
49772 + gr_log_badprocpid("smaps");
49773 + return 0;
49774 + }
49775 +#endif
49776 memset(&mss, 0, sizeof mss);
49777 - mss.vma = vma;
49778 - /* mmap_sem is held in m_start */
49779 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49780 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49781 -
49782 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49783 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49784 +#endif
49785 + mss.vma = vma;
49786 + /* mmap_sem is held in m_start */
49787 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49788 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49789 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49790 + }
49791 +#endif
49792 show_map_vma(m, vma);
49793
49794 seq_printf(m,
49795 @@ -460,7 +501,11 @@ static int show_smap(struct seq_file *m, void *v)
49796 "KernelPageSize: %8lu kB\n"
49797 "MMUPageSize: %8lu kB\n"
49798 "Locked: %8lu kB\n",
49799 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49800 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49801 +#else
49802 (vma->vm_end - vma->vm_start) >> 10,
49803 +#endif
49804 mss.resident >> 10,
49805 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49806 mss.shared_clean >> 10,
49807 @@ -1024,6 +1069,13 @@ static int show_numa_map(struct seq_file *m, void *v)
49808 int n;
49809 char buffer[50];
49810
49811 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49812 + if (current->exec_id != m->exec_id) {
49813 + gr_log_badprocpid("numa_maps");
49814 + return 0;
49815 + }
49816 +#endif
49817 +
49818 if (!mm)
49819 return 0;
49820
49821 @@ -1041,11 +1093,15 @@ static int show_numa_map(struct seq_file *m, void *v)
49822 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49823 mpol_cond_put(pol);
49824
49825 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49826 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49827 +#else
49828 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49829 +#endif
49830
49831 if (file) {
49832 seq_printf(m, " file=");
49833 - seq_path(m, &file->f_path, "\n\t= ");
49834 + seq_path(m, &file->f_path, "\n\t\\= ");
49835 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49836 seq_printf(m, " heap");
49837 } else if (vma->vm_start <= mm->start_stack &&
49838 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49839 index 980de54..2a4db5f 100644
49840 --- a/fs/proc/task_nommu.c
49841 +++ b/fs/proc/task_nommu.c
49842 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49843 else
49844 bytes += kobjsize(mm);
49845
49846 - if (current->fs && current->fs->users > 1)
49847 + if (current->fs && atomic_read(&current->fs->users) > 1)
49848 sbytes += kobjsize(current->fs);
49849 else
49850 bytes += kobjsize(current->fs);
49851 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
49852
49853 if (file) {
49854 pad_len_spaces(m, len);
49855 - seq_path(m, &file->f_path, "");
49856 + seq_path(m, &file->f_path, "\n\\");
49857 } else if (mm) {
49858 if (vma->vm_start <= mm->start_stack &&
49859 vma->vm_end >= mm->start_stack) {
49860 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49861 index d67908b..d13f6a6 100644
49862 --- a/fs/quota/netlink.c
49863 +++ b/fs/quota/netlink.c
49864 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49865 void quota_send_warning(short type, unsigned int id, dev_t dev,
49866 const char warntype)
49867 {
49868 - static atomic_t seq;
49869 + static atomic_unchecked_t seq;
49870 struct sk_buff *skb;
49871 void *msg_head;
49872 int ret;
49873 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49874 "VFS: Not enough memory to send quota warning.\n");
49875 return;
49876 }
49877 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49878 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49879 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49880 if (!msg_head) {
49881 printk(KERN_ERR
49882 diff --git a/fs/readdir.c b/fs/readdir.c
49883 index 356f715..c918d38 100644
49884 --- a/fs/readdir.c
49885 +++ b/fs/readdir.c
49886 @@ -17,6 +17,7 @@
49887 #include <linux/security.h>
49888 #include <linux/syscalls.h>
49889 #include <linux/unistd.h>
49890 +#include <linux/namei.h>
49891
49892 #include <asm/uaccess.h>
49893
49894 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49895
49896 struct readdir_callback {
49897 struct old_linux_dirent __user * dirent;
49898 + struct file * file;
49899 int result;
49900 };
49901
49902 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49903 buf->result = -EOVERFLOW;
49904 return -EOVERFLOW;
49905 }
49906 +
49907 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49908 + return 0;
49909 +
49910 buf->result++;
49911 dirent = buf->dirent;
49912 if (!access_ok(VERIFY_WRITE, dirent,
49913 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49914
49915 buf.result = 0;
49916 buf.dirent = dirent;
49917 + buf.file = file;
49918
49919 error = vfs_readdir(file, fillonedir, &buf);
49920 if (buf.result)
49921 @@ -142,6 +149,7 @@ struct linux_dirent {
49922 struct getdents_callback {
49923 struct linux_dirent __user * current_dir;
49924 struct linux_dirent __user * previous;
49925 + struct file * file;
49926 int count;
49927 int error;
49928 };
49929 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49930 buf->error = -EOVERFLOW;
49931 return -EOVERFLOW;
49932 }
49933 +
49934 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49935 + return 0;
49936 +
49937 dirent = buf->previous;
49938 if (dirent) {
49939 if (__put_user(offset, &dirent->d_off))
49940 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49941 buf.previous = NULL;
49942 buf.count = count;
49943 buf.error = 0;
49944 + buf.file = file;
49945
49946 error = vfs_readdir(file, filldir, &buf);
49947 if (error >= 0)
49948 @@ -229,6 +242,7 @@ out:
49949 struct getdents_callback64 {
49950 struct linux_dirent64 __user * current_dir;
49951 struct linux_dirent64 __user * previous;
49952 + struct file *file;
49953 int count;
49954 int error;
49955 };
49956 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49957 buf->error = -EINVAL; /* only used if we fail.. */
49958 if (reclen > buf->count)
49959 return -EINVAL;
49960 +
49961 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49962 + return 0;
49963 +
49964 dirent = buf->previous;
49965 if (dirent) {
49966 if (__put_user(offset, &dirent->d_off))
49967 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49968
49969 buf.current_dir = dirent;
49970 buf.previous = NULL;
49971 + buf.file = file;
49972 buf.count = count;
49973 buf.error = 0;
49974
49975 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49976 error = buf.error;
49977 lastdirent = buf.previous;
49978 if (lastdirent) {
49979 - typeof(lastdirent->d_off) d_off = file->f_pos;
49980 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49981 if (__put_user(d_off, &lastdirent->d_off))
49982 error = -EFAULT;
49983 else
49984 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49985 index 60c0804..d814f98 100644
49986 --- a/fs/reiserfs/do_balan.c
49987 +++ b/fs/reiserfs/do_balan.c
49988 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49989 return;
49990 }
49991
49992 - atomic_inc(&(fs_generation(tb->tb_sb)));
49993 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49994 do_balance_starts(tb);
49995
49996 /* balance leaf returns 0 except if combining L R and S into
49997 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49998 index 7a99811..a7c96c4 100644
49999 --- a/fs/reiserfs/procfs.c
50000 +++ b/fs/reiserfs/procfs.c
50001 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50002 "SMALL_TAILS " : "NO_TAILS ",
50003 replay_only(sb) ? "REPLAY_ONLY " : "",
50004 convert_reiserfs(sb) ? "CONV " : "",
50005 - atomic_read(&r->s_generation_counter),
50006 + atomic_read_unchecked(&r->s_generation_counter),
50007 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50008 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50009 SF(s_good_search_by_key_reada), SF(s_bmaps),
50010 diff --git a/fs/select.c b/fs/select.c
50011 index e782258..3b4b44c 100644
50012 --- a/fs/select.c
50013 +++ b/fs/select.c
50014 @@ -20,6 +20,7 @@
50015 #include <linux/module.h>
50016 #include <linux/slab.h>
50017 #include <linux/poll.h>
50018 +#include <linux/security.h>
50019 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50020 #include <linux/file.h>
50021 #include <linux/fdtable.h>
50022 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50023 struct poll_list *walk = head;
50024 unsigned long todo = nfds;
50025
50026 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50027 if (nfds > rlimit(RLIMIT_NOFILE))
50028 return -EINVAL;
50029
50030 diff --git a/fs/seq_file.c b/fs/seq_file.c
50031 index 4023d6b..ab46c6a 100644
50032 --- a/fs/seq_file.c
50033 +++ b/fs/seq_file.c
50034 @@ -9,6 +9,7 @@
50035 #include <linux/module.h>
50036 #include <linux/seq_file.h>
50037 #include <linux/slab.h>
50038 +#include <linux/sched.h>
50039
50040 #include <asm/uaccess.h>
50041 #include <asm/page.h>
50042 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50043 memset(p, 0, sizeof(*p));
50044 mutex_init(&p->lock);
50045 p->op = op;
50046 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50047 + p->exec_id = current->exec_id;
50048 +#endif
50049
50050 /*
50051 * Wrappers around seq_open(e.g. swaps_open) need to be
50052 @@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
50053 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50054 void *data)
50055 {
50056 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50057 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50058 int res = -ENOMEM;
50059
50060 if (op) {
50061 diff --git a/fs/splice.c b/fs/splice.c
50062 index 96d7b28..fd465ac 100644
50063 --- a/fs/splice.c
50064 +++ b/fs/splice.c
50065 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50066 pipe_lock(pipe);
50067
50068 for (;;) {
50069 - if (!pipe->readers) {
50070 + if (!atomic_read(&pipe->readers)) {
50071 send_sig(SIGPIPE, current, 0);
50072 if (!ret)
50073 ret = -EPIPE;
50074 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50075 do_wakeup = 0;
50076 }
50077
50078 - pipe->waiting_writers++;
50079 + atomic_inc(&pipe->waiting_writers);
50080 pipe_wait(pipe);
50081 - pipe->waiting_writers--;
50082 + atomic_dec(&pipe->waiting_writers);
50083 }
50084
50085 pipe_unlock(pipe);
50086 @@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50087 old_fs = get_fs();
50088 set_fs(get_ds());
50089 /* The cast to a user pointer is valid due to the set_fs() */
50090 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50091 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50092 set_fs(old_fs);
50093
50094 return res;
50095 @@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50096 old_fs = get_fs();
50097 set_fs(get_ds());
50098 /* The cast to a user pointer is valid due to the set_fs() */
50099 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50100 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50101 set_fs(old_fs);
50102
50103 return res;
50104 @@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50105 goto err;
50106
50107 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50108 - vec[i].iov_base = (void __user *) page_address(page);
50109 + vec[i].iov_base = (void __force_user *) page_address(page);
50110 vec[i].iov_len = this_len;
50111 spd.pages[i] = page;
50112 spd.nr_pages++;
50113 @@ -848,10 +848,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50114 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50115 {
50116 while (!pipe->nrbufs) {
50117 - if (!pipe->writers)
50118 + if (!atomic_read(&pipe->writers))
50119 return 0;
50120
50121 - if (!pipe->waiting_writers && sd->num_spliced)
50122 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50123 return 0;
50124
50125 if (sd->flags & SPLICE_F_NONBLOCK)
50126 @@ -1184,7 +1184,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50127 * out of the pipe right after the splice_to_pipe(). So set
50128 * PIPE_READERS appropriately.
50129 */
50130 - pipe->readers = 1;
50131 + atomic_set(&pipe->readers, 1);
50132
50133 current->splice_pipe = pipe;
50134 }
50135 @@ -1736,9 +1736,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50136 ret = -ERESTARTSYS;
50137 break;
50138 }
50139 - if (!pipe->writers)
50140 + if (!atomic_read(&pipe->writers))
50141 break;
50142 - if (!pipe->waiting_writers) {
50143 + if (!atomic_read(&pipe->waiting_writers)) {
50144 if (flags & SPLICE_F_NONBLOCK) {
50145 ret = -EAGAIN;
50146 break;
50147 @@ -1770,7 +1770,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50148 pipe_lock(pipe);
50149
50150 while (pipe->nrbufs >= pipe->buffers) {
50151 - if (!pipe->readers) {
50152 + if (!atomic_read(&pipe->readers)) {
50153 send_sig(SIGPIPE, current, 0);
50154 ret = -EPIPE;
50155 break;
50156 @@ -1783,9 +1783,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50157 ret = -ERESTARTSYS;
50158 break;
50159 }
50160 - pipe->waiting_writers++;
50161 + atomic_inc(&pipe->waiting_writers);
50162 pipe_wait(pipe);
50163 - pipe->waiting_writers--;
50164 + atomic_dec(&pipe->waiting_writers);
50165 }
50166
50167 pipe_unlock(pipe);
50168 @@ -1821,14 +1821,14 @@ retry:
50169 pipe_double_lock(ipipe, opipe);
50170
50171 do {
50172 - if (!opipe->readers) {
50173 + if (!atomic_read(&opipe->readers)) {
50174 send_sig(SIGPIPE, current, 0);
50175 if (!ret)
50176 ret = -EPIPE;
50177 break;
50178 }
50179
50180 - if (!ipipe->nrbufs && !ipipe->writers)
50181 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50182 break;
50183
50184 /*
50185 @@ -1925,7 +1925,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50186 pipe_double_lock(ipipe, opipe);
50187
50188 do {
50189 - if (!opipe->readers) {
50190 + if (!atomic_read(&opipe->readers)) {
50191 send_sig(SIGPIPE, current, 0);
50192 if (!ret)
50193 ret = -EPIPE;
50194 @@ -1970,7 +1970,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50195 * return EAGAIN if we have the potential of some data in the
50196 * future, otherwise just return 0
50197 */
50198 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50199 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50200 ret = -EAGAIN;
50201
50202 pipe_unlock(ipipe);
50203 diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
50204 index a475983..9c6a1f0 100644
50205 --- a/fs/sysfs/bin.c
50206 +++ b/fs/sysfs/bin.c
50207 @@ -67,6 +67,8 @@ fill_read(struct file *file, char *buffer, loff_t off, size_t count)
50208 }
50209
50210 static ssize_t
50211 +read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off) __size_overflow(3);
50212 +static ssize_t
50213 read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
50214 {
50215 struct bin_buffer *bb = file->private_data;
50216 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50217 index 7fdf6a7..e6cd8ad 100644
50218 --- a/fs/sysfs/dir.c
50219 +++ b/fs/sysfs/dir.c
50220 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50221 struct sysfs_dirent *sd;
50222 int rc;
50223
50224 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50225 + const char *parent_name = parent_sd->s_name;
50226 +
50227 + mode = S_IFDIR | S_IRWXU;
50228 +
50229 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50230 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50231 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50232 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50233 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50234 +#endif
50235 +
50236 /* allocate */
50237 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50238 if (!sd)
50239 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50240 index 00012e3..8392349 100644
50241 --- a/fs/sysfs/file.c
50242 +++ b/fs/sysfs/file.c
50243 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50244
50245 struct sysfs_open_dirent {
50246 atomic_t refcnt;
50247 - atomic_t event;
50248 + atomic_unchecked_t event;
50249 wait_queue_head_t poll;
50250 struct list_head buffers; /* goes through sysfs_buffer.list */
50251 };
50252 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50253 if (!sysfs_get_active(attr_sd))
50254 return -ENODEV;
50255
50256 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50257 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50258 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50259
50260 sysfs_put_active(attr_sd);
50261 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50262 return -ENOMEM;
50263
50264 atomic_set(&new_od->refcnt, 0);
50265 - atomic_set(&new_od->event, 1);
50266 + atomic_set_unchecked(&new_od->event, 1);
50267 init_waitqueue_head(&new_od->poll);
50268 INIT_LIST_HEAD(&new_od->buffers);
50269 goto retry;
50270 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50271
50272 sysfs_put_active(attr_sd);
50273
50274 - if (buffer->event != atomic_read(&od->event))
50275 + if (buffer->event != atomic_read_unchecked(&od->event))
50276 goto trigger;
50277
50278 return DEFAULT_POLLMASK;
50279 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50280
50281 od = sd->s_attr.open;
50282 if (od) {
50283 - atomic_inc(&od->event);
50284 + atomic_inc_unchecked(&od->event);
50285 wake_up_interruptible(&od->poll);
50286 }
50287
50288 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50289 index a7ac78f..02158e1 100644
50290 --- a/fs/sysfs/symlink.c
50291 +++ b/fs/sysfs/symlink.c
50292 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50293
50294 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50295 {
50296 - char *page = nd_get_link(nd);
50297 + const char *page = nd_get_link(nd);
50298 if (!IS_ERR(page))
50299 free_page((unsigned long)page);
50300 }
50301 diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
50302 index f922cba..062fb02 100644
50303 --- a/fs/ubifs/debug.c
50304 +++ b/fs/ubifs/debug.c
50305 @@ -2819,6 +2819,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
50306 * debugfs file. Returns %0 or %1 in case of success and a negative error code
50307 * in case of failure.
50308 */
50309 +static int interpret_user_input(const char __user *u, size_t count) __size_overflow(2);
50310 static int interpret_user_input(const char __user *u, size_t count)
50311 {
50312 size_t buf_size;
50313 @@ -2837,6 +2838,8 @@ static int interpret_user_input(const char __user *u, size_t count)
50314 }
50315
50316 static ssize_t dfs_file_write(struct file *file, const char __user *u,
50317 + size_t count, loff_t *ppos) __size_overflow(3);
50318 +static ssize_t dfs_file_write(struct file *file, const char __user *u,
50319 size_t count, loff_t *ppos)
50320 {
50321 struct ubifs_info *c = file->private_data;
50322 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50323 index c175b4d..8f36a16 100644
50324 --- a/fs/udf/misc.c
50325 +++ b/fs/udf/misc.c
50326 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50327
50328 u8 udf_tag_checksum(const struct tag *t)
50329 {
50330 - u8 *data = (u8 *)t;
50331 + const u8 *data = (const u8 *)t;
50332 u8 checksum = 0;
50333 int i;
50334 for (i = 0; i < sizeof(struct tag); ++i)
50335 diff --git a/fs/utimes.c b/fs/utimes.c
50336 index ba653f3..06ea4b1 100644
50337 --- a/fs/utimes.c
50338 +++ b/fs/utimes.c
50339 @@ -1,6 +1,7 @@
50340 #include <linux/compiler.h>
50341 #include <linux/file.h>
50342 #include <linux/fs.h>
50343 +#include <linux/security.h>
50344 #include <linux/linkage.h>
50345 #include <linux/mount.h>
50346 #include <linux/namei.h>
50347 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50348 goto mnt_drop_write_and_out;
50349 }
50350 }
50351 +
50352 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50353 + error = -EACCES;
50354 + goto mnt_drop_write_and_out;
50355 + }
50356 +
50357 mutex_lock(&inode->i_mutex);
50358 error = notify_change(path->dentry, &newattrs);
50359 mutex_unlock(&inode->i_mutex);
50360 diff --git a/fs/xattr.c b/fs/xattr.c
50361 index 82f4337..236473c 100644
50362 --- a/fs/xattr.c
50363 +++ b/fs/xattr.c
50364 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50365 * Extended attribute SET operations
50366 */
50367 static long
50368 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50369 +setxattr(struct path *path, const char __user *name, const void __user *value,
50370 size_t size, int flags)
50371 {
50372 int error;
50373 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50374 return PTR_ERR(kvalue);
50375 }
50376
50377 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50378 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50379 + error = -EACCES;
50380 + goto out;
50381 + }
50382 +
50383 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50384 +out:
50385 kfree(kvalue);
50386 return error;
50387 }
50388 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50389 return error;
50390 error = mnt_want_write(path.mnt);
50391 if (!error) {
50392 - error = setxattr(path.dentry, name, value, size, flags);
50393 + error = setxattr(&path, name, value, size, flags);
50394 mnt_drop_write(path.mnt);
50395 }
50396 path_put(&path);
50397 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50398 return error;
50399 error = mnt_want_write(path.mnt);
50400 if (!error) {
50401 - error = setxattr(path.dentry, name, value, size, flags);
50402 + error = setxattr(&path, name, value, size, flags);
50403 mnt_drop_write(path.mnt);
50404 }
50405 path_put(&path);
50406 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50407 const void __user *,value, size_t, size, int, flags)
50408 {
50409 struct file *f;
50410 - struct dentry *dentry;
50411 int error = -EBADF;
50412
50413 f = fget(fd);
50414 if (!f)
50415 return error;
50416 - dentry = f->f_path.dentry;
50417 - audit_inode(NULL, dentry);
50418 + audit_inode(NULL, f->f_path.dentry);
50419 error = mnt_want_write_file(f);
50420 if (!error) {
50421 - error = setxattr(dentry, name, value, size, flags);
50422 + error = setxattr(&f->f_path, name, value, size, flags);
50423 mnt_drop_write_file(f);
50424 }
50425 fput(f);
50426 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50427 index 8d5a506..7f62712 100644
50428 --- a/fs/xattr_acl.c
50429 +++ b/fs/xattr_acl.c
50430 @@ -17,8 +17,8 @@
50431 struct posix_acl *
50432 posix_acl_from_xattr(const void *value, size_t size)
50433 {
50434 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50435 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50436 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50437 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50438 int count;
50439 struct posix_acl *acl;
50440 struct posix_acl_entry *acl_e;
50441 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50442 index 188ef2f..adcf864 100644
50443 --- a/fs/xfs/xfs_bmap.c
50444 +++ b/fs/xfs/xfs_bmap.c
50445 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
50446 int nmap,
50447 int ret_nmap);
50448 #else
50449 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50450 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50451 #endif /* DEBUG */
50452
50453 STATIC int
50454 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50455 index 79d05e8..e3e5861 100644
50456 --- a/fs/xfs/xfs_dir2_sf.c
50457 +++ b/fs/xfs/xfs_dir2_sf.c
50458 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
50459 }
50460
50461 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50462 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50463 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50464 + char name[sfep->namelen];
50465 + memcpy(name, sfep->name, sfep->namelen);
50466 + if (filldir(dirent, name, sfep->namelen,
50467 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50468 + *offset = off & 0x7fffffff;
50469 + return 0;
50470 + }
50471 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50472 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50473 *offset = off & 0x7fffffff;
50474 return 0;
50475 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50476 index 76f3ca5..f57f712 100644
50477 --- a/fs/xfs/xfs_ioctl.c
50478 +++ b/fs/xfs/xfs_ioctl.c
50479 @@ -128,7 +128,7 @@ xfs_find_handle(
50480 }
50481
50482 error = -EFAULT;
50483 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50484 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50485 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50486 goto out_put;
50487
50488 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50489 index ab30253..4d86958 100644
50490 --- a/fs/xfs/xfs_iops.c
50491 +++ b/fs/xfs/xfs_iops.c
50492 @@ -447,7 +447,7 @@ xfs_vn_put_link(
50493 struct nameidata *nd,
50494 void *p)
50495 {
50496 - char *s = nd_get_link(nd);
50497 + const char *s = nd_get_link(nd);
50498
50499 if (!IS_ERR(s))
50500 kfree(s);
50501 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50502 new file mode 100644
50503 index 0000000..2645296
50504 --- /dev/null
50505 +++ b/grsecurity/Kconfig
50506 @@ -0,0 +1,1079 @@
50507 +#
50508 +# grecurity configuration
50509 +#
50510 +
50511 +menu "Grsecurity"
50512 +
50513 +config GRKERNSEC
50514 + bool "Grsecurity"
50515 + select CRYPTO
50516 + select CRYPTO_SHA256
50517 + help
50518 + If you say Y here, you will be able to configure many features
50519 + that will enhance the security of your system. It is highly
50520 + recommended that you say Y here and read through the help
50521 + for each option so that you fully understand the features and
50522 + can evaluate their usefulness for your machine.
50523 +
50524 +choice
50525 + prompt "Security Level"
50526 + depends on GRKERNSEC
50527 + default GRKERNSEC_CUSTOM
50528 +
50529 +config GRKERNSEC_LOW
50530 + bool "Low"
50531 + select GRKERNSEC_LINK
50532 + select GRKERNSEC_FIFO
50533 + select GRKERNSEC_RANDNET
50534 + select GRKERNSEC_DMESG
50535 + select GRKERNSEC_CHROOT
50536 + select GRKERNSEC_CHROOT_CHDIR
50537 +
50538 + help
50539 + If you choose this option, several of the grsecurity options will
50540 + be enabled that will give you greater protection against a number
50541 + of attacks, while assuring that none of your software will have any
50542 + conflicts with the additional security measures. If you run a lot
50543 + of unusual software, or you are having problems with the higher
50544 + security levels, you should say Y here. With this option, the
50545 + following features are enabled:
50546 +
50547 + - Linking restrictions
50548 + - FIFO restrictions
50549 + - Restricted dmesg
50550 + - Enforced chdir("/") on chroot
50551 + - Runtime module disabling
50552 +
50553 +config GRKERNSEC_MEDIUM
50554 + bool "Medium"
50555 + select PAX
50556 + select PAX_EI_PAX
50557 + select PAX_PT_PAX_FLAGS
50558 + select PAX_HAVE_ACL_FLAGS
50559 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
50560 + select GRKERNSEC_CHROOT
50561 + select GRKERNSEC_CHROOT_SYSCTL
50562 + select GRKERNSEC_LINK
50563 + select GRKERNSEC_FIFO
50564 + select GRKERNSEC_DMESG
50565 + select GRKERNSEC_RANDNET
50566 + select GRKERNSEC_FORKFAIL
50567 + select GRKERNSEC_TIME
50568 + select GRKERNSEC_SIGNAL
50569 + select GRKERNSEC_CHROOT
50570 + select GRKERNSEC_CHROOT_UNIX
50571 + select GRKERNSEC_CHROOT_MOUNT
50572 + select GRKERNSEC_CHROOT_PIVOT
50573 + select GRKERNSEC_CHROOT_DOUBLE
50574 + select GRKERNSEC_CHROOT_CHDIR
50575 + select GRKERNSEC_CHROOT_MKNOD
50576 + select GRKERNSEC_PROC
50577 + select GRKERNSEC_PROC_USERGROUP
50578 + select PAX_RANDUSTACK
50579 + select PAX_ASLR
50580 + select PAX_RANDMMAP
50581 + select PAX_REFCOUNT if (X86 || SPARC64)
50582 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
50583 +
50584 + help
50585 + If you say Y here, several features in addition to those included
50586 + in the low additional security level will be enabled. These
50587 + features provide even more security to your system, though in rare
50588 + cases they may be incompatible with very old or poorly written
50589 + software. If you enable this option, make sure that your auth
50590 + service (identd) is running as gid 1001. With this option,
50591 + the following features (in addition to those provided in the
50592 + low additional security level) will be enabled:
50593 +
50594 + - Failed fork logging
50595 + - Time change logging
50596 + - Signal logging
50597 + - Deny mounts in chroot
50598 + - Deny double chrooting
50599 + - Deny sysctl writes in chroot
50600 + - Deny mknod in chroot
50601 + - Deny access to abstract AF_UNIX sockets out of chroot
50602 + - Deny pivot_root in chroot
50603 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
50604 + - /proc restrictions with special GID set to 10 (usually wheel)
50605 + - Address Space Layout Randomization (ASLR)
50606 + - Prevent exploitation of most refcount overflows
50607 + - Bounds checking of copying between the kernel and userland
50608 +
50609 +config GRKERNSEC_HIGH
50610 + bool "High"
50611 + select GRKERNSEC_LINK
50612 + select GRKERNSEC_FIFO
50613 + select GRKERNSEC_DMESG
50614 + select GRKERNSEC_FORKFAIL
50615 + select GRKERNSEC_TIME
50616 + select GRKERNSEC_SIGNAL
50617 + select GRKERNSEC_CHROOT
50618 + select GRKERNSEC_CHROOT_SHMAT
50619 + select GRKERNSEC_CHROOT_UNIX
50620 + select GRKERNSEC_CHROOT_MOUNT
50621 + select GRKERNSEC_CHROOT_FCHDIR
50622 + select GRKERNSEC_CHROOT_PIVOT
50623 + select GRKERNSEC_CHROOT_DOUBLE
50624 + select GRKERNSEC_CHROOT_CHDIR
50625 + select GRKERNSEC_CHROOT_MKNOD
50626 + select GRKERNSEC_CHROOT_CAPS
50627 + select GRKERNSEC_CHROOT_SYSCTL
50628 + select GRKERNSEC_CHROOT_FINDTASK
50629 + select GRKERNSEC_SYSFS_RESTRICT
50630 + select GRKERNSEC_PROC
50631 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
50632 + select GRKERNSEC_HIDESYM
50633 + select GRKERNSEC_BRUTE
50634 + select GRKERNSEC_PROC_USERGROUP
50635 + select GRKERNSEC_KMEM
50636 + select GRKERNSEC_RESLOG
50637 + select GRKERNSEC_RANDNET
50638 + select GRKERNSEC_PROC_ADD
50639 + select GRKERNSEC_CHROOT_CHMOD
50640 + select GRKERNSEC_CHROOT_NICE
50641 + select GRKERNSEC_SETXID if (X86 || SPARC64 || PPC || ARM || MIPS)
50642 + select GRKERNSEC_AUDIT_MOUNT
50643 + select GRKERNSEC_MODHARDEN if (MODULES)
50644 + select GRKERNSEC_HARDEN_PTRACE
50645 + select GRKERNSEC_PTRACE_READEXEC
50646 + select GRKERNSEC_VM86 if (X86_32)
50647 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
50648 + select PAX
50649 + select PAX_RANDUSTACK
50650 + select PAX_ASLR
50651 + select PAX_RANDMMAP
50652 + select PAX_NOEXEC
50653 + select PAX_MPROTECT
50654 + select PAX_EI_PAX
50655 + select PAX_PT_PAX_FLAGS
50656 + select PAX_HAVE_ACL_FLAGS
50657 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
50658 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
50659 + select PAX_RANDKSTACK if (X86_TSC && X86)
50660 + select PAX_SEGMEXEC if (X86_32)
50661 + select PAX_PAGEEXEC
50662 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
50663 + select PAX_EMUTRAMP if (PARISC)
50664 + select PAX_EMUSIGRT if (PARISC)
50665 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
50666 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
50667 + select PAX_REFCOUNT if (X86 || SPARC64)
50668 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
50669 + help
50670 + If you say Y here, many of the features of grsecurity will be
50671 + enabled, which will protect you against many kinds of attacks
50672 + against your system. The heightened security comes at a cost
50673 + of an increased chance of incompatibilities with rare software
50674 + on your machine. Since this security level enables PaX, you should
50675 + view <http://pax.grsecurity.net> and read about the PaX
50676 + project. While you are there, download chpax and run it on
50677 + binaries that cause problems with PaX. Also remember that
50678 + since the /proc restrictions are enabled, you must run your
50679 + identd as gid 1001. This security level enables the following
50680 + features in addition to those listed in the low and medium
50681 + security levels:
50682 +
50683 + - Additional /proc restrictions
50684 + - Chmod restrictions in chroot
50685 + - No signals, ptrace, or viewing of processes outside of chroot
50686 + - Capability restrictions in chroot
50687 + - Deny fchdir out of chroot
50688 + - Priority restrictions in chroot
50689 + - Segmentation-based implementation of PaX
50690 + - Mprotect restrictions
50691 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
50692 + - Kernel stack randomization
50693 + - Mount/unmount/remount logging
50694 + - Kernel symbol hiding
50695 + - Hardening of module auto-loading
50696 + - Ptrace restrictions
50697 + - Restricted vm86 mode
50698 + - Restricted sysfs/debugfs
50699 + - Active kernel exploit response
50700 +
50701 +config GRKERNSEC_CUSTOM
50702 + bool "Custom"
50703 + help
50704 + If you say Y here, you will be able to configure every grsecurity
50705 + option, which allows you to enable many more features that aren't
50706 + covered in the basic security levels. These additional features
50707 + include TPE, socket restrictions, and the sysctl system for
50708 + grsecurity. It is advised that you read through the help for
50709 + each option to determine its usefulness in your situation.
50710 +
50711 +endchoice
50712 +
50713 +menu "Memory Protections"
50714 +depends on GRKERNSEC
50715 +
50716 +config GRKERNSEC_KMEM
50717 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50718 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50719 + help
50720 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50721 + be written to or read from to modify or leak the contents of the running
50722 + kernel. /dev/port will also not be allowed to be opened. If you have module
50723 + support disabled, enabling this will close up four ways that are
50724 + currently used to insert malicious code into the running kernel.
50725 + Even with all these features enabled, we still highly recommend that
50726 + you use the RBAC system, as it is still possible for an attacker to
50727 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50728 + If you are not using XFree86, you may be able to stop this additional
50729 + case by enabling the 'Disable privileged I/O' option. Though nothing
50730 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50731 + but only to video memory, which is the only writing we allow in this
50732 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50733 + not be allowed to mprotect it with PROT_WRITE later.
50734 + It is highly recommended that you say Y here if you meet all the
50735 + conditions above.
50736 +
50737 +config GRKERNSEC_VM86
50738 + bool "Restrict VM86 mode"
50739 + depends on X86_32
50740 +
50741 + help
50742 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50743 + make use of a special execution mode on 32bit x86 processors called
50744 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50745 + video cards and will still work with this option enabled. The purpose
50746 + of the option is to prevent exploitation of emulation errors in
50747 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50748 + Nearly all users should be able to enable this option.
50749 +
50750 +config GRKERNSEC_IO
50751 + bool "Disable privileged I/O"
50752 + depends on X86
50753 + select RTC_CLASS
50754 + select RTC_INTF_DEV
50755 + select RTC_DRV_CMOS
50756 +
50757 + help
50758 + If you say Y here, all ioperm and iopl calls will return an error.
50759 + Ioperm and iopl can be used to modify the running kernel.
50760 + Unfortunately, some programs need this access to operate properly,
50761 + the most notable of which are XFree86 and hwclock. hwclock can be
50762 + remedied by having RTC support in the kernel, so real-time
50763 + clock support is enabled if this option is enabled, to ensure
50764 + that hwclock operates correctly. XFree86 still will not
50765 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50766 + IF YOU USE XFree86. If you use XFree86 and you still want to
50767 + protect your kernel against modification, use the RBAC system.
50768 +
50769 +config GRKERNSEC_PROC_MEMMAP
50770 + bool "Harden ASLR against information leaks and entropy reduction"
50771 + default y if (PAX_NOEXEC || PAX_ASLR)
50772 + depends on PAX_NOEXEC || PAX_ASLR
50773 + help
50774 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50775 + give no information about the addresses of its mappings if
50776 + PaX features that rely on random addresses are enabled on the task.
50777 + In addition to sanitizing this information and disabling other
50778 + dangerous sources of information, this option causes reads of sensitive
50779 + /proc/<pid> entries where the file descriptor was opened in a different
50780 + task than the one performing the read. Such attempts are logged.
50781 + This option also limits argv/env strings for suid/sgid binaries
50782 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50783 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50784 + binaries to prevent alternative mmap layouts from being abused.
50785 +
50786 + If you use PaX it is essential that you say Y here as it closes up
50787 + several holes that make full ASLR useless locally.
50788 +
50789 +config GRKERNSEC_BRUTE
50790 + bool "Deter exploit bruteforcing"
50791 + help
50792 + If you say Y here, attempts to bruteforce exploits against forking
50793 + daemons such as apache or sshd, as well as against suid/sgid binaries
50794 + will be deterred. When a child of a forking daemon is killed by PaX
50795 + or crashes due to an illegal instruction or other suspicious signal,
50796 + the parent process will be delayed 30 seconds upon every subsequent
50797 + fork until the administrator is able to assess the situation and
50798 + restart the daemon.
50799 + In the suid/sgid case, the attempt is logged, the user has all their
50800 + processes terminated, and they are prevented from executing any further
50801 + processes for 15 minutes.
50802 + It is recommended that you also enable signal logging in the auditing
50803 + section so that logs are generated when a process triggers a suspicious
50804 + signal.
50805 + If the sysctl option is enabled, a sysctl option with name
50806 + "deter_bruteforce" is created.
50807 +
50808 +
50809 +config GRKERNSEC_MODHARDEN
50810 + bool "Harden module auto-loading"
50811 + depends on MODULES
50812 + help
50813 + If you say Y here, module auto-loading in response to use of some
50814 + feature implemented by an unloaded module will be restricted to
50815 + root users. Enabling this option helps defend against attacks
50816 + by unprivileged users who abuse the auto-loading behavior to
50817 + cause a vulnerable module to load that is then exploited.
50818 +
50819 + If this option prevents a legitimate use of auto-loading for a
50820 + non-root user, the administrator can execute modprobe manually
50821 + with the exact name of the module mentioned in the alert log.
50822 + Alternatively, the administrator can add the module to the list
50823 + of modules loaded at boot by modifying init scripts.
50824 +
50825 + Modification of init scripts will most likely be needed on
50826 + Ubuntu servers with encrypted home directory support enabled,
50827 + as the first non-root user logging in will cause the ecb(aes),
50828 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50829 +
50830 +config GRKERNSEC_HIDESYM
50831 + bool "Hide kernel symbols"
50832 + help
50833 + If you say Y here, getting information on loaded modules, and
50834 + displaying all kernel symbols through a syscall will be restricted
50835 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50836 + /proc/kallsyms will be restricted to the root user. The RBAC
50837 + system can hide that entry even from root.
50838 +
50839 + This option also prevents leaking of kernel addresses through
50840 + several /proc entries.
50841 +
50842 + Note that this option is only effective provided the following
50843 + conditions are met:
50844 + 1) The kernel using grsecurity is not precompiled by some distribution
50845 + 2) You have also enabled GRKERNSEC_DMESG
50846 + 3) You are using the RBAC system and hiding other files such as your
50847 + kernel image and System.map. Alternatively, enabling this option
50848 + causes the permissions on /boot, /lib/modules, and the kernel
50849 + source directory to change at compile time to prevent
50850 + reading by non-root users.
50851 + If the above conditions are met, this option will aid in providing a
50852 + useful protection against local kernel exploitation of overflows
50853 + and arbitrary read/write vulnerabilities.
50854 +
50855 +config GRKERNSEC_KERN_LOCKOUT
50856 + bool "Active kernel exploit response"
50857 + depends on X86 || ARM || PPC || SPARC
50858 + help
50859 + If you say Y here, when a PaX alert is triggered due to suspicious
50860 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50861 + or an OOPs occurs due to bad memory accesses, instead of just
50862 + terminating the offending process (and potentially allowing
50863 + a subsequent exploit from the same user), we will take one of two
50864 + actions:
50865 + If the user was root, we will panic the system
50866 + If the user was non-root, we will log the attempt, terminate
50867 + all processes owned by the user, then prevent them from creating
50868 + any new processes until the system is restarted
50869 + This deters repeated kernel exploitation/bruteforcing attempts
50870 + and is useful for later forensics.
50871 +
50872 +endmenu
50873 +menu "Role Based Access Control Options"
50874 +depends on GRKERNSEC
50875 +
50876 +config GRKERNSEC_RBAC_DEBUG
50877 + bool
50878 +
50879 +config GRKERNSEC_NO_RBAC
50880 + bool "Disable RBAC system"
50881 + help
50882 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50883 + preventing the RBAC system from being enabled. You should only say Y
50884 + here if you have no intention of using the RBAC system, so as to prevent
50885 + an attacker with root access from misusing the RBAC system to hide files
50886 + and processes when loadable module support and /dev/[k]mem have been
50887 + locked down.
50888 +
50889 +config GRKERNSEC_ACL_HIDEKERN
50890 + bool "Hide kernel processes"
50891 + help
50892 + If you say Y here, all kernel threads will be hidden to all
50893 + processes but those whose subject has the "view hidden processes"
50894 + flag.
50895 +
50896 +config GRKERNSEC_ACL_MAXTRIES
50897 + int "Maximum tries before password lockout"
50898 + default 3
50899 + help
50900 + This option enforces the maximum number of times a user can attempt
50901 + to authorize themselves with the grsecurity RBAC system before being
50902 + denied the ability to attempt authorization again for a specified time.
50903 + The lower the number, the harder it will be to brute-force a password.
50904 +
50905 +config GRKERNSEC_ACL_TIMEOUT
50906 + int "Time to wait after max password tries, in seconds"
50907 + default 30
50908 + help
50909 + This option specifies the time the user must wait after attempting to
50910 + authorize to the RBAC system with the maximum number of invalid
50911 + passwords. The higher the number, the harder it will be to brute-force
50912 + a password.
50913 +
50914 +endmenu
50915 +menu "Filesystem Protections"
50916 +depends on GRKERNSEC
50917 +
50918 +config GRKERNSEC_PROC
50919 + bool "Proc restrictions"
50920 + help
50921 + If you say Y here, the permissions of the /proc filesystem
50922 + will be altered to enhance system security and privacy. You MUST
50923 + choose either a user only restriction or a user and group restriction.
50924 + Depending upon the option you choose, you can either restrict users to
50925 + see only the processes they themselves run, or choose a group that can
50926 + view all processes and files normally restricted to root if you choose
50927 + the "restrict to user only" option. NOTE: If you're running identd or
50928 + ntpd as a non-root user, you will have to run it as the group you
50929 + specify here.
50930 +
50931 +config GRKERNSEC_PROC_USER
50932 + bool "Restrict /proc to user only"
50933 + depends on GRKERNSEC_PROC
50934 + help
50935 + If you say Y here, non-root users will only be able to view their own
50936 + processes, and restricts them from viewing network-related information,
50937 + and viewing kernel symbol and module information.
50938 +
50939 +config GRKERNSEC_PROC_USERGROUP
50940 + bool "Allow special group"
50941 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50942 + help
50943 + If you say Y here, you will be able to select a group that will be
50944 + able to view all processes and network-related information. If you've
50945 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50946 + remain hidden. This option is useful if you want to run identd as
50947 + a non-root user.
50948 +
50949 +config GRKERNSEC_PROC_GID
50950 + int "GID for special group"
50951 + depends on GRKERNSEC_PROC_USERGROUP
50952 + default 1001
50953 +
50954 +config GRKERNSEC_PROC_ADD
50955 + bool "Additional restrictions"
50956 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50957 + help
50958 + If you say Y here, additional restrictions will be placed on
50959 + /proc that keep normal users from viewing device information and
50960 + slabinfo information that could be useful for exploits.
50961 +
50962 +config GRKERNSEC_LINK
50963 + bool "Linking restrictions"
50964 + help
50965 + If you say Y here, /tmp race exploits will be prevented, since users
50966 + will no longer be able to follow symlinks owned by other users in
50967 + world-writable +t directories (e.g. /tmp), unless the owner of the
50968 + symlink is the owner of the directory. users will also not be
50969 + able to hardlink to files they do not own. If the sysctl option is
50970 + enabled, a sysctl option with name "linking_restrictions" is created.
50971 +
50972 +config GRKERNSEC_FIFO
50973 + bool "FIFO restrictions"
50974 + help
50975 + If you say Y here, users will not be able to write to FIFOs they don't
50976 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50977 + the FIFO is the same owner of the directory it's held in. If the sysctl
50978 + option is enabled, a sysctl option with name "fifo_restrictions" is
50979 + created.
50980 +
50981 +config GRKERNSEC_SYSFS_RESTRICT
50982 + bool "Sysfs/debugfs restriction"
50983 + depends on SYSFS
50984 + help
50985 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50986 + any filesystem normally mounted under it (e.g. debugfs) will be
50987 + mostly accessible only by root. These filesystems generally provide access
50988 + to hardware and debug information that isn't appropriate for unprivileged
50989 + users of the system. Sysfs and debugfs have also become a large source
50990 + of new vulnerabilities, ranging from infoleaks to local compromise.
50991 + There has been very little oversight with an eye toward security involved
50992 + in adding new exporters of information to these filesystems, so their
50993 + use is discouraged.
50994 + For reasons of compatibility, a few directories have been whitelisted
50995 + for access by non-root users:
50996 + /sys/fs/selinux
50997 + /sys/fs/fuse
50998 + /sys/devices/system/cpu
50999 +
51000 +config GRKERNSEC_ROFS
51001 + bool "Runtime read-only mount protection"
51002 + help
51003 + If you say Y here, a sysctl option with name "romount_protect" will
51004 + be created. By setting this option to 1 at runtime, filesystems
51005 + will be protected in the following ways:
51006 + * No new writable mounts will be allowed
51007 + * Existing read-only mounts won't be able to be remounted read/write
51008 + * Write operations will be denied on all block devices
51009 + This option acts independently of grsec_lock: once it is set to 1,
51010 + it cannot be turned off. Therefore, please be mindful of the resulting
51011 + behavior if this option is enabled in an init script on a read-only
51012 + filesystem. This feature is mainly intended for secure embedded systems.
51013 +
51014 +config GRKERNSEC_CHROOT
51015 + bool "Chroot jail restrictions"
51016 + help
51017 + If you say Y here, you will be able to choose several options that will
51018 + make breaking out of a chrooted jail much more difficult. If you
51019 + encounter no software incompatibilities with the following options, it
51020 + is recommended that you enable each one.
51021 +
51022 +config GRKERNSEC_CHROOT_MOUNT
51023 + bool "Deny mounts"
51024 + depends on GRKERNSEC_CHROOT
51025 + help
51026 + If you say Y here, processes inside a chroot will not be able to
51027 + mount or remount filesystems. If the sysctl option is enabled, a
51028 + sysctl option with name "chroot_deny_mount" is created.
51029 +
51030 +config GRKERNSEC_CHROOT_DOUBLE
51031 + bool "Deny double-chroots"
51032 + depends on GRKERNSEC_CHROOT
51033 + help
51034 + If you say Y here, processes inside a chroot will not be able to chroot
51035 + again outside the chroot. This is a widely used method of breaking
51036 + out of a chroot jail and should not be allowed. If the sysctl
51037 + option is enabled, a sysctl option with name
51038 + "chroot_deny_chroot" is created.
51039 +
51040 +config GRKERNSEC_CHROOT_PIVOT
51041 + bool "Deny pivot_root in chroot"
51042 + depends on GRKERNSEC_CHROOT
51043 + help
51044 + If you say Y here, processes inside a chroot will not be able to use
51045 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51046 + works similar to chroot in that it changes the root filesystem. This
51047 + function could be misused in a chrooted process to attempt to break out
51048 + of the chroot, and therefore should not be allowed. If the sysctl
51049 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51050 + created.
51051 +
51052 +config GRKERNSEC_CHROOT_CHDIR
51053 + bool "Enforce chdir(\"/\") on all chroots"
51054 + depends on GRKERNSEC_CHROOT
51055 + help
51056 + If you say Y here, the current working directory of all newly-chrooted
51057 + applications will be set to the the root directory of the chroot.
51058 + The man page on chroot(2) states:
51059 + Note that this call does not change the current working
51060 + directory, so that `.' can be outside the tree rooted at
51061 + `/'. In particular, the super-user can escape from a
51062 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51063 +
51064 + It is recommended that you say Y here, since it's not known to break
51065 + any software. If the sysctl option is enabled, a sysctl option with
51066 + name "chroot_enforce_chdir" is created.
51067 +
51068 +config GRKERNSEC_CHROOT_CHMOD
51069 + bool "Deny (f)chmod +s"
51070 + depends on GRKERNSEC_CHROOT
51071 + help
51072 + If you say Y here, processes inside a chroot will not be able to chmod
51073 + or fchmod files to make them have suid or sgid bits. This protects
51074 + against another published method of breaking a chroot. If the sysctl
51075 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51076 + created.
51077 +
51078 +config GRKERNSEC_CHROOT_FCHDIR
51079 + bool "Deny fchdir out of chroot"
51080 + depends on GRKERNSEC_CHROOT
51081 + help
51082 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51083 + to a file descriptor of the chrooting process that points to a directory
51084 + outside the filesystem will be stopped. If the sysctl option
51085 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51086 +
51087 +config GRKERNSEC_CHROOT_MKNOD
51088 + bool "Deny mknod"
51089 + depends on GRKERNSEC_CHROOT
51090 + help
51091 + If you say Y here, processes inside a chroot will not be allowed to
51092 + mknod. The problem with using mknod inside a chroot is that it
51093 + would allow an attacker to create a device entry that is the same
51094 + as one on the physical root of your system, which could range from
51095 + anything from the console device to a device for your harddrive (which
51096 + they could then use to wipe the drive or steal data). It is recommended
51097 + that you say Y here, unless you run into software incompatibilities.
51098 + If the sysctl option is enabled, a sysctl option with name
51099 + "chroot_deny_mknod" is created.
51100 +
51101 +config GRKERNSEC_CHROOT_SHMAT
51102 + bool "Deny shmat() out of chroot"
51103 + depends on GRKERNSEC_CHROOT
51104 + help
51105 + If you say Y here, processes inside a chroot will not be able to attach
51106 + to shared memory segments that were created outside of the chroot jail.
51107 + It is recommended that you say Y here. If the sysctl option is enabled,
51108 + a sysctl option with name "chroot_deny_shmat" is created.
51109 +
51110 +config GRKERNSEC_CHROOT_UNIX
51111 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51112 + depends on GRKERNSEC_CHROOT
51113 + help
51114 + If you say Y here, processes inside a chroot will not be able to
51115 + connect to abstract (meaning not belonging to a filesystem) Unix
51116 + domain sockets that were bound outside of a chroot. It is recommended
51117 + that you say Y here. If the sysctl option is enabled, a sysctl option
51118 + with name "chroot_deny_unix" is created.
51119 +
51120 +config GRKERNSEC_CHROOT_FINDTASK
51121 + bool "Protect outside processes"
51122 + depends on GRKERNSEC_CHROOT
51123 + help
51124 + If you say Y here, processes inside a chroot will not be able to
51125 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51126 + getsid, or view any process outside of the chroot. If the sysctl
51127 + option is enabled, a sysctl option with name "chroot_findtask" is
51128 + created.
51129 +
51130 +config GRKERNSEC_CHROOT_NICE
51131 + bool "Restrict priority changes"
51132 + depends on GRKERNSEC_CHROOT
51133 + help
51134 + If you say Y here, processes inside a chroot will not be able to raise
51135 + the priority of processes in the chroot, or alter the priority of
51136 + processes outside the chroot. This provides more security than simply
51137 + removing CAP_SYS_NICE from the process' capability set. If the
51138 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51139 + is created.
51140 +
51141 +config GRKERNSEC_CHROOT_SYSCTL
51142 + bool "Deny sysctl writes"
51143 + depends on GRKERNSEC_CHROOT
51144 + help
51145 + If you say Y here, an attacker in a chroot will not be able to
51146 + write to sysctl entries, either by sysctl(2) or through a /proc
51147 + interface. It is strongly recommended that you say Y here. If the
51148 + sysctl option is enabled, a sysctl option with name
51149 + "chroot_deny_sysctl" is created.
51150 +
51151 +config GRKERNSEC_CHROOT_CAPS
51152 + bool "Capability restrictions"
51153 + depends on GRKERNSEC_CHROOT
51154 + help
51155 + If you say Y here, the capabilities on all processes within a
51156 + chroot jail will be lowered to stop module insertion, raw i/o,
51157 + system and net admin tasks, rebooting the system, modifying immutable
51158 + files, modifying IPC owned by another, and changing the system time.
51159 + This is left an option because it can break some apps. Disable this
51160 + if your chrooted apps are having problems performing those kinds of
51161 + tasks. If the sysctl option is enabled, a sysctl option with
51162 + name "chroot_caps" is created.
51163 +
51164 +endmenu
51165 +menu "Kernel Auditing"
51166 +depends on GRKERNSEC
51167 +
51168 +config GRKERNSEC_AUDIT_GROUP
51169 + bool "Single group for auditing"
51170 + help
51171 + If you say Y here, the exec, chdir, and (un)mount logging features
51172 + will only operate on a group you specify. This option is recommended
51173 + if you only want to watch certain users instead of having a large
51174 + amount of logs from the entire system. If the sysctl option is enabled,
51175 + a sysctl option with name "audit_group" is created.
51176 +
51177 +config GRKERNSEC_AUDIT_GID
51178 + int "GID for auditing"
51179 + depends on GRKERNSEC_AUDIT_GROUP
51180 + default 1007
51181 +
51182 +config GRKERNSEC_EXECLOG
51183 + bool "Exec logging"
51184 + help
51185 + If you say Y here, all execve() calls will be logged (since the
51186 + other exec*() calls are frontends to execve(), all execution
51187 + will be logged). Useful for shell-servers that like to keep track
51188 + of their users. If the sysctl option is enabled, a sysctl option with
51189 + name "exec_logging" is created.
51190 + WARNING: This option when enabled will produce a LOT of logs, especially
51191 + on an active system.
51192 +
51193 +config GRKERNSEC_RESLOG
51194 + bool "Resource logging"
51195 + help
51196 + If you say Y here, all attempts to overstep resource limits will
51197 + be logged with the resource name, the requested size, and the current
51198 + limit. It is highly recommended that you say Y here. If the sysctl
51199 + option is enabled, a sysctl option with name "resource_logging" is
51200 + created. If the RBAC system is enabled, the sysctl value is ignored.
51201 +
51202 +config GRKERNSEC_CHROOT_EXECLOG
51203 + bool "Log execs within chroot"
51204 + help
51205 + If you say Y here, all executions inside a chroot jail will be logged
51206 + to syslog. This can cause a large amount of logs if certain
51207 + applications (eg. djb's daemontools) are installed on the system, and
51208 + is therefore left as an option. If the sysctl option is enabled, a
51209 + sysctl option with name "chroot_execlog" is created.
51210 +
51211 +config GRKERNSEC_AUDIT_PTRACE
51212 + bool "Ptrace logging"
51213 + help
51214 + If you say Y here, all attempts to attach to a process via ptrace
51215 + will be logged. If the sysctl option is enabled, a sysctl option
51216 + with name "audit_ptrace" is created.
51217 +
51218 +config GRKERNSEC_AUDIT_CHDIR
51219 + bool "Chdir logging"
51220 + help
51221 + If you say Y here, all chdir() calls will be logged. If the sysctl
51222 + option is enabled, a sysctl option with name "audit_chdir" is created.
51223 +
51224 +config GRKERNSEC_AUDIT_MOUNT
51225 + bool "(Un)Mount logging"
51226 + help
51227 + If you say Y here, all mounts and unmounts will be logged. If the
51228 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51229 + created.
51230 +
51231 +config GRKERNSEC_SIGNAL
51232 + bool "Signal logging"
51233 + help
51234 + If you say Y here, certain important signals will be logged, such as
51235 + SIGSEGV, which will as a result inform you of when a error in a program
51236 + occurred, which in some cases could mean a possible exploit attempt.
51237 + If the sysctl option is enabled, a sysctl option with name
51238 + "signal_logging" is created.
51239 +
51240 +config GRKERNSEC_FORKFAIL
51241 + bool "Fork failure logging"
51242 + help
51243 + If you say Y here, all failed fork() attempts will be logged.
51244 + This could suggest a fork bomb, or someone attempting to overstep
51245 + their process limit. If the sysctl option is enabled, a sysctl option
51246 + with name "forkfail_logging" is created.
51247 +
51248 +config GRKERNSEC_TIME
51249 + bool "Time change logging"
51250 + help
51251 + If you say Y here, any changes of the system clock will be logged.
51252 + If the sysctl option is enabled, a sysctl option with name
51253 + "timechange_logging" is created.
51254 +
51255 +config GRKERNSEC_PROC_IPADDR
51256 + bool "/proc/<pid>/ipaddr support"
51257 + help
51258 + If you say Y here, a new entry will be added to each /proc/<pid>
51259 + directory that contains the IP address of the person using the task.
51260 + The IP is carried across local TCP and AF_UNIX stream sockets.
51261 + This information can be useful for IDS/IPSes to perform remote response
51262 + to a local attack. The entry is readable by only the owner of the
51263 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51264 + the RBAC system), and thus does not create privacy concerns.
51265 +
51266 +config GRKERNSEC_RWXMAP_LOG
51267 + bool 'Denied RWX mmap/mprotect logging'
51268 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51269 + help
51270 + If you say Y here, calls to mmap() and mprotect() with explicit
51271 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51272 + denied by the PAX_MPROTECT feature. If the sysctl option is
51273 + enabled, a sysctl option with name "rwxmap_logging" is created.
51274 +
51275 +config GRKERNSEC_AUDIT_TEXTREL
51276 + bool 'ELF text relocations logging (READ HELP)'
51277 + depends on PAX_MPROTECT
51278 + help
51279 + If you say Y here, text relocations will be logged with the filename
51280 + of the offending library or binary. The purpose of the feature is
51281 + to help Linux distribution developers get rid of libraries and
51282 + binaries that need text relocations which hinder the future progress
51283 + of PaX. Only Linux distribution developers should say Y here, and
51284 + never on a production machine, as this option creates an information
51285 + leak that could aid an attacker in defeating the randomization of
51286 + a single memory region. If the sysctl option is enabled, a sysctl
51287 + option with name "audit_textrel" is created.
51288 +
51289 +endmenu
51290 +
51291 +menu "Executable Protections"
51292 +depends on GRKERNSEC
51293 +
51294 +config GRKERNSEC_DMESG
51295 + bool "Dmesg(8) restriction"
51296 + help
51297 + If you say Y here, non-root users will not be able to use dmesg(8)
51298 + to view up to the last 4kb of messages in the kernel's log buffer.
51299 + The kernel's log buffer often contains kernel addresses and other
51300 + identifying information useful to an attacker in fingerprinting a
51301 + system for a targeted exploit.
51302 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51303 + created.
51304 +
51305 +config GRKERNSEC_HARDEN_PTRACE
51306 + bool "Deter ptrace-based process snooping"
51307 + help
51308 + If you say Y here, TTY sniffers and other malicious monitoring
51309 + programs implemented through ptrace will be defeated. If you
51310 + have been using the RBAC system, this option has already been
51311 + enabled for several years for all users, with the ability to make
51312 + fine-grained exceptions.
51313 +
51314 + This option only affects the ability of non-root users to ptrace
51315 + processes that are not a descendent of the ptracing process.
51316 + This means that strace ./binary and gdb ./binary will still work,
51317 + but attaching to arbitrary processes will not. If the sysctl
51318 + option is enabled, a sysctl option with name "harden_ptrace" is
51319 + created.
51320 +
51321 +config GRKERNSEC_PTRACE_READEXEC
51322 + bool "Require read access to ptrace sensitive binaries"
51323 + help
51324 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51325 + binaries. This option is useful in environments that
51326 + remove the read bits (e.g. file mode 4711) from suid binaries to
51327 + prevent infoleaking of their contents. This option adds
51328 + consistency to the use of that file mode, as the binary could normally
51329 + be read out when run without privileges while ptracing.
51330 +
51331 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51332 + is created.
51333 +
51334 +config GRKERNSEC_SETXID
51335 + bool "Enforce consistent multithreaded privileges"
51336 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51337 + help
51338 + If you say Y here, a change from a root uid to a non-root uid
51339 + in a multithreaded application will cause the resulting uids,
51340 + gids, supplementary groups, and capabilities in that thread
51341 + to be propagated to the other threads of the process. In most
51342 + cases this is unnecessary, as glibc will emulate this behavior
51343 + on behalf of the application. Other libcs do not act in the
51344 + same way, allowing the other threads of the process to continue
51345 + running with root privileges. If the sysctl option is enabled,
51346 + a sysctl option with name "consistent_setxid" is created.
51347 +
51348 +config GRKERNSEC_TPE
51349 + bool "Trusted Path Execution (TPE)"
51350 + help
51351 + If you say Y here, you will be able to choose a gid to add to the
51352 + supplementary groups of users you want to mark as "untrusted."
51353 + These users will not be able to execute any files that are not in
51354 + root-owned directories writable only by root. If the sysctl option
51355 + is enabled, a sysctl option with name "tpe" is created.
51356 +
51357 +config GRKERNSEC_TPE_ALL
51358 + bool "Partially restrict all non-root users"
51359 + depends on GRKERNSEC_TPE
51360 + help
51361 + If you say Y here, all non-root users will be covered under
51362 + a weaker TPE restriction. This is separate from, and in addition to,
51363 + the main TPE options that you have selected elsewhere. Thus, if a
51364 + "trusted" GID is chosen, this restriction applies to even that GID.
51365 + Under this restriction, all non-root users will only be allowed to
51366 + execute files in directories they own that are not group or
51367 + world-writable, or in directories owned by root and writable only by
51368 + root. If the sysctl option is enabled, a sysctl option with name
51369 + "tpe_restrict_all" is created.
51370 +
51371 +config GRKERNSEC_TPE_INVERT
51372 + bool "Invert GID option"
51373 + depends on GRKERNSEC_TPE
51374 + help
51375 + If you say Y here, the group you specify in the TPE configuration will
51376 + decide what group TPE restrictions will be *disabled* for. This
51377 + option is useful if you want TPE restrictions to be applied to most
51378 + users on the system. If the sysctl option is enabled, a sysctl option
51379 + with name "tpe_invert" is created. Unlike other sysctl options, this
51380 + entry will default to on for backward-compatibility.
51381 +
51382 +config GRKERNSEC_TPE_GID
51383 + int "GID for untrusted users"
51384 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51385 + default 1005
51386 + help
51387 + Setting this GID determines what group TPE restrictions will be
51388 + *enabled* for. If the sysctl option is enabled, a sysctl option
51389 + with name "tpe_gid" is created.
51390 +
51391 +config GRKERNSEC_TPE_GID
51392 + int "GID for trusted users"
51393 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51394 + default 1005
51395 + help
51396 + Setting this GID determines what group TPE restrictions will be
51397 + *disabled* for. If the sysctl option is enabled, a sysctl option
51398 + with name "tpe_gid" is created.
51399 +
51400 +endmenu
51401 +menu "Network Protections"
51402 +depends on GRKERNSEC
51403 +
51404 +config GRKERNSEC_RANDNET
51405 + bool "Larger entropy pools"
51406 + help
51407 + If you say Y here, the entropy pools used for many features of Linux
51408 + and grsecurity will be doubled in size. Since several grsecurity
51409 + features use additional randomness, it is recommended that you say Y
51410 + here. Saying Y here has a similar effect as modifying
51411 + /proc/sys/kernel/random/poolsize.
51412 +
51413 +config GRKERNSEC_BLACKHOLE
51414 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51415 + depends on NET
51416 + help
51417 + If you say Y here, neither TCP resets nor ICMP
51418 + destination-unreachable packets will be sent in response to packets
51419 + sent to ports for which no associated listening process exists.
51420 + This feature supports both IPV4 and IPV6 and exempts the
51421 + loopback interface from blackholing. Enabling this feature
51422 + makes a host more resilient to DoS attacks and reduces network
51423 + visibility against scanners.
51424 +
51425 + The blackhole feature as-implemented is equivalent to the FreeBSD
51426 + blackhole feature, as it prevents RST responses to all packets, not
51427 + just SYNs. Under most application behavior this causes no
51428 + problems, but applications (like haproxy) may not close certain
51429 + connections in a way that cleanly terminates them on the remote
51430 + end, leaving the remote host in LAST_ACK state. Because of this
51431 + side-effect and to prevent intentional LAST_ACK DoSes, this
51432 + feature also adds automatic mitigation against such attacks.
51433 + The mitigation drastically reduces the amount of time a socket
51434 + can spend in LAST_ACK state. If you're using haproxy and not
51435 + all servers it connects to have this option enabled, consider
51436 + disabling this feature on the haproxy host.
51437 +
51438 + If the sysctl option is enabled, two sysctl options with names
51439 + "ip_blackhole" and "lastack_retries" will be created.
51440 + While "ip_blackhole" takes the standard zero/non-zero on/off
51441 + toggle, "lastack_retries" uses the same kinds of values as
51442 + "tcp_retries1" and "tcp_retries2". The default value of 4
51443 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51444 + state.
51445 +
51446 +config GRKERNSEC_SOCKET
51447 + bool "Socket restrictions"
51448 + depends on NET
51449 + help
51450 + If you say Y here, you will be able to choose from several options.
51451 + If you assign a GID on your system and add it to the supplementary
51452 + groups of users you want to restrict socket access to, this patch
51453 + will perform up to three things, based on the option(s) you choose.
51454 +
51455 +config GRKERNSEC_SOCKET_ALL
51456 + bool "Deny any sockets to group"
51457 + depends on GRKERNSEC_SOCKET
51458 + help
51459 + If you say Y here, you will be able to choose a GID of whose users will
51460 + be unable to connect to other hosts from your machine or run server
51461 + applications from your machine. If the sysctl option is enabled, a
51462 + sysctl option with name "socket_all" is created.
51463 +
51464 +config GRKERNSEC_SOCKET_ALL_GID
51465 + int "GID to deny all sockets for"
51466 + depends on GRKERNSEC_SOCKET_ALL
51467 + default 1004
51468 + help
51469 + Here you can choose the GID to disable socket access for. Remember to
51470 + add the users you want socket access disabled for to the GID
51471 + specified here. If the sysctl option is enabled, a sysctl option
51472 + with name "socket_all_gid" is created.
51473 +
51474 +config GRKERNSEC_SOCKET_CLIENT
51475 + bool "Deny client sockets to group"
51476 + depends on GRKERNSEC_SOCKET
51477 + help
51478 + If you say Y here, you will be able to choose a GID of whose users will
51479 + be unable to connect to other hosts from your machine, but will be
51480 + able to run servers. If this option is enabled, all users in the group
51481 + you specify will have to use passive mode when initiating ftp transfers
51482 + from the shell on your machine. If the sysctl option is enabled, a
51483 + sysctl option with name "socket_client" is created.
51484 +
51485 +config GRKERNSEC_SOCKET_CLIENT_GID
51486 + int "GID to deny client sockets for"
51487 + depends on GRKERNSEC_SOCKET_CLIENT
51488 + default 1003
51489 + help
51490 + Here you can choose the GID to disable client socket access for.
51491 + Remember to add the users you want client socket access disabled for to
51492 + the GID specified here. If the sysctl option is enabled, a sysctl
51493 + option with name "socket_client_gid" is created.
51494 +
51495 +config GRKERNSEC_SOCKET_SERVER
51496 + bool "Deny server sockets to group"
51497 + depends on GRKERNSEC_SOCKET
51498 + help
51499 + If you say Y here, you will be able to choose a GID of whose users will
51500 + be unable to run server applications from your machine. If the sysctl
51501 + option is enabled, a sysctl option with name "socket_server" is created.
51502 +
51503 +config GRKERNSEC_SOCKET_SERVER_GID
51504 + int "GID to deny server sockets for"
51505 + depends on GRKERNSEC_SOCKET_SERVER
51506 + default 1002
51507 + help
51508 + Here you can choose the GID to disable server socket access for.
51509 + Remember to add the users you want server socket access disabled for to
51510 + the GID specified here. If the sysctl option is enabled, a sysctl
51511 + option with name "socket_server_gid" is created.
51512 +
51513 +endmenu
51514 +menu "Sysctl support"
51515 +depends on GRKERNSEC && SYSCTL
51516 +
51517 +config GRKERNSEC_SYSCTL
51518 + bool "Sysctl support"
51519 + help
51520 + If you say Y here, you will be able to change the options that
51521 + grsecurity runs with at bootup, without having to recompile your
51522 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51523 + to enable (1) or disable (0) various features. All the sysctl entries
51524 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51525 + All features enabled in the kernel configuration are disabled at boot
51526 + if you do not say Y to the "Turn on features by default" option.
51527 + All options should be set at startup, and the grsec_lock entry should
51528 + be set to a non-zero value after all the options are set.
51529 + *THIS IS EXTREMELY IMPORTANT*
51530 +
51531 +config GRKERNSEC_SYSCTL_DISTRO
51532 + bool "Extra sysctl support for distro makers (READ HELP)"
51533 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51534 + help
51535 + If you say Y here, additional sysctl options will be created
51536 + for features that affect processes running as root. Therefore,
51537 + it is critical when using this option that the grsec_lock entry be
51538 + enabled after boot. Only distros with prebuilt kernel packages
51539 + with this option enabled that can ensure grsec_lock is enabled
51540 + after boot should use this option.
51541 + *Failure to set grsec_lock after boot makes all grsec features
51542 + this option covers useless*
51543 +
51544 + Currently this option creates the following sysctl entries:
51545 + "Disable Privileged I/O": "disable_priv_io"
51546 +
51547 +config GRKERNSEC_SYSCTL_ON
51548 + bool "Turn on features by default"
51549 + depends on GRKERNSEC_SYSCTL
51550 + help
51551 + If you say Y here, instead of having all features enabled in the
51552 + kernel configuration disabled at boot time, the features will be
51553 + enabled at boot time. It is recommended you say Y here unless
51554 + there is some reason you would want all sysctl-tunable features to
51555 + be disabled by default. As mentioned elsewhere, it is important
51556 + to enable the grsec_lock entry once you have finished modifying
51557 + the sysctl entries.
51558 +
51559 +endmenu
51560 +menu "Logging Options"
51561 +depends on GRKERNSEC
51562 +
51563 +config GRKERNSEC_FLOODTIME
51564 + int "Seconds in between log messages (minimum)"
51565 + default 10
51566 + help
51567 + This option allows you to enforce the number of seconds between
51568 + grsecurity log messages. The default should be suitable for most
51569 + people, however, if you choose to change it, choose a value small enough
51570 + to allow informative logs to be produced, but large enough to
51571 + prevent flooding.
51572 +
51573 +config GRKERNSEC_FLOODBURST
51574 + int "Number of messages in a burst (maximum)"
51575 + default 6
51576 + help
51577 + This option allows you to choose the maximum number of messages allowed
51578 + within the flood time interval you chose in a separate option. The
51579 + default should be suitable for most people, however if you find that
51580 + many of your logs are being interpreted as flooding, you may want to
51581 + raise this value.
51582 +
51583 +endmenu
51584 +
51585 +endmenu
51586 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51587 new file mode 100644
51588 index 0000000..1b9afa9
51589 --- /dev/null
51590 +++ b/grsecurity/Makefile
51591 @@ -0,0 +1,38 @@
51592 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51593 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51594 +# into an RBAC system
51595 +#
51596 +# All code in this directory and various hooks inserted throughout the kernel
51597 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51598 +# under the GPL v2 or higher
51599 +
51600 +KBUILD_CFLAGS += -Werror
51601 +
51602 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51603 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51604 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51605 +
51606 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51607 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51608 + gracl_learn.o grsec_log.o
51609 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51610 +
51611 +ifdef CONFIG_NET
51612 +obj-y += grsec_sock.o
51613 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51614 +endif
51615 +
51616 +ifndef CONFIG_GRKERNSEC
51617 +obj-y += grsec_disabled.o
51618 +endif
51619 +
51620 +ifdef CONFIG_GRKERNSEC_HIDESYM
51621 +extra-y := grsec_hidesym.o
51622 +$(obj)/grsec_hidesym.o:
51623 + @-chmod -f 500 /boot
51624 + @-chmod -f 500 /lib/modules
51625 + @-chmod -f 500 /lib64/modules
51626 + @-chmod -f 500 /lib32/modules
51627 + @-chmod -f 700 .
51628 + @echo ' grsec: protected kernel image paths'
51629 +endif
51630 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51631 new file mode 100644
51632 index 0000000..a6d83f0
51633 --- /dev/null
51634 +++ b/grsecurity/gracl.c
51635 @@ -0,0 +1,4193 @@
51636 +#include <linux/kernel.h>
51637 +#include <linux/module.h>
51638 +#include <linux/sched.h>
51639 +#include <linux/mm.h>
51640 +#include <linux/file.h>
51641 +#include <linux/fs.h>
51642 +#include <linux/namei.h>
51643 +#include <linux/mount.h>
51644 +#include <linux/tty.h>
51645 +#include <linux/proc_fs.h>
51646 +#include <linux/lglock.h>
51647 +#include <linux/slab.h>
51648 +#include <linux/vmalloc.h>
51649 +#include <linux/types.h>
51650 +#include <linux/sysctl.h>
51651 +#include <linux/netdevice.h>
51652 +#include <linux/ptrace.h>
51653 +#include <linux/gracl.h>
51654 +#include <linux/gralloc.h>
51655 +#include <linux/security.h>
51656 +#include <linux/grinternal.h>
51657 +#include <linux/pid_namespace.h>
51658 +#include <linux/fdtable.h>
51659 +#include <linux/percpu.h>
51660 +#include "../fs/mount.h"
51661 +
51662 +#include <asm/uaccess.h>
51663 +#include <asm/errno.h>
51664 +#include <asm/mman.h>
51665 +
51666 +static struct acl_role_db acl_role_set;
51667 +static struct name_db name_set;
51668 +static struct inodev_db inodev_set;
51669 +
51670 +/* for keeping track of userspace pointers used for subjects, so we
51671 + can share references in the kernel as well
51672 +*/
51673 +
51674 +static struct path real_root;
51675 +
51676 +static struct acl_subj_map_db subj_map_set;
51677 +
51678 +static struct acl_role_label *default_role;
51679 +
51680 +static struct acl_role_label *role_list;
51681 +
51682 +static u16 acl_sp_role_value;
51683 +
51684 +extern char *gr_shared_page[4];
51685 +static DEFINE_MUTEX(gr_dev_mutex);
51686 +DEFINE_RWLOCK(gr_inode_lock);
51687 +
51688 +struct gr_arg *gr_usermode;
51689 +
51690 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51691 +
51692 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51693 +extern void gr_clear_learn_entries(void);
51694 +
51695 +#ifdef CONFIG_GRKERNSEC_RESLOG
51696 +extern void gr_log_resource(const struct task_struct *task,
51697 + const int res, const unsigned long wanted, const int gt);
51698 +#endif
51699 +
51700 +unsigned char *gr_system_salt;
51701 +unsigned char *gr_system_sum;
51702 +
51703 +static struct sprole_pw **acl_special_roles = NULL;
51704 +static __u16 num_sprole_pws = 0;
51705 +
51706 +static struct acl_role_label *kernel_role = NULL;
51707 +
51708 +static unsigned int gr_auth_attempts = 0;
51709 +static unsigned long gr_auth_expires = 0UL;
51710 +
51711 +#ifdef CONFIG_NET
51712 +extern struct vfsmount *sock_mnt;
51713 +#endif
51714 +
51715 +extern struct vfsmount *pipe_mnt;
51716 +extern struct vfsmount *shm_mnt;
51717 +#ifdef CONFIG_HUGETLBFS
51718 +extern struct vfsmount *hugetlbfs_vfsmount;
51719 +#endif
51720 +
51721 +static struct acl_object_label *fakefs_obj_rw;
51722 +static struct acl_object_label *fakefs_obj_rwx;
51723 +
51724 +extern int gr_init_uidset(void);
51725 +extern void gr_free_uidset(void);
51726 +extern void gr_remove_uid(uid_t uid);
51727 +extern int gr_find_uid(uid_t uid);
51728 +
51729 +DECLARE_BRLOCK(vfsmount_lock);
51730 +
51731 +__inline__ int
51732 +gr_acl_is_enabled(void)
51733 +{
51734 + return (gr_status & GR_READY);
51735 +}
51736 +
51737 +#ifdef CONFIG_BTRFS_FS
51738 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51739 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51740 +#endif
51741 +
51742 +static inline dev_t __get_dev(const struct dentry *dentry)
51743 +{
51744 +#ifdef CONFIG_BTRFS_FS
51745 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51746 + return get_btrfs_dev_from_inode(dentry->d_inode);
51747 + else
51748 +#endif
51749 + return dentry->d_inode->i_sb->s_dev;
51750 +}
51751 +
51752 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51753 +{
51754 + return __get_dev(dentry);
51755 +}
51756 +
51757 +static char gr_task_roletype_to_char(struct task_struct *task)
51758 +{
51759 + switch (task->role->roletype &
51760 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51761 + GR_ROLE_SPECIAL)) {
51762 + case GR_ROLE_DEFAULT:
51763 + return 'D';
51764 + case GR_ROLE_USER:
51765 + return 'U';
51766 + case GR_ROLE_GROUP:
51767 + return 'G';
51768 + case GR_ROLE_SPECIAL:
51769 + return 'S';
51770 + }
51771 +
51772 + return 'X';
51773 +}
51774 +
51775 +char gr_roletype_to_char(void)
51776 +{
51777 + return gr_task_roletype_to_char(current);
51778 +}
51779 +
51780 +__inline__ int
51781 +gr_acl_tpe_check(void)
51782 +{
51783 + if (unlikely(!(gr_status & GR_READY)))
51784 + return 0;
51785 + if (current->role->roletype & GR_ROLE_TPE)
51786 + return 1;
51787 + else
51788 + return 0;
51789 +}
51790 +
51791 +int
51792 +gr_handle_rawio(const struct inode *inode)
51793 +{
51794 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51795 + if (inode && S_ISBLK(inode->i_mode) &&
51796 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51797 + !capable(CAP_SYS_RAWIO))
51798 + return 1;
51799 +#endif
51800 + return 0;
51801 +}
51802 +
51803 +static int
51804 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51805 +{
51806 + if (likely(lena != lenb))
51807 + return 0;
51808 +
51809 + return !memcmp(a, b, lena);
51810 +}
51811 +
51812 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51813 +{
51814 + *buflen -= namelen;
51815 + if (*buflen < 0)
51816 + return -ENAMETOOLONG;
51817 + *buffer -= namelen;
51818 + memcpy(*buffer, str, namelen);
51819 + return 0;
51820 +}
51821 +
51822 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51823 +{
51824 + return prepend(buffer, buflen, name->name, name->len);
51825 +}
51826 +
51827 +static int prepend_path(const struct path *path, struct path *root,
51828 + char **buffer, int *buflen)
51829 +{
51830 + struct dentry *dentry = path->dentry;
51831 + struct vfsmount *vfsmnt = path->mnt;
51832 + struct mount *mnt = real_mount(vfsmnt);
51833 + bool slash = false;
51834 + int error = 0;
51835 +
51836 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51837 + struct dentry * parent;
51838 +
51839 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51840 + /* Global root? */
51841 + if (!mnt_has_parent(mnt)) {
51842 + goto out;
51843 + }
51844 + dentry = mnt->mnt_mountpoint;
51845 + mnt = mnt->mnt_parent;
51846 + vfsmnt = &mnt->mnt;
51847 + continue;
51848 + }
51849 + parent = dentry->d_parent;
51850 + prefetch(parent);
51851 + spin_lock(&dentry->d_lock);
51852 + error = prepend_name(buffer, buflen, &dentry->d_name);
51853 + spin_unlock(&dentry->d_lock);
51854 + if (!error)
51855 + error = prepend(buffer, buflen, "/", 1);
51856 + if (error)
51857 + break;
51858 +
51859 + slash = true;
51860 + dentry = parent;
51861 + }
51862 +
51863 +out:
51864 + if (!error && !slash)
51865 + error = prepend(buffer, buflen, "/", 1);
51866 +
51867 + return error;
51868 +}
51869 +
51870 +/* this must be called with vfsmount_lock and rename_lock held */
51871 +
51872 +static char *__our_d_path(const struct path *path, struct path *root,
51873 + char *buf, int buflen)
51874 +{
51875 + char *res = buf + buflen;
51876 + int error;
51877 +
51878 + prepend(&res, &buflen, "\0", 1);
51879 + error = prepend_path(path, root, &res, &buflen);
51880 + if (error)
51881 + return ERR_PTR(error);
51882 +
51883 + return res;
51884 +}
51885 +
51886 +static char *
51887 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51888 +{
51889 + char *retval;
51890 +
51891 + retval = __our_d_path(path, root, buf, buflen);
51892 + if (unlikely(IS_ERR(retval)))
51893 + retval = strcpy(buf, "<path too long>");
51894 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51895 + retval[1] = '\0';
51896 +
51897 + return retval;
51898 +}
51899 +
51900 +static char *
51901 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51902 + char *buf, int buflen)
51903 +{
51904 + struct path path;
51905 + char *res;
51906 +
51907 + path.dentry = (struct dentry *)dentry;
51908 + path.mnt = (struct vfsmount *)vfsmnt;
51909 +
51910 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51911 + by the RBAC system */
51912 + res = gen_full_path(&path, &real_root, buf, buflen);
51913 +
51914 + return res;
51915 +}
51916 +
51917 +static char *
51918 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51919 + char *buf, int buflen)
51920 +{
51921 + char *res;
51922 + struct path path;
51923 + struct path root;
51924 + struct task_struct *reaper = &init_task;
51925 +
51926 + path.dentry = (struct dentry *)dentry;
51927 + path.mnt = (struct vfsmount *)vfsmnt;
51928 +
51929 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51930 + get_fs_root(reaper->fs, &root);
51931 +
51932 + write_seqlock(&rename_lock);
51933 + br_read_lock(vfsmount_lock);
51934 + res = gen_full_path(&path, &root, buf, buflen);
51935 + br_read_unlock(vfsmount_lock);
51936 + write_sequnlock(&rename_lock);
51937 +
51938 + path_put(&root);
51939 + return res;
51940 +}
51941 +
51942 +static char *
51943 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51944 +{
51945 + char *ret;
51946 + write_seqlock(&rename_lock);
51947 + br_read_lock(vfsmount_lock);
51948 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51949 + PAGE_SIZE);
51950 + br_read_unlock(vfsmount_lock);
51951 + write_sequnlock(&rename_lock);
51952 + return ret;
51953 +}
51954 +
51955 +static char *
51956 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51957 +{
51958 + char *ret;
51959 + char *buf;
51960 + int buflen;
51961 +
51962 + write_seqlock(&rename_lock);
51963 + br_read_lock(vfsmount_lock);
51964 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51965 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51966 + buflen = (int)(ret - buf);
51967 + if (buflen >= 5)
51968 + prepend(&ret, &buflen, "/proc", 5);
51969 + else
51970 + ret = strcpy(buf, "<path too long>");
51971 + br_read_unlock(vfsmount_lock);
51972 + write_sequnlock(&rename_lock);
51973 + return ret;
51974 +}
51975 +
51976 +char *
51977 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51978 +{
51979 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51980 + PAGE_SIZE);
51981 +}
51982 +
51983 +char *
51984 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51985 +{
51986 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51987 + PAGE_SIZE);
51988 +}
51989 +
51990 +char *
51991 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51992 +{
51993 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51994 + PAGE_SIZE);
51995 +}
51996 +
51997 +char *
51998 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51999 +{
52000 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52001 + PAGE_SIZE);
52002 +}
52003 +
52004 +char *
52005 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52006 +{
52007 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52008 + PAGE_SIZE);
52009 +}
52010 +
52011 +__inline__ __u32
52012 +to_gr_audit(const __u32 reqmode)
52013 +{
52014 + /* masks off auditable permission flags, then shifts them to create
52015 + auditing flags, and adds the special case of append auditing if
52016 + we're requesting write */
52017 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52018 +}
52019 +
52020 +struct acl_subject_label *
52021 +lookup_subject_map(const struct acl_subject_label *userp)
52022 +{
52023 + unsigned int index = shash(userp, subj_map_set.s_size);
52024 + struct subject_map *match;
52025 +
52026 + match = subj_map_set.s_hash[index];
52027 +
52028 + while (match && match->user != userp)
52029 + match = match->next;
52030 +
52031 + if (match != NULL)
52032 + return match->kernel;
52033 + else
52034 + return NULL;
52035 +}
52036 +
52037 +static void
52038 +insert_subj_map_entry(struct subject_map *subjmap)
52039 +{
52040 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52041 + struct subject_map **curr;
52042 +
52043 + subjmap->prev = NULL;
52044 +
52045 + curr = &subj_map_set.s_hash[index];
52046 + if (*curr != NULL)
52047 + (*curr)->prev = subjmap;
52048 +
52049 + subjmap->next = *curr;
52050 + *curr = subjmap;
52051 +
52052 + return;
52053 +}
52054 +
52055 +static struct acl_role_label *
52056 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52057 + const gid_t gid)
52058 +{
52059 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52060 + struct acl_role_label *match;
52061 + struct role_allowed_ip *ipp;
52062 + unsigned int x;
52063 + u32 curr_ip = task->signal->curr_ip;
52064 +
52065 + task->signal->saved_ip = curr_ip;
52066 +
52067 + match = acl_role_set.r_hash[index];
52068 +
52069 + while (match) {
52070 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52071 + for (x = 0; x < match->domain_child_num; x++) {
52072 + if (match->domain_children[x] == uid)
52073 + goto found;
52074 + }
52075 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52076 + break;
52077 + match = match->next;
52078 + }
52079 +found:
52080 + if (match == NULL) {
52081 + try_group:
52082 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52083 + match = acl_role_set.r_hash[index];
52084 +
52085 + while (match) {
52086 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52087 + for (x = 0; x < match->domain_child_num; x++) {
52088 + if (match->domain_children[x] == gid)
52089 + goto found2;
52090 + }
52091 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52092 + break;
52093 + match = match->next;
52094 + }
52095 +found2:
52096 + if (match == NULL)
52097 + match = default_role;
52098 + if (match->allowed_ips == NULL)
52099 + return match;
52100 + else {
52101 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52102 + if (likely
52103 + ((ntohl(curr_ip) & ipp->netmask) ==
52104 + (ntohl(ipp->addr) & ipp->netmask)))
52105 + return match;
52106 + }
52107 + match = default_role;
52108 + }
52109 + } else if (match->allowed_ips == NULL) {
52110 + return match;
52111 + } else {
52112 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52113 + if (likely
52114 + ((ntohl(curr_ip) & ipp->netmask) ==
52115 + (ntohl(ipp->addr) & ipp->netmask)))
52116 + return match;
52117 + }
52118 + goto try_group;
52119 + }
52120 +
52121 + return match;
52122 +}
52123 +
52124 +struct acl_subject_label *
52125 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52126 + const struct acl_role_label *role)
52127 +{
52128 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52129 + struct acl_subject_label *match;
52130 +
52131 + match = role->subj_hash[index];
52132 +
52133 + while (match && (match->inode != ino || match->device != dev ||
52134 + (match->mode & GR_DELETED))) {
52135 + match = match->next;
52136 + }
52137 +
52138 + if (match && !(match->mode & GR_DELETED))
52139 + return match;
52140 + else
52141 + return NULL;
52142 +}
52143 +
52144 +struct acl_subject_label *
52145 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52146 + const struct acl_role_label *role)
52147 +{
52148 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52149 + struct acl_subject_label *match;
52150 +
52151 + match = role->subj_hash[index];
52152 +
52153 + while (match && (match->inode != ino || match->device != dev ||
52154 + !(match->mode & GR_DELETED))) {
52155 + match = match->next;
52156 + }
52157 +
52158 + if (match && (match->mode & GR_DELETED))
52159 + return match;
52160 + else
52161 + return NULL;
52162 +}
52163 +
52164 +static struct acl_object_label *
52165 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52166 + const struct acl_subject_label *subj)
52167 +{
52168 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52169 + struct acl_object_label *match;
52170 +
52171 + match = subj->obj_hash[index];
52172 +
52173 + while (match && (match->inode != ino || match->device != dev ||
52174 + (match->mode & GR_DELETED))) {
52175 + match = match->next;
52176 + }
52177 +
52178 + if (match && !(match->mode & GR_DELETED))
52179 + return match;
52180 + else
52181 + return NULL;
52182 +}
52183 +
52184 +static struct acl_object_label *
52185 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52186 + const struct acl_subject_label *subj)
52187 +{
52188 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52189 + struct acl_object_label *match;
52190 +
52191 + match = subj->obj_hash[index];
52192 +
52193 + while (match && (match->inode != ino || match->device != dev ||
52194 + !(match->mode & GR_DELETED))) {
52195 + match = match->next;
52196 + }
52197 +
52198 + if (match && (match->mode & GR_DELETED))
52199 + return match;
52200 +
52201 + match = subj->obj_hash[index];
52202 +
52203 + while (match && (match->inode != ino || match->device != dev ||
52204 + (match->mode & GR_DELETED))) {
52205 + match = match->next;
52206 + }
52207 +
52208 + if (match && !(match->mode & GR_DELETED))
52209 + return match;
52210 + else
52211 + return NULL;
52212 +}
52213 +
52214 +static struct name_entry *
52215 +lookup_name_entry(const char *name)
52216 +{
52217 + unsigned int len = strlen(name);
52218 + unsigned int key = full_name_hash(name, len);
52219 + unsigned int index = key % name_set.n_size;
52220 + struct name_entry *match;
52221 +
52222 + match = name_set.n_hash[index];
52223 +
52224 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52225 + match = match->next;
52226 +
52227 + return match;
52228 +}
52229 +
52230 +static struct name_entry *
52231 +lookup_name_entry_create(const char *name)
52232 +{
52233 + unsigned int len = strlen(name);
52234 + unsigned int key = full_name_hash(name, len);
52235 + unsigned int index = key % name_set.n_size;
52236 + struct name_entry *match;
52237 +
52238 + match = name_set.n_hash[index];
52239 +
52240 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52241 + !match->deleted))
52242 + match = match->next;
52243 +
52244 + if (match && match->deleted)
52245 + return match;
52246 +
52247 + match = name_set.n_hash[index];
52248 +
52249 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52250 + match->deleted))
52251 + match = match->next;
52252 +
52253 + if (match && !match->deleted)
52254 + return match;
52255 + else
52256 + return NULL;
52257 +}
52258 +
52259 +static struct inodev_entry *
52260 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52261 +{
52262 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52263 + struct inodev_entry *match;
52264 +
52265 + match = inodev_set.i_hash[index];
52266 +
52267 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52268 + match = match->next;
52269 +
52270 + return match;
52271 +}
52272 +
52273 +static void
52274 +insert_inodev_entry(struct inodev_entry *entry)
52275 +{
52276 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52277 + inodev_set.i_size);
52278 + struct inodev_entry **curr;
52279 +
52280 + entry->prev = NULL;
52281 +
52282 + curr = &inodev_set.i_hash[index];
52283 + if (*curr != NULL)
52284 + (*curr)->prev = entry;
52285 +
52286 + entry->next = *curr;
52287 + *curr = entry;
52288 +
52289 + return;
52290 +}
52291 +
52292 +static void
52293 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52294 +{
52295 + unsigned int index =
52296 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52297 + struct acl_role_label **curr;
52298 + struct acl_role_label *tmp, *tmp2;
52299 +
52300 + curr = &acl_role_set.r_hash[index];
52301 +
52302 + /* simple case, slot is empty, just set it to our role */
52303 + if (*curr == NULL) {
52304 + *curr = role;
52305 + } else {
52306 + /* example:
52307 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52308 + 2 -> 3
52309 + */
52310 + /* first check to see if we can already be reached via this slot */
52311 + tmp = *curr;
52312 + while (tmp && tmp != role)
52313 + tmp = tmp->next;
52314 + if (tmp == role) {
52315 + /* we don't need to add ourselves to this slot's chain */
52316 + return;
52317 + }
52318 + /* we need to add ourselves to this chain, two cases */
52319 + if (role->next == NULL) {
52320 + /* simple case, append the current chain to our role */
52321 + role->next = *curr;
52322 + *curr = role;
52323 + } else {
52324 + /* 1 -> 2 -> 3 -> 4
52325 + 2 -> 3 -> 4
52326 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52327 + */
52328 + /* trickier case: walk our role's chain until we find
52329 + the role for the start of the current slot's chain */
52330 + tmp = role;
52331 + tmp2 = *curr;
52332 + while (tmp->next && tmp->next != tmp2)
52333 + tmp = tmp->next;
52334 + if (tmp->next == tmp2) {
52335 + /* from example above, we found 3, so just
52336 + replace this slot's chain with ours */
52337 + *curr = role;
52338 + } else {
52339 + /* we didn't find a subset of our role's chain
52340 + in the current slot's chain, so append their
52341 + chain to ours, and set us as the first role in
52342 + the slot's chain
52343 +
52344 + we could fold this case with the case above,
52345 + but making it explicit for clarity
52346 + */
52347 + tmp->next = tmp2;
52348 + *curr = role;
52349 + }
52350 + }
52351 + }
52352 +
52353 + return;
52354 +}
52355 +
52356 +static void
52357 +insert_acl_role_label(struct acl_role_label *role)
52358 +{
52359 + int i;
52360 +
52361 + if (role_list == NULL) {
52362 + role_list = role;
52363 + role->prev = NULL;
52364 + } else {
52365 + role->prev = role_list;
52366 + role_list = role;
52367 + }
52368 +
52369 + /* used for hash chains */
52370 + role->next = NULL;
52371 +
52372 + if (role->roletype & GR_ROLE_DOMAIN) {
52373 + for (i = 0; i < role->domain_child_num; i++)
52374 + __insert_acl_role_label(role, role->domain_children[i]);
52375 + } else
52376 + __insert_acl_role_label(role, role->uidgid);
52377 +}
52378 +
52379 +static int
52380 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52381 +{
52382 + struct name_entry **curr, *nentry;
52383 + struct inodev_entry *ientry;
52384 + unsigned int len = strlen(name);
52385 + unsigned int key = full_name_hash(name, len);
52386 + unsigned int index = key % name_set.n_size;
52387 +
52388 + curr = &name_set.n_hash[index];
52389 +
52390 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52391 + curr = &((*curr)->next);
52392 +
52393 + if (*curr != NULL)
52394 + return 1;
52395 +
52396 + nentry = acl_alloc(sizeof (struct name_entry));
52397 + if (nentry == NULL)
52398 + return 0;
52399 + ientry = acl_alloc(sizeof (struct inodev_entry));
52400 + if (ientry == NULL)
52401 + return 0;
52402 + ientry->nentry = nentry;
52403 +
52404 + nentry->key = key;
52405 + nentry->name = name;
52406 + nentry->inode = inode;
52407 + nentry->device = device;
52408 + nentry->len = len;
52409 + nentry->deleted = deleted;
52410 +
52411 + nentry->prev = NULL;
52412 + curr = &name_set.n_hash[index];
52413 + if (*curr != NULL)
52414 + (*curr)->prev = nentry;
52415 + nentry->next = *curr;
52416 + *curr = nentry;
52417 +
52418 + /* insert us into the table searchable by inode/dev */
52419 + insert_inodev_entry(ientry);
52420 +
52421 + return 1;
52422 +}
52423 +
52424 +static void
52425 +insert_acl_obj_label(struct acl_object_label *obj,
52426 + struct acl_subject_label *subj)
52427 +{
52428 + unsigned int index =
52429 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52430 + struct acl_object_label **curr;
52431 +
52432 +
52433 + obj->prev = NULL;
52434 +
52435 + curr = &subj->obj_hash[index];
52436 + if (*curr != NULL)
52437 + (*curr)->prev = obj;
52438 +
52439 + obj->next = *curr;
52440 + *curr = obj;
52441 +
52442 + return;
52443 +}
52444 +
52445 +static void
52446 +insert_acl_subj_label(struct acl_subject_label *obj,
52447 + struct acl_role_label *role)
52448 +{
52449 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52450 + struct acl_subject_label **curr;
52451 +
52452 + obj->prev = NULL;
52453 +
52454 + curr = &role->subj_hash[index];
52455 + if (*curr != NULL)
52456 + (*curr)->prev = obj;
52457 +
52458 + obj->next = *curr;
52459 + *curr = obj;
52460 +
52461 + return;
52462 +}
52463 +
52464 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52465 +
52466 +static void *
52467 +create_table(__u32 * len, int elementsize)
52468 +{
52469 + unsigned int table_sizes[] = {
52470 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52471 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52472 + 4194301, 8388593, 16777213, 33554393, 67108859
52473 + };
52474 + void *newtable = NULL;
52475 + unsigned int pwr = 0;
52476 +
52477 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52478 + table_sizes[pwr] <= *len)
52479 + pwr++;
52480 +
52481 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52482 + return newtable;
52483 +
52484 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52485 + newtable =
52486 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52487 + else
52488 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52489 +
52490 + *len = table_sizes[pwr];
52491 +
52492 + return newtable;
52493 +}
52494 +
52495 +static int
52496 +init_variables(const struct gr_arg *arg)
52497 +{
52498 + struct task_struct *reaper = &init_task;
52499 + unsigned int stacksize;
52500 +
52501 + subj_map_set.s_size = arg->role_db.num_subjects;
52502 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52503 + name_set.n_size = arg->role_db.num_objects;
52504 + inodev_set.i_size = arg->role_db.num_objects;
52505 +
52506 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52507 + !name_set.n_size || !inodev_set.i_size)
52508 + return 1;
52509 +
52510 + if (!gr_init_uidset())
52511 + return 1;
52512 +
52513 + /* set up the stack that holds allocation info */
52514 +
52515 + stacksize = arg->role_db.num_pointers + 5;
52516 +
52517 + if (!acl_alloc_stack_init(stacksize))
52518 + return 1;
52519 +
52520 + /* grab reference for the real root dentry and vfsmount */
52521 + get_fs_root(reaper->fs, &real_root);
52522 +
52523 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52524 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52525 +#endif
52526 +
52527 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52528 + if (fakefs_obj_rw == NULL)
52529 + return 1;
52530 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52531 +
52532 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52533 + if (fakefs_obj_rwx == NULL)
52534 + return 1;
52535 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52536 +
52537 + subj_map_set.s_hash =
52538 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52539 + acl_role_set.r_hash =
52540 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52541 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52542 + inodev_set.i_hash =
52543 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52544 +
52545 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52546 + !name_set.n_hash || !inodev_set.i_hash)
52547 + return 1;
52548 +
52549 + memset(subj_map_set.s_hash, 0,
52550 + sizeof(struct subject_map *) * subj_map_set.s_size);
52551 + memset(acl_role_set.r_hash, 0,
52552 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52553 + memset(name_set.n_hash, 0,
52554 + sizeof (struct name_entry *) * name_set.n_size);
52555 + memset(inodev_set.i_hash, 0,
52556 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52557 +
52558 + return 0;
52559 +}
52560 +
52561 +/* free information not needed after startup
52562 + currently contains user->kernel pointer mappings for subjects
52563 +*/
52564 +
52565 +static void
52566 +free_init_variables(void)
52567 +{
52568 + __u32 i;
52569 +
52570 + if (subj_map_set.s_hash) {
52571 + for (i = 0; i < subj_map_set.s_size; i++) {
52572 + if (subj_map_set.s_hash[i]) {
52573 + kfree(subj_map_set.s_hash[i]);
52574 + subj_map_set.s_hash[i] = NULL;
52575 + }
52576 + }
52577 +
52578 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52579 + PAGE_SIZE)
52580 + kfree(subj_map_set.s_hash);
52581 + else
52582 + vfree(subj_map_set.s_hash);
52583 + }
52584 +
52585 + return;
52586 +}
52587 +
52588 +static void
52589 +free_variables(void)
52590 +{
52591 + struct acl_subject_label *s;
52592 + struct acl_role_label *r;
52593 + struct task_struct *task, *task2;
52594 + unsigned int x;
52595 +
52596 + gr_clear_learn_entries();
52597 +
52598 + read_lock(&tasklist_lock);
52599 + do_each_thread(task2, task) {
52600 + task->acl_sp_role = 0;
52601 + task->acl_role_id = 0;
52602 + task->acl = NULL;
52603 + task->role = NULL;
52604 + } while_each_thread(task2, task);
52605 + read_unlock(&tasklist_lock);
52606 +
52607 + /* release the reference to the real root dentry and vfsmount */
52608 + path_put(&real_root);
52609 + memset(&real_root, 0, sizeof(real_root));
52610 +
52611 + /* free all object hash tables */
52612 +
52613 + FOR_EACH_ROLE_START(r)
52614 + if (r->subj_hash == NULL)
52615 + goto next_role;
52616 + FOR_EACH_SUBJECT_START(r, s, x)
52617 + if (s->obj_hash == NULL)
52618 + break;
52619 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52620 + kfree(s->obj_hash);
52621 + else
52622 + vfree(s->obj_hash);
52623 + FOR_EACH_SUBJECT_END(s, x)
52624 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52625 + if (s->obj_hash == NULL)
52626 + break;
52627 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52628 + kfree(s->obj_hash);
52629 + else
52630 + vfree(s->obj_hash);
52631 + FOR_EACH_NESTED_SUBJECT_END(s)
52632 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52633 + kfree(r->subj_hash);
52634 + else
52635 + vfree(r->subj_hash);
52636 + r->subj_hash = NULL;
52637 +next_role:
52638 + FOR_EACH_ROLE_END(r)
52639 +
52640 + acl_free_all();
52641 +
52642 + if (acl_role_set.r_hash) {
52643 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52644 + PAGE_SIZE)
52645 + kfree(acl_role_set.r_hash);
52646 + else
52647 + vfree(acl_role_set.r_hash);
52648 + }
52649 + if (name_set.n_hash) {
52650 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52651 + PAGE_SIZE)
52652 + kfree(name_set.n_hash);
52653 + else
52654 + vfree(name_set.n_hash);
52655 + }
52656 +
52657 + if (inodev_set.i_hash) {
52658 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52659 + PAGE_SIZE)
52660 + kfree(inodev_set.i_hash);
52661 + else
52662 + vfree(inodev_set.i_hash);
52663 + }
52664 +
52665 + gr_free_uidset();
52666 +
52667 + memset(&name_set, 0, sizeof (struct name_db));
52668 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52669 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52670 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52671 +
52672 + default_role = NULL;
52673 + kernel_role = NULL;
52674 + role_list = NULL;
52675 +
52676 + return;
52677 +}
52678 +
52679 +static __u32
52680 +count_user_objs(struct acl_object_label *userp)
52681 +{
52682 + struct acl_object_label o_tmp;
52683 + __u32 num = 0;
52684 +
52685 + while (userp) {
52686 + if (copy_from_user(&o_tmp, userp,
52687 + sizeof (struct acl_object_label)))
52688 + break;
52689 +
52690 + userp = o_tmp.prev;
52691 + num++;
52692 + }
52693 +
52694 + return num;
52695 +}
52696 +
52697 +static struct acl_subject_label *
52698 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52699 +
52700 +static int
52701 +copy_user_glob(struct acl_object_label *obj)
52702 +{
52703 + struct acl_object_label *g_tmp, **guser;
52704 + unsigned int len;
52705 + char *tmp;
52706 +
52707 + if (obj->globbed == NULL)
52708 + return 0;
52709 +
52710 + guser = &obj->globbed;
52711 + while (*guser) {
52712 + g_tmp = (struct acl_object_label *)
52713 + acl_alloc(sizeof (struct acl_object_label));
52714 + if (g_tmp == NULL)
52715 + return -ENOMEM;
52716 +
52717 + if (copy_from_user(g_tmp, *guser,
52718 + sizeof (struct acl_object_label)))
52719 + return -EFAULT;
52720 +
52721 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52722 +
52723 + if (!len || len >= PATH_MAX)
52724 + return -EINVAL;
52725 +
52726 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52727 + return -ENOMEM;
52728 +
52729 + if (copy_from_user(tmp, g_tmp->filename, len))
52730 + return -EFAULT;
52731 + tmp[len-1] = '\0';
52732 + g_tmp->filename = tmp;
52733 +
52734 + *guser = g_tmp;
52735 + guser = &(g_tmp->next);
52736 + }
52737 +
52738 + return 0;
52739 +}
52740 +
52741 +static int
52742 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52743 + struct acl_role_label *role)
52744 +{
52745 + struct acl_object_label *o_tmp;
52746 + unsigned int len;
52747 + int ret;
52748 + char *tmp;
52749 +
52750 + while (userp) {
52751 + if ((o_tmp = (struct acl_object_label *)
52752 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52753 + return -ENOMEM;
52754 +
52755 + if (copy_from_user(o_tmp, userp,
52756 + sizeof (struct acl_object_label)))
52757 + return -EFAULT;
52758 +
52759 + userp = o_tmp->prev;
52760 +
52761 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52762 +
52763 + if (!len || len >= PATH_MAX)
52764 + return -EINVAL;
52765 +
52766 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52767 + return -ENOMEM;
52768 +
52769 + if (copy_from_user(tmp, o_tmp->filename, len))
52770 + return -EFAULT;
52771 + tmp[len-1] = '\0';
52772 + o_tmp->filename = tmp;
52773 +
52774 + insert_acl_obj_label(o_tmp, subj);
52775 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52776 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52777 + return -ENOMEM;
52778 +
52779 + ret = copy_user_glob(o_tmp);
52780 + if (ret)
52781 + return ret;
52782 +
52783 + if (o_tmp->nested) {
52784 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52785 + if (IS_ERR(o_tmp->nested))
52786 + return PTR_ERR(o_tmp->nested);
52787 +
52788 + /* insert into nested subject list */
52789 + o_tmp->nested->next = role->hash->first;
52790 + role->hash->first = o_tmp->nested;
52791 + }
52792 + }
52793 +
52794 + return 0;
52795 +}
52796 +
52797 +static __u32
52798 +count_user_subjs(struct acl_subject_label *userp)
52799 +{
52800 + struct acl_subject_label s_tmp;
52801 + __u32 num = 0;
52802 +
52803 + while (userp) {
52804 + if (copy_from_user(&s_tmp, userp,
52805 + sizeof (struct acl_subject_label)))
52806 + break;
52807 +
52808 + userp = s_tmp.prev;
52809 + /* do not count nested subjects against this count, since
52810 + they are not included in the hash table, but are
52811 + attached to objects. We have already counted
52812 + the subjects in userspace for the allocation
52813 + stack
52814 + */
52815 + if (!(s_tmp.mode & GR_NESTED))
52816 + num++;
52817 + }
52818 +
52819 + return num;
52820 +}
52821 +
52822 +static int
52823 +copy_user_allowedips(struct acl_role_label *rolep)
52824 +{
52825 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52826 +
52827 + ruserip = rolep->allowed_ips;
52828 +
52829 + while (ruserip) {
52830 + rlast = rtmp;
52831 +
52832 + if ((rtmp = (struct role_allowed_ip *)
52833 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52834 + return -ENOMEM;
52835 +
52836 + if (copy_from_user(rtmp, ruserip,
52837 + sizeof (struct role_allowed_ip)))
52838 + return -EFAULT;
52839 +
52840 + ruserip = rtmp->prev;
52841 +
52842 + if (!rlast) {
52843 + rtmp->prev = NULL;
52844 + rolep->allowed_ips = rtmp;
52845 + } else {
52846 + rlast->next = rtmp;
52847 + rtmp->prev = rlast;
52848 + }
52849 +
52850 + if (!ruserip)
52851 + rtmp->next = NULL;
52852 + }
52853 +
52854 + return 0;
52855 +}
52856 +
52857 +static int
52858 +copy_user_transitions(struct acl_role_label *rolep)
52859 +{
52860 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52861 +
52862 + unsigned int len;
52863 + char *tmp;
52864 +
52865 + rusertp = rolep->transitions;
52866 +
52867 + while (rusertp) {
52868 + rlast = rtmp;
52869 +
52870 + if ((rtmp = (struct role_transition *)
52871 + acl_alloc(sizeof (struct role_transition))) == NULL)
52872 + return -ENOMEM;
52873 +
52874 + if (copy_from_user(rtmp, rusertp,
52875 + sizeof (struct role_transition)))
52876 + return -EFAULT;
52877 +
52878 + rusertp = rtmp->prev;
52879 +
52880 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52881 +
52882 + if (!len || len >= GR_SPROLE_LEN)
52883 + return -EINVAL;
52884 +
52885 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52886 + return -ENOMEM;
52887 +
52888 + if (copy_from_user(tmp, rtmp->rolename, len))
52889 + return -EFAULT;
52890 + tmp[len-1] = '\0';
52891 + rtmp->rolename = tmp;
52892 +
52893 + if (!rlast) {
52894 + rtmp->prev = NULL;
52895 + rolep->transitions = rtmp;
52896 + } else {
52897 + rlast->next = rtmp;
52898 + rtmp->prev = rlast;
52899 + }
52900 +
52901 + if (!rusertp)
52902 + rtmp->next = NULL;
52903 + }
52904 +
52905 + return 0;
52906 +}
52907 +
52908 +static struct acl_subject_label *
52909 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52910 +{
52911 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52912 + unsigned int len;
52913 + char *tmp;
52914 + __u32 num_objs;
52915 + struct acl_ip_label **i_tmp, *i_utmp2;
52916 + struct gr_hash_struct ghash;
52917 + struct subject_map *subjmap;
52918 + unsigned int i_num;
52919 + int err;
52920 +
52921 + s_tmp = lookup_subject_map(userp);
52922 +
52923 + /* we've already copied this subject into the kernel, just return
52924 + the reference to it, and don't copy it over again
52925 + */
52926 + if (s_tmp)
52927 + return(s_tmp);
52928 +
52929 + if ((s_tmp = (struct acl_subject_label *)
52930 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52931 + return ERR_PTR(-ENOMEM);
52932 +
52933 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52934 + if (subjmap == NULL)
52935 + return ERR_PTR(-ENOMEM);
52936 +
52937 + subjmap->user = userp;
52938 + subjmap->kernel = s_tmp;
52939 + insert_subj_map_entry(subjmap);
52940 +
52941 + if (copy_from_user(s_tmp, userp,
52942 + sizeof (struct acl_subject_label)))
52943 + return ERR_PTR(-EFAULT);
52944 +
52945 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52946 +
52947 + if (!len || len >= PATH_MAX)
52948 + return ERR_PTR(-EINVAL);
52949 +
52950 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52951 + return ERR_PTR(-ENOMEM);
52952 +
52953 + if (copy_from_user(tmp, s_tmp->filename, len))
52954 + return ERR_PTR(-EFAULT);
52955 + tmp[len-1] = '\0';
52956 + s_tmp->filename = tmp;
52957 +
52958 + if (!strcmp(s_tmp->filename, "/"))
52959 + role->root_label = s_tmp;
52960 +
52961 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52962 + return ERR_PTR(-EFAULT);
52963 +
52964 + /* copy user and group transition tables */
52965 +
52966 + if (s_tmp->user_trans_num) {
52967 + uid_t *uidlist;
52968 +
52969 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52970 + if (uidlist == NULL)
52971 + return ERR_PTR(-ENOMEM);
52972 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52973 + return ERR_PTR(-EFAULT);
52974 +
52975 + s_tmp->user_transitions = uidlist;
52976 + }
52977 +
52978 + if (s_tmp->group_trans_num) {
52979 + gid_t *gidlist;
52980 +
52981 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52982 + if (gidlist == NULL)
52983 + return ERR_PTR(-ENOMEM);
52984 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52985 + return ERR_PTR(-EFAULT);
52986 +
52987 + s_tmp->group_transitions = gidlist;
52988 + }
52989 +
52990 + /* set up object hash table */
52991 + num_objs = count_user_objs(ghash.first);
52992 +
52993 + s_tmp->obj_hash_size = num_objs;
52994 + s_tmp->obj_hash =
52995 + (struct acl_object_label **)
52996 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52997 +
52998 + if (!s_tmp->obj_hash)
52999 + return ERR_PTR(-ENOMEM);
53000 +
53001 + memset(s_tmp->obj_hash, 0,
53002 + s_tmp->obj_hash_size *
53003 + sizeof (struct acl_object_label *));
53004 +
53005 + /* add in objects */
53006 + err = copy_user_objs(ghash.first, s_tmp, role);
53007 +
53008 + if (err)
53009 + return ERR_PTR(err);
53010 +
53011 + /* set pointer for parent subject */
53012 + if (s_tmp->parent_subject) {
53013 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
53014 +
53015 + if (IS_ERR(s_tmp2))
53016 + return s_tmp2;
53017 +
53018 + s_tmp->parent_subject = s_tmp2;
53019 + }
53020 +
53021 + /* add in ip acls */
53022 +
53023 + if (!s_tmp->ip_num) {
53024 + s_tmp->ips = NULL;
53025 + goto insert;
53026 + }
53027 +
53028 + i_tmp =
53029 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53030 + sizeof (struct acl_ip_label *));
53031 +
53032 + if (!i_tmp)
53033 + return ERR_PTR(-ENOMEM);
53034 +
53035 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53036 + *(i_tmp + i_num) =
53037 + (struct acl_ip_label *)
53038 + acl_alloc(sizeof (struct acl_ip_label));
53039 + if (!*(i_tmp + i_num))
53040 + return ERR_PTR(-ENOMEM);
53041 +
53042 + if (copy_from_user
53043 + (&i_utmp2, s_tmp->ips + i_num,
53044 + sizeof (struct acl_ip_label *)))
53045 + return ERR_PTR(-EFAULT);
53046 +
53047 + if (copy_from_user
53048 + (*(i_tmp + i_num), i_utmp2,
53049 + sizeof (struct acl_ip_label)))
53050 + return ERR_PTR(-EFAULT);
53051 +
53052 + if ((*(i_tmp + i_num))->iface == NULL)
53053 + continue;
53054 +
53055 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53056 + if (!len || len >= IFNAMSIZ)
53057 + return ERR_PTR(-EINVAL);
53058 + tmp = acl_alloc(len);
53059 + if (tmp == NULL)
53060 + return ERR_PTR(-ENOMEM);
53061 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53062 + return ERR_PTR(-EFAULT);
53063 + (*(i_tmp + i_num))->iface = tmp;
53064 + }
53065 +
53066 + s_tmp->ips = i_tmp;
53067 +
53068 +insert:
53069 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53070 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53071 + return ERR_PTR(-ENOMEM);
53072 +
53073 + return s_tmp;
53074 +}
53075 +
53076 +static int
53077 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53078 +{
53079 + struct acl_subject_label s_pre;
53080 + struct acl_subject_label * ret;
53081 + int err;
53082 +
53083 + while (userp) {
53084 + if (copy_from_user(&s_pre, userp,
53085 + sizeof (struct acl_subject_label)))
53086 + return -EFAULT;
53087 +
53088 + /* do not add nested subjects here, add
53089 + while parsing objects
53090 + */
53091 +
53092 + if (s_pre.mode & GR_NESTED) {
53093 + userp = s_pre.prev;
53094 + continue;
53095 + }
53096 +
53097 + ret = do_copy_user_subj(userp, role);
53098 +
53099 + err = PTR_ERR(ret);
53100 + if (IS_ERR(ret))
53101 + return err;
53102 +
53103 + insert_acl_subj_label(ret, role);
53104 +
53105 + userp = s_pre.prev;
53106 + }
53107 +
53108 + return 0;
53109 +}
53110 +
53111 +static int
53112 +copy_user_acl(struct gr_arg *arg)
53113 +{
53114 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53115 + struct sprole_pw *sptmp;
53116 + struct gr_hash_struct *ghash;
53117 + uid_t *domainlist;
53118 + unsigned int r_num;
53119 + unsigned int len;
53120 + char *tmp;
53121 + int err = 0;
53122 + __u16 i;
53123 + __u32 num_subjs;
53124 +
53125 + /* we need a default and kernel role */
53126 + if (arg->role_db.num_roles < 2)
53127 + return -EINVAL;
53128 +
53129 + /* copy special role authentication info from userspace */
53130 +
53131 + num_sprole_pws = arg->num_sprole_pws;
53132 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53133 +
53134 + if (!acl_special_roles && num_sprole_pws)
53135 + return -ENOMEM;
53136 +
53137 + for (i = 0; i < num_sprole_pws; i++) {
53138 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53139 + if (!sptmp)
53140 + return -ENOMEM;
53141 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53142 + sizeof (struct sprole_pw)))
53143 + return -EFAULT;
53144 +
53145 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53146 +
53147 + if (!len || len >= GR_SPROLE_LEN)
53148 + return -EINVAL;
53149 +
53150 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53151 + return -ENOMEM;
53152 +
53153 + if (copy_from_user(tmp, sptmp->rolename, len))
53154 + return -EFAULT;
53155 +
53156 + tmp[len-1] = '\0';
53157 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53158 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53159 +#endif
53160 + sptmp->rolename = tmp;
53161 + acl_special_roles[i] = sptmp;
53162 + }
53163 +
53164 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53165 +
53166 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53167 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53168 +
53169 + if (!r_tmp)
53170 + return -ENOMEM;
53171 +
53172 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53173 + sizeof (struct acl_role_label *)))
53174 + return -EFAULT;
53175 +
53176 + if (copy_from_user(r_tmp, r_utmp2,
53177 + sizeof (struct acl_role_label)))
53178 + return -EFAULT;
53179 +
53180 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53181 +
53182 + if (!len || len >= PATH_MAX)
53183 + return -EINVAL;
53184 +
53185 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53186 + return -ENOMEM;
53187 +
53188 + if (copy_from_user(tmp, r_tmp->rolename, len))
53189 + return -EFAULT;
53190 +
53191 + tmp[len-1] = '\0';
53192 + r_tmp->rolename = tmp;
53193 +
53194 + if (!strcmp(r_tmp->rolename, "default")
53195 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53196 + default_role = r_tmp;
53197 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53198 + kernel_role = r_tmp;
53199 + }
53200 +
53201 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53202 + return -ENOMEM;
53203 +
53204 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53205 + return -EFAULT;
53206 +
53207 + r_tmp->hash = ghash;
53208 +
53209 + num_subjs = count_user_subjs(r_tmp->hash->first);
53210 +
53211 + r_tmp->subj_hash_size = num_subjs;
53212 + r_tmp->subj_hash =
53213 + (struct acl_subject_label **)
53214 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53215 +
53216 + if (!r_tmp->subj_hash)
53217 + return -ENOMEM;
53218 +
53219 + err = copy_user_allowedips(r_tmp);
53220 + if (err)
53221 + return err;
53222 +
53223 + /* copy domain info */
53224 + if (r_tmp->domain_children != NULL) {
53225 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53226 + if (domainlist == NULL)
53227 + return -ENOMEM;
53228 +
53229 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53230 + return -EFAULT;
53231 +
53232 + r_tmp->domain_children = domainlist;
53233 + }
53234 +
53235 + err = copy_user_transitions(r_tmp);
53236 + if (err)
53237 + return err;
53238 +
53239 + memset(r_tmp->subj_hash, 0,
53240 + r_tmp->subj_hash_size *
53241 + sizeof (struct acl_subject_label *));
53242 +
53243 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
53244 +
53245 + if (err)
53246 + return err;
53247 +
53248 + /* set nested subject list to null */
53249 + r_tmp->hash->first = NULL;
53250 +
53251 + insert_acl_role_label(r_tmp);
53252 + }
53253 +
53254 + if (default_role == NULL || kernel_role == NULL)
53255 + return -EINVAL;
53256 +
53257 + return err;
53258 +}
53259 +
53260 +static int
53261 +gracl_init(struct gr_arg *args)
53262 +{
53263 + int error = 0;
53264 +
53265 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53266 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53267 +
53268 + if (init_variables(args)) {
53269 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53270 + error = -ENOMEM;
53271 + free_variables();
53272 + goto out;
53273 + }
53274 +
53275 + error = copy_user_acl(args);
53276 + free_init_variables();
53277 + if (error) {
53278 + free_variables();
53279 + goto out;
53280 + }
53281 +
53282 + if ((error = gr_set_acls(0))) {
53283 + free_variables();
53284 + goto out;
53285 + }
53286 +
53287 + pax_open_kernel();
53288 + gr_status |= GR_READY;
53289 + pax_close_kernel();
53290 +
53291 + out:
53292 + return error;
53293 +}
53294 +
53295 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53296 +
53297 +static int
53298 +glob_match(const char *p, const char *n)
53299 +{
53300 + char c;
53301 +
53302 + while ((c = *p++) != '\0') {
53303 + switch (c) {
53304 + case '?':
53305 + if (*n == '\0')
53306 + return 1;
53307 + else if (*n == '/')
53308 + return 1;
53309 + break;
53310 + case '\\':
53311 + if (*n != c)
53312 + return 1;
53313 + break;
53314 + case '*':
53315 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53316 + if (*n == '/')
53317 + return 1;
53318 + else if (c == '?') {
53319 + if (*n == '\0')
53320 + return 1;
53321 + else
53322 + ++n;
53323 + }
53324 + }
53325 + if (c == '\0') {
53326 + return 0;
53327 + } else {
53328 + const char *endp;
53329 +
53330 + if ((endp = strchr(n, '/')) == NULL)
53331 + endp = n + strlen(n);
53332 +
53333 + if (c == '[') {
53334 + for (--p; n < endp; ++n)
53335 + if (!glob_match(p, n))
53336 + return 0;
53337 + } else if (c == '/') {
53338 + while (*n != '\0' && *n != '/')
53339 + ++n;
53340 + if (*n == '/' && !glob_match(p, n + 1))
53341 + return 0;
53342 + } else {
53343 + for (--p; n < endp; ++n)
53344 + if (*n == c && !glob_match(p, n))
53345 + return 0;
53346 + }
53347 +
53348 + return 1;
53349 + }
53350 + case '[':
53351 + {
53352 + int not;
53353 + char cold;
53354 +
53355 + if (*n == '\0' || *n == '/')
53356 + return 1;
53357 +
53358 + not = (*p == '!' || *p == '^');
53359 + if (not)
53360 + ++p;
53361 +
53362 + c = *p++;
53363 + for (;;) {
53364 + unsigned char fn = (unsigned char)*n;
53365 +
53366 + if (c == '\0')
53367 + return 1;
53368 + else {
53369 + if (c == fn)
53370 + goto matched;
53371 + cold = c;
53372 + c = *p++;
53373 +
53374 + if (c == '-' && *p != ']') {
53375 + unsigned char cend = *p++;
53376 +
53377 + if (cend == '\0')
53378 + return 1;
53379 +
53380 + if (cold <= fn && fn <= cend)
53381 + goto matched;
53382 +
53383 + c = *p++;
53384 + }
53385 + }
53386 +
53387 + if (c == ']')
53388 + break;
53389 + }
53390 + if (!not)
53391 + return 1;
53392 + break;
53393 + matched:
53394 + while (c != ']') {
53395 + if (c == '\0')
53396 + return 1;
53397 +
53398 + c = *p++;
53399 + }
53400 + if (not)
53401 + return 1;
53402 + }
53403 + break;
53404 + default:
53405 + if (c != *n)
53406 + return 1;
53407 + }
53408 +
53409 + ++n;
53410 + }
53411 +
53412 + if (*n == '\0')
53413 + return 0;
53414 +
53415 + if (*n == '/')
53416 + return 0;
53417 +
53418 + return 1;
53419 +}
53420 +
53421 +static struct acl_object_label *
53422 +chk_glob_label(struct acl_object_label *globbed,
53423 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53424 +{
53425 + struct acl_object_label *tmp;
53426 +
53427 + if (*path == NULL)
53428 + *path = gr_to_filename_nolock(dentry, mnt);
53429 +
53430 + tmp = globbed;
53431 +
53432 + while (tmp) {
53433 + if (!glob_match(tmp->filename, *path))
53434 + return tmp;
53435 + tmp = tmp->next;
53436 + }
53437 +
53438 + return NULL;
53439 +}
53440 +
53441 +static struct acl_object_label *
53442 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53443 + const ino_t curr_ino, const dev_t curr_dev,
53444 + const struct acl_subject_label *subj, char **path, const int checkglob)
53445 +{
53446 + struct acl_subject_label *tmpsubj;
53447 + struct acl_object_label *retval;
53448 + struct acl_object_label *retval2;
53449 +
53450 + tmpsubj = (struct acl_subject_label *) subj;
53451 + read_lock(&gr_inode_lock);
53452 + do {
53453 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53454 + if (retval) {
53455 + if (checkglob && retval->globbed) {
53456 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53457 + if (retval2)
53458 + retval = retval2;
53459 + }
53460 + break;
53461 + }
53462 + } while ((tmpsubj = tmpsubj->parent_subject));
53463 + read_unlock(&gr_inode_lock);
53464 +
53465 + return retval;
53466 +}
53467 +
53468 +static __inline__ struct acl_object_label *
53469 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53470 + struct dentry *curr_dentry,
53471 + const struct acl_subject_label *subj, char **path, const int checkglob)
53472 +{
53473 + int newglob = checkglob;
53474 + ino_t inode;
53475 + dev_t device;
53476 +
53477 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53478 + as we don't want a / * rule to match instead of the / object
53479 + don't do this for create lookups that call this function though, since they're looking up
53480 + on the parent and thus need globbing checks on all paths
53481 + */
53482 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53483 + newglob = GR_NO_GLOB;
53484 +
53485 + spin_lock(&curr_dentry->d_lock);
53486 + inode = curr_dentry->d_inode->i_ino;
53487 + device = __get_dev(curr_dentry);
53488 + spin_unlock(&curr_dentry->d_lock);
53489 +
53490 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53491 +}
53492 +
53493 +static struct acl_object_label *
53494 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53495 + const struct acl_subject_label *subj, char *path, const int checkglob)
53496 +{
53497 + struct dentry *dentry = (struct dentry *) l_dentry;
53498 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53499 + struct mount *real_mnt = real_mount(mnt);
53500 + struct acl_object_label *retval;
53501 + struct dentry *parent;
53502 +
53503 + write_seqlock(&rename_lock);
53504 + br_read_lock(vfsmount_lock);
53505 +
53506 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53507 +#ifdef CONFIG_NET
53508 + mnt == sock_mnt ||
53509 +#endif
53510 +#ifdef CONFIG_HUGETLBFS
53511 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53512 +#endif
53513 + /* ignore Eric Biederman */
53514 + IS_PRIVATE(l_dentry->d_inode))) {
53515 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53516 + goto out;
53517 + }
53518 +
53519 + for (;;) {
53520 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53521 + break;
53522 +
53523 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53524 + if (!mnt_has_parent(real_mnt))
53525 + break;
53526 +
53527 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53528 + if (retval != NULL)
53529 + goto out;
53530 +
53531 + dentry = real_mnt->mnt_mountpoint;
53532 + real_mnt = real_mnt->mnt_parent;
53533 + mnt = &real_mnt->mnt;
53534 + continue;
53535 + }
53536 +
53537 + parent = dentry->d_parent;
53538 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53539 + if (retval != NULL)
53540 + goto out;
53541 +
53542 + dentry = parent;
53543 + }
53544 +
53545 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53546 +
53547 + /* real_root is pinned so we don't have to hold a reference */
53548 + if (retval == NULL)
53549 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53550 +out:
53551 + br_read_unlock(vfsmount_lock);
53552 + write_sequnlock(&rename_lock);
53553 +
53554 + BUG_ON(retval == NULL);
53555 +
53556 + return retval;
53557 +}
53558 +
53559 +static __inline__ struct acl_object_label *
53560 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53561 + const struct acl_subject_label *subj)
53562 +{
53563 + char *path = NULL;
53564 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53565 +}
53566 +
53567 +static __inline__ struct acl_object_label *
53568 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53569 + const struct acl_subject_label *subj)
53570 +{
53571 + char *path = NULL;
53572 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53573 +}
53574 +
53575 +static __inline__ struct acl_object_label *
53576 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53577 + const struct acl_subject_label *subj, char *path)
53578 +{
53579 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53580 +}
53581 +
53582 +static struct acl_subject_label *
53583 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53584 + const struct acl_role_label *role)
53585 +{
53586 + struct dentry *dentry = (struct dentry *) l_dentry;
53587 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53588 + struct mount *real_mnt = real_mount(mnt);
53589 + struct acl_subject_label *retval;
53590 + struct dentry *parent;
53591 +
53592 + write_seqlock(&rename_lock);
53593 + br_read_lock(vfsmount_lock);
53594 +
53595 + for (;;) {
53596 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53597 + break;
53598 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53599 + if (!mnt_has_parent(real_mnt))
53600 + break;
53601 +
53602 + spin_lock(&dentry->d_lock);
53603 + read_lock(&gr_inode_lock);
53604 + retval =
53605 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53606 + __get_dev(dentry), role);
53607 + read_unlock(&gr_inode_lock);
53608 + spin_unlock(&dentry->d_lock);
53609 + if (retval != NULL)
53610 + goto out;
53611 +
53612 + dentry = real_mnt->mnt_mountpoint;
53613 + real_mnt = real_mnt->mnt_parent;
53614 + mnt = &real_mnt->mnt;
53615 + continue;
53616 + }
53617 +
53618 + spin_lock(&dentry->d_lock);
53619 + read_lock(&gr_inode_lock);
53620 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53621 + __get_dev(dentry), role);
53622 + read_unlock(&gr_inode_lock);
53623 + parent = dentry->d_parent;
53624 + spin_unlock(&dentry->d_lock);
53625 +
53626 + if (retval != NULL)
53627 + goto out;
53628 +
53629 + dentry = parent;
53630 + }
53631 +
53632 + spin_lock(&dentry->d_lock);
53633 + read_lock(&gr_inode_lock);
53634 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53635 + __get_dev(dentry), role);
53636 + read_unlock(&gr_inode_lock);
53637 + spin_unlock(&dentry->d_lock);
53638 +
53639 + if (unlikely(retval == NULL)) {
53640 + /* real_root is pinned, we don't need to hold a reference */
53641 + read_lock(&gr_inode_lock);
53642 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53643 + __get_dev(real_root.dentry), role);
53644 + read_unlock(&gr_inode_lock);
53645 + }
53646 +out:
53647 + br_read_unlock(vfsmount_lock);
53648 + write_sequnlock(&rename_lock);
53649 +
53650 + BUG_ON(retval == NULL);
53651 +
53652 + return retval;
53653 +}
53654 +
53655 +static void
53656 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53657 +{
53658 + struct task_struct *task = current;
53659 + const struct cred *cred = current_cred();
53660 +
53661 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53662 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53663 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53664 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53665 +
53666 + return;
53667 +}
53668 +
53669 +static void
53670 +gr_log_learn_sysctl(const char *path, const __u32 mode)
53671 +{
53672 + struct task_struct *task = current;
53673 + const struct cred *cred = current_cred();
53674 +
53675 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53676 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53677 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53678 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
53679 +
53680 + return;
53681 +}
53682 +
53683 +static void
53684 +gr_log_learn_id_change(const char type, const unsigned int real,
53685 + const unsigned int effective, const unsigned int fs)
53686 +{
53687 + struct task_struct *task = current;
53688 + const struct cred *cred = current_cred();
53689 +
53690 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53691 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53692 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53693 + type, real, effective, fs, &task->signal->saved_ip);
53694 +
53695 + return;
53696 +}
53697 +
53698 +__u32
53699 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53700 + const struct vfsmount * mnt)
53701 +{
53702 + __u32 retval = mode;
53703 + struct acl_subject_label *curracl;
53704 + struct acl_object_label *currobj;
53705 +
53706 + if (unlikely(!(gr_status & GR_READY)))
53707 + return (mode & ~GR_AUDITS);
53708 +
53709 + curracl = current->acl;
53710 +
53711 + currobj = chk_obj_label(dentry, mnt, curracl);
53712 + retval = currobj->mode & mode;
53713 +
53714 + /* if we're opening a specified transfer file for writing
53715 + (e.g. /dev/initctl), then transfer our role to init
53716 + */
53717 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53718 + current->role->roletype & GR_ROLE_PERSIST)) {
53719 + struct task_struct *task = init_pid_ns.child_reaper;
53720 +
53721 + if (task->role != current->role) {
53722 + task->acl_sp_role = 0;
53723 + task->acl_role_id = current->acl_role_id;
53724 + task->role = current->role;
53725 + rcu_read_lock();
53726 + read_lock(&grsec_exec_file_lock);
53727 + gr_apply_subject_to_task(task);
53728 + read_unlock(&grsec_exec_file_lock);
53729 + rcu_read_unlock();
53730 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53731 + }
53732 + }
53733 +
53734 + if (unlikely
53735 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53736 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53737 + __u32 new_mode = mode;
53738 +
53739 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53740 +
53741 + retval = new_mode;
53742 +
53743 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53744 + new_mode |= GR_INHERIT;
53745 +
53746 + if (!(mode & GR_NOLEARN))
53747 + gr_log_learn(dentry, mnt, new_mode);
53748 + }
53749 +
53750 + return retval;
53751 +}
53752 +
53753 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53754 + const struct dentry *parent,
53755 + const struct vfsmount *mnt)
53756 +{
53757 + struct name_entry *match;
53758 + struct acl_object_label *matchpo;
53759 + struct acl_subject_label *curracl;
53760 + char *path;
53761 +
53762 + if (unlikely(!(gr_status & GR_READY)))
53763 + return NULL;
53764 +
53765 + preempt_disable();
53766 + path = gr_to_filename_rbac(new_dentry, mnt);
53767 + match = lookup_name_entry_create(path);
53768 +
53769 + curracl = current->acl;
53770 +
53771 + if (match) {
53772 + read_lock(&gr_inode_lock);
53773 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53774 + read_unlock(&gr_inode_lock);
53775 +
53776 + if (matchpo) {
53777 + preempt_enable();
53778 + return matchpo;
53779 + }
53780 + }
53781 +
53782 + // lookup parent
53783 +
53784 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53785 +
53786 + preempt_enable();
53787 + return matchpo;
53788 +}
53789 +
53790 +__u32
53791 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53792 + const struct vfsmount * mnt, const __u32 mode)
53793 +{
53794 + struct acl_object_label *matchpo;
53795 + __u32 retval;
53796 +
53797 + if (unlikely(!(gr_status & GR_READY)))
53798 + return (mode & ~GR_AUDITS);
53799 +
53800 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53801 +
53802 + retval = matchpo->mode & mode;
53803 +
53804 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53805 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53806 + __u32 new_mode = mode;
53807 +
53808 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53809 +
53810 + gr_log_learn(new_dentry, mnt, new_mode);
53811 + return new_mode;
53812 + }
53813 +
53814 + return retval;
53815 +}
53816 +
53817 +__u32
53818 +gr_check_link(const struct dentry * new_dentry,
53819 + const struct dentry * parent_dentry,
53820 + const struct vfsmount * parent_mnt,
53821 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53822 +{
53823 + struct acl_object_label *obj;
53824 + __u32 oldmode, newmode;
53825 + __u32 needmode;
53826 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53827 + GR_DELETE | GR_INHERIT;
53828 +
53829 + if (unlikely(!(gr_status & GR_READY)))
53830 + return (GR_CREATE | GR_LINK);
53831 +
53832 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53833 + oldmode = obj->mode;
53834 +
53835 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53836 + newmode = obj->mode;
53837 +
53838 + needmode = newmode & checkmodes;
53839 +
53840 + // old name for hardlink must have at least the permissions of the new name
53841 + if ((oldmode & needmode) != needmode)
53842 + goto bad;
53843 +
53844 + // if old name had restrictions/auditing, make sure the new name does as well
53845 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53846 +
53847 + // don't allow hardlinking of suid/sgid files without permission
53848 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53849 + needmode |= GR_SETID;
53850 +
53851 + if ((newmode & needmode) != needmode)
53852 + goto bad;
53853 +
53854 + // enforce minimum permissions
53855 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53856 + return newmode;
53857 +bad:
53858 + needmode = oldmode;
53859 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
53860 + needmode |= GR_SETID;
53861 +
53862 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53863 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53864 + return (GR_CREATE | GR_LINK);
53865 + } else if (newmode & GR_SUPPRESS)
53866 + return GR_SUPPRESS;
53867 + else
53868 + return 0;
53869 +}
53870 +
53871 +int
53872 +gr_check_hidden_task(const struct task_struct *task)
53873 +{
53874 + if (unlikely(!(gr_status & GR_READY)))
53875 + return 0;
53876 +
53877 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53878 + return 1;
53879 +
53880 + return 0;
53881 +}
53882 +
53883 +int
53884 +gr_check_protected_task(const struct task_struct *task)
53885 +{
53886 + if (unlikely(!(gr_status & GR_READY) || !task))
53887 + return 0;
53888 +
53889 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53890 + task->acl != current->acl)
53891 + return 1;
53892 +
53893 + return 0;
53894 +}
53895 +
53896 +int
53897 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53898 +{
53899 + struct task_struct *p;
53900 + int ret = 0;
53901 +
53902 + if (unlikely(!(gr_status & GR_READY) || !pid))
53903 + return ret;
53904 +
53905 + read_lock(&tasklist_lock);
53906 + do_each_pid_task(pid, type, p) {
53907 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53908 + p->acl != current->acl) {
53909 + ret = 1;
53910 + goto out;
53911 + }
53912 + } while_each_pid_task(pid, type, p);
53913 +out:
53914 + read_unlock(&tasklist_lock);
53915 +
53916 + return ret;
53917 +}
53918 +
53919 +void
53920 +gr_copy_label(struct task_struct *tsk)
53921 +{
53922 + /* plain copying of fields is already done by dup_task_struct */
53923 + tsk->signal->used_accept = 0;
53924 + tsk->acl_sp_role = 0;
53925 + //tsk->acl_role_id = current->acl_role_id;
53926 + //tsk->acl = current->acl;
53927 + //tsk->role = current->role;
53928 + tsk->signal->curr_ip = current->signal->curr_ip;
53929 + tsk->signal->saved_ip = current->signal->saved_ip;
53930 + if (current->exec_file)
53931 + get_file(current->exec_file);
53932 + //tsk->exec_file = current->exec_file;
53933 + //tsk->is_writable = current->is_writable;
53934 + if (unlikely(current->signal->used_accept)) {
53935 + current->signal->curr_ip = 0;
53936 + current->signal->saved_ip = 0;
53937 + }
53938 +
53939 + return;
53940 +}
53941 +
53942 +static void
53943 +gr_set_proc_res(struct task_struct *task)
53944 +{
53945 + struct acl_subject_label *proc;
53946 + unsigned short i;
53947 +
53948 + proc = task->acl;
53949 +
53950 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53951 + return;
53952 +
53953 + for (i = 0; i < RLIM_NLIMITS; i++) {
53954 + if (!(proc->resmask & (1 << i)))
53955 + continue;
53956 +
53957 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53958 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53959 + }
53960 +
53961 + return;
53962 +}
53963 +
53964 +extern int __gr_process_user_ban(struct user_struct *user);
53965 +
53966 +int
53967 +gr_check_user_change(int real, int effective, int fs)
53968 +{
53969 + unsigned int i;
53970 + __u16 num;
53971 + uid_t *uidlist;
53972 + int curuid;
53973 + int realok = 0;
53974 + int effectiveok = 0;
53975 + int fsok = 0;
53976 +
53977 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53978 + struct user_struct *user;
53979 +
53980 + if (real == -1)
53981 + goto skipit;
53982 +
53983 + user = find_user(real);
53984 + if (user == NULL)
53985 + goto skipit;
53986 +
53987 + if (__gr_process_user_ban(user)) {
53988 + /* for find_user */
53989 + free_uid(user);
53990 + return 1;
53991 + }
53992 +
53993 + /* for find_user */
53994 + free_uid(user);
53995 +
53996 +skipit:
53997 +#endif
53998 +
53999 + if (unlikely(!(gr_status & GR_READY)))
54000 + return 0;
54001 +
54002 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54003 + gr_log_learn_id_change('u', real, effective, fs);
54004 +
54005 + num = current->acl->user_trans_num;
54006 + uidlist = current->acl->user_transitions;
54007 +
54008 + if (uidlist == NULL)
54009 + return 0;
54010 +
54011 + if (real == -1)
54012 + realok = 1;
54013 + if (effective == -1)
54014 + effectiveok = 1;
54015 + if (fs == -1)
54016 + fsok = 1;
54017 +
54018 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54019 + for (i = 0; i < num; i++) {
54020 + curuid = (int)uidlist[i];
54021 + if (real == curuid)
54022 + realok = 1;
54023 + if (effective == curuid)
54024 + effectiveok = 1;
54025 + if (fs == curuid)
54026 + fsok = 1;
54027 + }
54028 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54029 + for (i = 0; i < num; i++) {
54030 + curuid = (int)uidlist[i];
54031 + if (real == curuid)
54032 + break;
54033 + if (effective == curuid)
54034 + break;
54035 + if (fs == curuid)
54036 + break;
54037 + }
54038 + /* not in deny list */
54039 + if (i == num) {
54040 + realok = 1;
54041 + effectiveok = 1;
54042 + fsok = 1;
54043 + }
54044 + }
54045 +
54046 + if (realok && effectiveok && fsok)
54047 + return 0;
54048 + else {
54049 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54050 + return 1;
54051 + }
54052 +}
54053 +
54054 +int
54055 +gr_check_group_change(int real, int effective, int fs)
54056 +{
54057 + unsigned int i;
54058 + __u16 num;
54059 + gid_t *gidlist;
54060 + int curgid;
54061 + int realok = 0;
54062 + int effectiveok = 0;
54063 + int fsok = 0;
54064 +
54065 + if (unlikely(!(gr_status & GR_READY)))
54066 + return 0;
54067 +
54068 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54069 + gr_log_learn_id_change('g', real, effective, fs);
54070 +
54071 + num = current->acl->group_trans_num;
54072 + gidlist = current->acl->group_transitions;
54073 +
54074 + if (gidlist == NULL)
54075 + return 0;
54076 +
54077 + if (real == -1)
54078 + realok = 1;
54079 + if (effective == -1)
54080 + effectiveok = 1;
54081 + if (fs == -1)
54082 + fsok = 1;
54083 +
54084 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54085 + for (i = 0; i < num; i++) {
54086 + curgid = (int)gidlist[i];
54087 + if (real == curgid)
54088 + realok = 1;
54089 + if (effective == curgid)
54090 + effectiveok = 1;
54091 + if (fs == curgid)
54092 + fsok = 1;
54093 + }
54094 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54095 + for (i = 0; i < num; i++) {
54096 + curgid = (int)gidlist[i];
54097 + if (real == curgid)
54098 + break;
54099 + if (effective == curgid)
54100 + break;
54101 + if (fs == curgid)
54102 + break;
54103 + }
54104 + /* not in deny list */
54105 + if (i == num) {
54106 + realok = 1;
54107 + effectiveok = 1;
54108 + fsok = 1;
54109 + }
54110 + }
54111 +
54112 + if (realok && effectiveok && fsok)
54113 + return 0;
54114 + else {
54115 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54116 + return 1;
54117 + }
54118 +}
54119 +
54120 +extern int gr_acl_is_capable(const int cap);
54121 +
54122 +void
54123 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54124 +{
54125 + struct acl_role_label *role = task->role;
54126 + struct acl_subject_label *subj = NULL;
54127 + struct acl_object_label *obj;
54128 + struct file *filp;
54129 +
54130 + if (unlikely(!(gr_status & GR_READY)))
54131 + return;
54132 +
54133 + filp = task->exec_file;
54134 +
54135 + /* kernel process, we'll give them the kernel role */
54136 + if (unlikely(!filp)) {
54137 + task->role = kernel_role;
54138 + task->acl = kernel_role->root_label;
54139 + return;
54140 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54141 + role = lookup_acl_role_label(task, uid, gid);
54142 +
54143 + /* don't change the role if we're not a privileged process */
54144 + if (role && task->role != role &&
54145 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54146 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54147 + return;
54148 +
54149 + /* perform subject lookup in possibly new role
54150 + we can use this result below in the case where role == task->role
54151 + */
54152 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54153 +
54154 + /* if we changed uid/gid, but result in the same role
54155 + and are using inheritance, don't lose the inherited subject
54156 + if current subject is other than what normal lookup
54157 + would result in, we arrived via inheritance, don't
54158 + lose subject
54159 + */
54160 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54161 + (subj == task->acl)))
54162 + task->acl = subj;
54163 +
54164 + task->role = role;
54165 +
54166 + task->is_writable = 0;
54167 +
54168 + /* ignore additional mmap checks for processes that are writable
54169 + by the default ACL */
54170 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54171 + if (unlikely(obj->mode & GR_WRITE))
54172 + task->is_writable = 1;
54173 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54174 + if (unlikely(obj->mode & GR_WRITE))
54175 + task->is_writable = 1;
54176 +
54177 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54178 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54179 +#endif
54180 +
54181 + gr_set_proc_res(task);
54182 +
54183 + return;
54184 +}
54185 +
54186 +int
54187 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54188 + const int unsafe_flags)
54189 +{
54190 + struct task_struct *task = current;
54191 + struct acl_subject_label *newacl;
54192 + struct acl_object_label *obj;
54193 + __u32 retmode;
54194 +
54195 + if (unlikely(!(gr_status & GR_READY)))
54196 + return 0;
54197 +
54198 + newacl = chk_subj_label(dentry, mnt, task->role);
54199 +
54200 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54201 + did an exec
54202 + */
54203 + rcu_read_lock();
54204 + read_lock(&tasklist_lock);
54205 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54206 + (task->parent->acl->mode & GR_POVERRIDE))) {
54207 + read_unlock(&tasklist_lock);
54208 + rcu_read_unlock();
54209 + goto skip_check;
54210 + }
54211 + read_unlock(&tasklist_lock);
54212 + rcu_read_unlock();
54213 +
54214 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54215 + !(task->role->roletype & GR_ROLE_GOD) &&
54216 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54217 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54218 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54219 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54220 + else
54221 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54222 + return -EACCES;
54223 + }
54224 +
54225 +skip_check:
54226 +
54227 + obj = chk_obj_label(dentry, mnt, task->acl);
54228 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54229 +
54230 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54231 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54232 + if (obj->nested)
54233 + task->acl = obj->nested;
54234 + else
54235 + task->acl = newacl;
54236 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54237 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54238 +
54239 + task->is_writable = 0;
54240 +
54241 + /* ignore additional mmap checks for processes that are writable
54242 + by the default ACL */
54243 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54244 + if (unlikely(obj->mode & GR_WRITE))
54245 + task->is_writable = 1;
54246 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54247 + if (unlikely(obj->mode & GR_WRITE))
54248 + task->is_writable = 1;
54249 +
54250 + gr_set_proc_res(task);
54251 +
54252 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54253 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54254 +#endif
54255 + return 0;
54256 +}
54257 +
54258 +/* always called with valid inodev ptr */
54259 +static void
54260 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54261 +{
54262 + struct acl_object_label *matchpo;
54263 + struct acl_subject_label *matchps;
54264 + struct acl_subject_label *subj;
54265 + struct acl_role_label *role;
54266 + unsigned int x;
54267 +
54268 + FOR_EACH_ROLE_START(role)
54269 + FOR_EACH_SUBJECT_START(role, subj, x)
54270 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54271 + matchpo->mode |= GR_DELETED;
54272 + FOR_EACH_SUBJECT_END(subj,x)
54273 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54274 + if (subj->inode == ino && subj->device == dev)
54275 + subj->mode |= GR_DELETED;
54276 + FOR_EACH_NESTED_SUBJECT_END(subj)
54277 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54278 + matchps->mode |= GR_DELETED;
54279 + FOR_EACH_ROLE_END(role)
54280 +
54281 + inodev->nentry->deleted = 1;
54282 +
54283 + return;
54284 +}
54285 +
54286 +void
54287 +gr_handle_delete(const ino_t ino, const dev_t dev)
54288 +{
54289 + struct inodev_entry *inodev;
54290 +
54291 + if (unlikely(!(gr_status & GR_READY)))
54292 + return;
54293 +
54294 + write_lock(&gr_inode_lock);
54295 + inodev = lookup_inodev_entry(ino, dev);
54296 + if (inodev != NULL)
54297 + do_handle_delete(inodev, ino, dev);
54298 + write_unlock(&gr_inode_lock);
54299 +
54300 + return;
54301 +}
54302 +
54303 +static void
54304 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54305 + const ino_t newinode, const dev_t newdevice,
54306 + struct acl_subject_label *subj)
54307 +{
54308 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54309 + struct acl_object_label *match;
54310 +
54311 + match = subj->obj_hash[index];
54312 +
54313 + while (match && (match->inode != oldinode ||
54314 + match->device != olddevice ||
54315 + !(match->mode & GR_DELETED)))
54316 + match = match->next;
54317 +
54318 + if (match && (match->inode == oldinode)
54319 + && (match->device == olddevice)
54320 + && (match->mode & GR_DELETED)) {
54321 + if (match->prev == NULL) {
54322 + subj->obj_hash[index] = match->next;
54323 + if (match->next != NULL)
54324 + match->next->prev = NULL;
54325 + } else {
54326 + match->prev->next = match->next;
54327 + if (match->next != NULL)
54328 + match->next->prev = match->prev;
54329 + }
54330 + match->prev = NULL;
54331 + match->next = NULL;
54332 + match->inode = newinode;
54333 + match->device = newdevice;
54334 + match->mode &= ~GR_DELETED;
54335 +
54336 + insert_acl_obj_label(match, subj);
54337 + }
54338 +
54339 + return;
54340 +}
54341 +
54342 +static void
54343 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54344 + const ino_t newinode, const dev_t newdevice,
54345 + struct acl_role_label *role)
54346 +{
54347 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54348 + struct acl_subject_label *match;
54349 +
54350 + match = role->subj_hash[index];
54351 +
54352 + while (match && (match->inode != oldinode ||
54353 + match->device != olddevice ||
54354 + !(match->mode & GR_DELETED)))
54355 + match = match->next;
54356 +
54357 + if (match && (match->inode == oldinode)
54358 + && (match->device == olddevice)
54359 + && (match->mode & GR_DELETED)) {
54360 + if (match->prev == NULL) {
54361 + role->subj_hash[index] = match->next;
54362 + if (match->next != NULL)
54363 + match->next->prev = NULL;
54364 + } else {
54365 + match->prev->next = match->next;
54366 + if (match->next != NULL)
54367 + match->next->prev = match->prev;
54368 + }
54369 + match->prev = NULL;
54370 + match->next = NULL;
54371 + match->inode = newinode;
54372 + match->device = newdevice;
54373 + match->mode &= ~GR_DELETED;
54374 +
54375 + insert_acl_subj_label(match, role);
54376 + }
54377 +
54378 + return;
54379 +}
54380 +
54381 +static void
54382 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54383 + const ino_t newinode, const dev_t newdevice)
54384 +{
54385 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54386 + struct inodev_entry *match;
54387 +
54388 + match = inodev_set.i_hash[index];
54389 +
54390 + while (match && (match->nentry->inode != oldinode ||
54391 + match->nentry->device != olddevice || !match->nentry->deleted))
54392 + match = match->next;
54393 +
54394 + if (match && (match->nentry->inode == oldinode)
54395 + && (match->nentry->device == olddevice) &&
54396 + match->nentry->deleted) {
54397 + if (match->prev == NULL) {
54398 + inodev_set.i_hash[index] = match->next;
54399 + if (match->next != NULL)
54400 + match->next->prev = NULL;
54401 + } else {
54402 + match->prev->next = match->next;
54403 + if (match->next != NULL)
54404 + match->next->prev = match->prev;
54405 + }
54406 + match->prev = NULL;
54407 + match->next = NULL;
54408 + match->nentry->inode = newinode;
54409 + match->nentry->device = newdevice;
54410 + match->nentry->deleted = 0;
54411 +
54412 + insert_inodev_entry(match);
54413 + }
54414 +
54415 + return;
54416 +}
54417 +
54418 +static void
54419 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54420 +{
54421 + struct acl_subject_label *subj;
54422 + struct acl_role_label *role;
54423 + unsigned int x;
54424 +
54425 + FOR_EACH_ROLE_START(role)
54426 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54427 +
54428 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54429 + if ((subj->inode == ino) && (subj->device == dev)) {
54430 + subj->inode = ino;
54431 + subj->device = dev;
54432 + }
54433 + FOR_EACH_NESTED_SUBJECT_END(subj)
54434 + FOR_EACH_SUBJECT_START(role, subj, x)
54435 + update_acl_obj_label(matchn->inode, matchn->device,
54436 + ino, dev, subj);
54437 + FOR_EACH_SUBJECT_END(subj,x)
54438 + FOR_EACH_ROLE_END(role)
54439 +
54440 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54441 +
54442 + return;
54443 +}
54444 +
54445 +static void
54446 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54447 + const struct vfsmount *mnt)
54448 +{
54449 + ino_t ino = dentry->d_inode->i_ino;
54450 + dev_t dev = __get_dev(dentry);
54451 +
54452 + __do_handle_create(matchn, ino, dev);
54453 +
54454 + return;
54455 +}
54456 +
54457 +void
54458 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54459 +{
54460 + struct name_entry *matchn;
54461 +
54462 + if (unlikely(!(gr_status & GR_READY)))
54463 + return;
54464 +
54465 + preempt_disable();
54466 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54467 +
54468 + if (unlikely((unsigned long)matchn)) {
54469 + write_lock(&gr_inode_lock);
54470 + do_handle_create(matchn, dentry, mnt);
54471 + write_unlock(&gr_inode_lock);
54472 + }
54473 + preempt_enable();
54474 +
54475 + return;
54476 +}
54477 +
54478 +void
54479 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54480 +{
54481 + struct name_entry *matchn;
54482 +
54483 + if (unlikely(!(gr_status & GR_READY)))
54484 + return;
54485 +
54486 + preempt_disable();
54487 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54488 +
54489 + if (unlikely((unsigned long)matchn)) {
54490 + write_lock(&gr_inode_lock);
54491 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54492 + write_unlock(&gr_inode_lock);
54493 + }
54494 + preempt_enable();
54495 +
54496 + return;
54497 +}
54498 +
54499 +void
54500 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54501 + struct dentry *old_dentry,
54502 + struct dentry *new_dentry,
54503 + struct vfsmount *mnt, const __u8 replace)
54504 +{
54505 + struct name_entry *matchn;
54506 + struct inodev_entry *inodev;
54507 + struct inode *inode = new_dentry->d_inode;
54508 + ino_t old_ino = old_dentry->d_inode->i_ino;
54509 + dev_t old_dev = __get_dev(old_dentry);
54510 +
54511 + /* vfs_rename swaps the name and parent link for old_dentry and
54512 + new_dentry
54513 + at this point, old_dentry has the new name, parent link, and inode
54514 + for the renamed file
54515 + if a file is being replaced by a rename, new_dentry has the inode
54516 + and name for the replaced file
54517 + */
54518 +
54519 + if (unlikely(!(gr_status & GR_READY)))
54520 + return;
54521 +
54522 + preempt_disable();
54523 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54524 +
54525 + /* we wouldn't have to check d_inode if it weren't for
54526 + NFS silly-renaming
54527 + */
54528 +
54529 + write_lock(&gr_inode_lock);
54530 + if (unlikely(replace && inode)) {
54531 + ino_t new_ino = inode->i_ino;
54532 + dev_t new_dev = __get_dev(new_dentry);
54533 +
54534 + inodev = lookup_inodev_entry(new_ino, new_dev);
54535 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54536 + do_handle_delete(inodev, new_ino, new_dev);
54537 + }
54538 +
54539 + inodev = lookup_inodev_entry(old_ino, old_dev);
54540 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54541 + do_handle_delete(inodev, old_ino, old_dev);
54542 +
54543 + if (unlikely((unsigned long)matchn))
54544 + do_handle_create(matchn, old_dentry, mnt);
54545 +
54546 + write_unlock(&gr_inode_lock);
54547 + preempt_enable();
54548 +
54549 + return;
54550 +}
54551 +
54552 +static int
54553 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54554 + unsigned char **sum)
54555 +{
54556 + struct acl_role_label *r;
54557 + struct role_allowed_ip *ipp;
54558 + struct role_transition *trans;
54559 + unsigned int i;
54560 + int found = 0;
54561 + u32 curr_ip = current->signal->curr_ip;
54562 +
54563 + current->signal->saved_ip = curr_ip;
54564 +
54565 + /* check transition table */
54566 +
54567 + for (trans = current->role->transitions; trans; trans = trans->next) {
54568 + if (!strcmp(rolename, trans->rolename)) {
54569 + found = 1;
54570 + break;
54571 + }
54572 + }
54573 +
54574 + if (!found)
54575 + return 0;
54576 +
54577 + /* handle special roles that do not require authentication
54578 + and check ip */
54579 +
54580 + FOR_EACH_ROLE_START(r)
54581 + if (!strcmp(rolename, r->rolename) &&
54582 + (r->roletype & GR_ROLE_SPECIAL)) {
54583 + found = 0;
54584 + if (r->allowed_ips != NULL) {
54585 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54586 + if ((ntohl(curr_ip) & ipp->netmask) ==
54587 + (ntohl(ipp->addr) & ipp->netmask))
54588 + found = 1;
54589 + }
54590 + } else
54591 + found = 2;
54592 + if (!found)
54593 + return 0;
54594 +
54595 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54596 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54597 + *salt = NULL;
54598 + *sum = NULL;
54599 + return 1;
54600 + }
54601 + }
54602 + FOR_EACH_ROLE_END(r)
54603 +
54604 + for (i = 0; i < num_sprole_pws; i++) {
54605 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54606 + *salt = acl_special_roles[i]->salt;
54607 + *sum = acl_special_roles[i]->sum;
54608 + return 1;
54609 + }
54610 + }
54611 +
54612 + return 0;
54613 +}
54614 +
54615 +static void
54616 +assign_special_role(char *rolename)
54617 +{
54618 + struct acl_object_label *obj;
54619 + struct acl_role_label *r;
54620 + struct acl_role_label *assigned = NULL;
54621 + struct task_struct *tsk;
54622 + struct file *filp;
54623 +
54624 + FOR_EACH_ROLE_START(r)
54625 + if (!strcmp(rolename, r->rolename) &&
54626 + (r->roletype & GR_ROLE_SPECIAL)) {
54627 + assigned = r;
54628 + break;
54629 + }
54630 + FOR_EACH_ROLE_END(r)
54631 +
54632 + if (!assigned)
54633 + return;
54634 +
54635 + read_lock(&tasklist_lock);
54636 + read_lock(&grsec_exec_file_lock);
54637 +
54638 + tsk = current->real_parent;
54639 + if (tsk == NULL)
54640 + goto out_unlock;
54641 +
54642 + filp = tsk->exec_file;
54643 + if (filp == NULL)
54644 + goto out_unlock;
54645 +
54646 + tsk->is_writable = 0;
54647 +
54648 + tsk->acl_sp_role = 1;
54649 + tsk->acl_role_id = ++acl_sp_role_value;
54650 + tsk->role = assigned;
54651 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54652 +
54653 + /* ignore additional mmap checks for processes that are writable
54654 + by the default ACL */
54655 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54656 + if (unlikely(obj->mode & GR_WRITE))
54657 + tsk->is_writable = 1;
54658 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54659 + if (unlikely(obj->mode & GR_WRITE))
54660 + tsk->is_writable = 1;
54661 +
54662 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54663 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54664 +#endif
54665 +
54666 +out_unlock:
54667 + read_unlock(&grsec_exec_file_lock);
54668 + read_unlock(&tasklist_lock);
54669 + return;
54670 +}
54671 +
54672 +int gr_check_secure_terminal(struct task_struct *task)
54673 +{
54674 + struct task_struct *p, *p2, *p3;
54675 + struct files_struct *files;
54676 + struct fdtable *fdt;
54677 + struct file *our_file = NULL, *file;
54678 + int i;
54679 +
54680 + if (task->signal->tty == NULL)
54681 + return 1;
54682 +
54683 + files = get_files_struct(task);
54684 + if (files != NULL) {
54685 + rcu_read_lock();
54686 + fdt = files_fdtable(files);
54687 + for (i=0; i < fdt->max_fds; i++) {
54688 + file = fcheck_files(files, i);
54689 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54690 + get_file(file);
54691 + our_file = file;
54692 + }
54693 + }
54694 + rcu_read_unlock();
54695 + put_files_struct(files);
54696 + }
54697 +
54698 + if (our_file == NULL)
54699 + return 1;
54700 +
54701 + read_lock(&tasklist_lock);
54702 + do_each_thread(p2, p) {
54703 + files = get_files_struct(p);
54704 + if (files == NULL ||
54705 + (p->signal && p->signal->tty == task->signal->tty)) {
54706 + if (files != NULL)
54707 + put_files_struct(files);
54708 + continue;
54709 + }
54710 + rcu_read_lock();
54711 + fdt = files_fdtable(files);
54712 + for (i=0; i < fdt->max_fds; i++) {
54713 + file = fcheck_files(files, i);
54714 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54715 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54716 + p3 = task;
54717 + while (p3->pid > 0) {
54718 + if (p3 == p)
54719 + break;
54720 + p3 = p3->real_parent;
54721 + }
54722 + if (p3 == p)
54723 + break;
54724 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54725 + gr_handle_alertkill(p);
54726 + rcu_read_unlock();
54727 + put_files_struct(files);
54728 + read_unlock(&tasklist_lock);
54729 + fput(our_file);
54730 + return 0;
54731 + }
54732 + }
54733 + rcu_read_unlock();
54734 + put_files_struct(files);
54735 + } while_each_thread(p2, p);
54736 + read_unlock(&tasklist_lock);
54737 +
54738 + fput(our_file);
54739 + return 1;
54740 +}
54741 +
54742 +ssize_t
54743 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54744 +{
54745 + struct gr_arg_wrapper uwrap;
54746 + unsigned char *sprole_salt = NULL;
54747 + unsigned char *sprole_sum = NULL;
54748 + int error = sizeof (struct gr_arg_wrapper);
54749 + int error2 = 0;
54750 +
54751 + mutex_lock(&gr_dev_mutex);
54752 +
54753 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54754 + error = -EPERM;
54755 + goto out;
54756 + }
54757 +
54758 + if (count != sizeof (struct gr_arg_wrapper)) {
54759 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54760 + error = -EINVAL;
54761 + goto out;
54762 + }
54763 +
54764 +
54765 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54766 + gr_auth_expires = 0;
54767 + gr_auth_attempts = 0;
54768 + }
54769 +
54770 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54771 + error = -EFAULT;
54772 + goto out;
54773 + }
54774 +
54775 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54776 + error = -EINVAL;
54777 + goto out;
54778 + }
54779 +
54780 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54781 + error = -EFAULT;
54782 + goto out;
54783 + }
54784 +
54785 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54786 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54787 + time_after(gr_auth_expires, get_seconds())) {
54788 + error = -EBUSY;
54789 + goto out;
54790 + }
54791 +
54792 + /* if non-root trying to do anything other than use a special role,
54793 + do not attempt authentication, do not count towards authentication
54794 + locking
54795 + */
54796 +
54797 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54798 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54799 + current_uid()) {
54800 + error = -EPERM;
54801 + goto out;
54802 + }
54803 +
54804 + /* ensure pw and special role name are null terminated */
54805 +
54806 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54807 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54808 +
54809 + /* Okay.
54810 + * We have our enough of the argument structure..(we have yet
54811 + * to copy_from_user the tables themselves) . Copy the tables
54812 + * only if we need them, i.e. for loading operations. */
54813 +
54814 + switch (gr_usermode->mode) {
54815 + case GR_STATUS:
54816 + if (gr_status & GR_READY) {
54817 + error = 1;
54818 + if (!gr_check_secure_terminal(current))
54819 + error = 3;
54820 + } else
54821 + error = 2;
54822 + goto out;
54823 + case GR_SHUTDOWN:
54824 + if ((gr_status & GR_READY)
54825 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54826 + pax_open_kernel();
54827 + gr_status &= ~GR_READY;
54828 + pax_close_kernel();
54829 +
54830 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54831 + free_variables();
54832 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54833 + memset(gr_system_salt, 0, GR_SALT_LEN);
54834 + memset(gr_system_sum, 0, GR_SHA_LEN);
54835 + } else if (gr_status & GR_READY) {
54836 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54837 + error = -EPERM;
54838 + } else {
54839 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54840 + error = -EAGAIN;
54841 + }
54842 + break;
54843 + case GR_ENABLE:
54844 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54845 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54846 + else {
54847 + if (gr_status & GR_READY)
54848 + error = -EAGAIN;
54849 + else
54850 + error = error2;
54851 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54852 + }
54853 + break;
54854 + case GR_RELOAD:
54855 + if (!(gr_status & GR_READY)) {
54856 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54857 + error = -EAGAIN;
54858 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54859 + preempt_disable();
54860 +
54861 + pax_open_kernel();
54862 + gr_status &= ~GR_READY;
54863 + pax_close_kernel();
54864 +
54865 + free_variables();
54866 + if (!(error2 = gracl_init(gr_usermode))) {
54867 + preempt_enable();
54868 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54869 + } else {
54870 + preempt_enable();
54871 + error = error2;
54872 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54873 + }
54874 + } else {
54875 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54876 + error = -EPERM;
54877 + }
54878 + break;
54879 + case GR_SEGVMOD:
54880 + if (unlikely(!(gr_status & GR_READY))) {
54881 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54882 + error = -EAGAIN;
54883 + break;
54884 + }
54885 +
54886 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54887 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54888 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54889 + struct acl_subject_label *segvacl;
54890 + segvacl =
54891 + lookup_acl_subj_label(gr_usermode->segv_inode,
54892 + gr_usermode->segv_device,
54893 + current->role);
54894 + if (segvacl) {
54895 + segvacl->crashes = 0;
54896 + segvacl->expires = 0;
54897 + }
54898 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54899 + gr_remove_uid(gr_usermode->segv_uid);
54900 + }
54901 + } else {
54902 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54903 + error = -EPERM;
54904 + }
54905 + break;
54906 + case GR_SPROLE:
54907 + case GR_SPROLEPAM:
54908 + if (unlikely(!(gr_status & GR_READY))) {
54909 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54910 + error = -EAGAIN;
54911 + break;
54912 + }
54913 +
54914 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54915 + current->role->expires = 0;
54916 + current->role->auth_attempts = 0;
54917 + }
54918 +
54919 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54920 + time_after(current->role->expires, get_seconds())) {
54921 + error = -EBUSY;
54922 + goto out;
54923 + }
54924 +
54925 + if (lookup_special_role_auth
54926 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54927 + && ((!sprole_salt && !sprole_sum)
54928 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54929 + char *p = "";
54930 + assign_special_role(gr_usermode->sp_role);
54931 + read_lock(&tasklist_lock);
54932 + if (current->real_parent)
54933 + p = current->real_parent->role->rolename;
54934 + read_unlock(&tasklist_lock);
54935 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54936 + p, acl_sp_role_value);
54937 + } else {
54938 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54939 + error = -EPERM;
54940 + if(!(current->role->auth_attempts++))
54941 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54942 +
54943 + goto out;
54944 + }
54945 + break;
54946 + case GR_UNSPROLE:
54947 + if (unlikely(!(gr_status & GR_READY))) {
54948 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54949 + error = -EAGAIN;
54950 + break;
54951 + }
54952 +
54953 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54954 + char *p = "";
54955 + int i = 0;
54956 +
54957 + read_lock(&tasklist_lock);
54958 + if (current->real_parent) {
54959 + p = current->real_parent->role->rolename;
54960 + i = current->real_parent->acl_role_id;
54961 + }
54962 + read_unlock(&tasklist_lock);
54963 +
54964 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54965 + gr_set_acls(1);
54966 + } else {
54967 + error = -EPERM;
54968 + goto out;
54969 + }
54970 + break;
54971 + default:
54972 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54973 + error = -EINVAL;
54974 + break;
54975 + }
54976 +
54977 + if (error != -EPERM)
54978 + goto out;
54979 +
54980 + if(!(gr_auth_attempts++))
54981 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54982 +
54983 + out:
54984 + mutex_unlock(&gr_dev_mutex);
54985 + return error;
54986 +}
54987 +
54988 +/* must be called with
54989 + rcu_read_lock();
54990 + read_lock(&tasklist_lock);
54991 + read_lock(&grsec_exec_file_lock);
54992 +*/
54993 +int gr_apply_subject_to_task(struct task_struct *task)
54994 +{
54995 + struct acl_object_label *obj;
54996 + char *tmpname;
54997 + struct acl_subject_label *tmpsubj;
54998 + struct file *filp;
54999 + struct name_entry *nmatch;
55000 +
55001 + filp = task->exec_file;
55002 + if (filp == NULL)
55003 + return 0;
55004 +
55005 + /* the following is to apply the correct subject
55006 + on binaries running when the RBAC system
55007 + is enabled, when the binaries have been
55008 + replaced or deleted since their execution
55009 + -----
55010 + when the RBAC system starts, the inode/dev
55011 + from exec_file will be one the RBAC system
55012 + is unaware of. It only knows the inode/dev
55013 + of the present file on disk, or the absence
55014 + of it.
55015 + */
55016 + preempt_disable();
55017 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55018 +
55019 + nmatch = lookup_name_entry(tmpname);
55020 + preempt_enable();
55021 + tmpsubj = NULL;
55022 + if (nmatch) {
55023 + if (nmatch->deleted)
55024 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55025 + else
55026 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55027 + if (tmpsubj != NULL)
55028 + task->acl = tmpsubj;
55029 + }
55030 + if (tmpsubj == NULL)
55031 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55032 + task->role);
55033 + if (task->acl) {
55034 + task->is_writable = 0;
55035 + /* ignore additional mmap checks for processes that are writable
55036 + by the default ACL */
55037 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55038 + if (unlikely(obj->mode & GR_WRITE))
55039 + task->is_writable = 1;
55040 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55041 + if (unlikely(obj->mode & GR_WRITE))
55042 + task->is_writable = 1;
55043 +
55044 + gr_set_proc_res(task);
55045 +
55046 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55047 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55048 +#endif
55049 + } else {
55050 + return 1;
55051 + }
55052 +
55053 + return 0;
55054 +}
55055 +
55056 +int
55057 +gr_set_acls(const int type)
55058 +{
55059 + struct task_struct *task, *task2;
55060 + struct acl_role_label *role = current->role;
55061 + __u16 acl_role_id = current->acl_role_id;
55062 + const struct cred *cred;
55063 + int ret;
55064 +
55065 + rcu_read_lock();
55066 + read_lock(&tasklist_lock);
55067 + read_lock(&grsec_exec_file_lock);
55068 + do_each_thread(task2, task) {
55069 + /* check to see if we're called from the exit handler,
55070 + if so, only replace ACLs that have inherited the admin
55071 + ACL */
55072 +
55073 + if (type && (task->role != role ||
55074 + task->acl_role_id != acl_role_id))
55075 + continue;
55076 +
55077 + task->acl_role_id = 0;
55078 + task->acl_sp_role = 0;
55079 +
55080 + if (task->exec_file) {
55081 + cred = __task_cred(task);
55082 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55083 + ret = gr_apply_subject_to_task(task);
55084 + if (ret) {
55085 + read_unlock(&grsec_exec_file_lock);
55086 + read_unlock(&tasklist_lock);
55087 + rcu_read_unlock();
55088 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55089 + return ret;
55090 + }
55091 + } else {
55092 + // it's a kernel process
55093 + task->role = kernel_role;
55094 + task->acl = kernel_role->root_label;
55095 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55096 + task->acl->mode &= ~GR_PROCFIND;
55097 +#endif
55098 + }
55099 + } while_each_thread(task2, task);
55100 + read_unlock(&grsec_exec_file_lock);
55101 + read_unlock(&tasklist_lock);
55102 + rcu_read_unlock();
55103 +
55104 + return 0;
55105 +}
55106 +
55107 +void
55108 +gr_learn_resource(const struct task_struct *task,
55109 + const int res, const unsigned long wanted, const int gt)
55110 +{
55111 + struct acl_subject_label *acl;
55112 + const struct cred *cred;
55113 +
55114 + if (unlikely((gr_status & GR_READY) &&
55115 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55116 + goto skip_reslog;
55117 +
55118 +#ifdef CONFIG_GRKERNSEC_RESLOG
55119 + gr_log_resource(task, res, wanted, gt);
55120 +#endif
55121 + skip_reslog:
55122 +
55123 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55124 + return;
55125 +
55126 + acl = task->acl;
55127 +
55128 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55129 + !(acl->resmask & (1 << (unsigned short) res))))
55130 + return;
55131 +
55132 + if (wanted >= acl->res[res].rlim_cur) {
55133 + unsigned long res_add;
55134 +
55135 + res_add = wanted;
55136 + switch (res) {
55137 + case RLIMIT_CPU:
55138 + res_add += GR_RLIM_CPU_BUMP;
55139 + break;
55140 + case RLIMIT_FSIZE:
55141 + res_add += GR_RLIM_FSIZE_BUMP;
55142 + break;
55143 + case RLIMIT_DATA:
55144 + res_add += GR_RLIM_DATA_BUMP;
55145 + break;
55146 + case RLIMIT_STACK:
55147 + res_add += GR_RLIM_STACK_BUMP;
55148 + break;
55149 + case RLIMIT_CORE:
55150 + res_add += GR_RLIM_CORE_BUMP;
55151 + break;
55152 + case RLIMIT_RSS:
55153 + res_add += GR_RLIM_RSS_BUMP;
55154 + break;
55155 + case RLIMIT_NPROC:
55156 + res_add += GR_RLIM_NPROC_BUMP;
55157 + break;
55158 + case RLIMIT_NOFILE:
55159 + res_add += GR_RLIM_NOFILE_BUMP;
55160 + break;
55161 + case RLIMIT_MEMLOCK:
55162 + res_add += GR_RLIM_MEMLOCK_BUMP;
55163 + break;
55164 + case RLIMIT_AS:
55165 + res_add += GR_RLIM_AS_BUMP;
55166 + break;
55167 + case RLIMIT_LOCKS:
55168 + res_add += GR_RLIM_LOCKS_BUMP;
55169 + break;
55170 + case RLIMIT_SIGPENDING:
55171 + res_add += GR_RLIM_SIGPENDING_BUMP;
55172 + break;
55173 + case RLIMIT_MSGQUEUE:
55174 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55175 + break;
55176 + case RLIMIT_NICE:
55177 + res_add += GR_RLIM_NICE_BUMP;
55178 + break;
55179 + case RLIMIT_RTPRIO:
55180 + res_add += GR_RLIM_RTPRIO_BUMP;
55181 + break;
55182 + case RLIMIT_RTTIME:
55183 + res_add += GR_RLIM_RTTIME_BUMP;
55184 + break;
55185 + }
55186 +
55187 + acl->res[res].rlim_cur = res_add;
55188 +
55189 + if (wanted > acl->res[res].rlim_max)
55190 + acl->res[res].rlim_max = res_add;
55191 +
55192 + /* only log the subject filename, since resource logging is supported for
55193 + single-subject learning only */
55194 + rcu_read_lock();
55195 + cred = __task_cred(task);
55196 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55197 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55198 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55199 + "", (unsigned long) res, &task->signal->saved_ip);
55200 + rcu_read_unlock();
55201 + }
55202 +
55203 + return;
55204 +}
55205 +
55206 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55207 +void
55208 +pax_set_initial_flags(struct linux_binprm *bprm)
55209 +{
55210 + struct task_struct *task = current;
55211 + struct acl_subject_label *proc;
55212 + unsigned long flags;
55213 +
55214 + if (unlikely(!(gr_status & GR_READY)))
55215 + return;
55216 +
55217 + flags = pax_get_flags(task);
55218 +
55219 + proc = task->acl;
55220 +
55221 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55222 + flags &= ~MF_PAX_PAGEEXEC;
55223 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55224 + flags &= ~MF_PAX_SEGMEXEC;
55225 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55226 + flags &= ~MF_PAX_RANDMMAP;
55227 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55228 + flags &= ~MF_PAX_EMUTRAMP;
55229 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55230 + flags &= ~MF_PAX_MPROTECT;
55231 +
55232 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55233 + flags |= MF_PAX_PAGEEXEC;
55234 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55235 + flags |= MF_PAX_SEGMEXEC;
55236 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55237 + flags |= MF_PAX_RANDMMAP;
55238 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55239 + flags |= MF_PAX_EMUTRAMP;
55240 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55241 + flags |= MF_PAX_MPROTECT;
55242 +
55243 + pax_set_flags(task, flags);
55244 +
55245 + return;
55246 +}
55247 +#endif
55248 +
55249 +#ifdef CONFIG_SYSCTL
55250 +/* Eric Biederman likes breaking userland ABI and every inode-based security
55251 + system to save 35kb of memory */
55252 +
55253 +/* we modify the passed in filename, but adjust it back before returning */
55254 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
55255 +{
55256 + struct name_entry *nmatch;
55257 + char *p, *lastp = NULL;
55258 + struct acl_object_label *obj = NULL, *tmp;
55259 + struct acl_subject_label *tmpsubj;
55260 + char c = '\0';
55261 +
55262 + read_lock(&gr_inode_lock);
55263 +
55264 + p = name + len - 1;
55265 + do {
55266 + nmatch = lookup_name_entry(name);
55267 + if (lastp != NULL)
55268 + *lastp = c;
55269 +
55270 + if (nmatch == NULL)
55271 + goto next_component;
55272 + tmpsubj = current->acl;
55273 + do {
55274 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
55275 + if (obj != NULL) {
55276 + tmp = obj->globbed;
55277 + while (tmp) {
55278 + if (!glob_match(tmp->filename, name)) {
55279 + obj = tmp;
55280 + goto found_obj;
55281 + }
55282 + tmp = tmp->next;
55283 + }
55284 + goto found_obj;
55285 + }
55286 + } while ((tmpsubj = tmpsubj->parent_subject));
55287 +next_component:
55288 + /* end case */
55289 + if (p == name)
55290 + break;
55291 +
55292 + while (*p != '/')
55293 + p--;
55294 + if (p == name)
55295 + lastp = p + 1;
55296 + else {
55297 + lastp = p;
55298 + p--;
55299 + }
55300 + c = *lastp;
55301 + *lastp = '\0';
55302 + } while (1);
55303 +found_obj:
55304 + read_unlock(&gr_inode_lock);
55305 + /* obj returned will always be non-null */
55306 + return obj;
55307 +}
55308 +
55309 +/* returns 0 when allowing, non-zero on error
55310 + op of 0 is used for readdir, so we don't log the names of hidden files
55311 +*/
55312 +__u32
55313 +gr_handle_sysctl(const struct ctl_table *table, const int op)
55314 +{
55315 + struct ctl_table *tmp;
55316 + const char *proc_sys = "/proc/sys";
55317 + char *path;
55318 + struct acl_object_label *obj;
55319 + unsigned short len = 0, pos = 0, depth = 0, i;
55320 + __u32 err = 0;
55321 + __u32 mode = 0;
55322 +
55323 + if (unlikely(!(gr_status & GR_READY)))
55324 + return 0;
55325 +
55326 + /* for now, ignore operations on non-sysctl entries if it's not a
55327 + readdir*/
55328 + if (table->child != NULL && op != 0)
55329 + return 0;
55330 +
55331 + mode |= GR_FIND;
55332 + /* it's only a read if it's an entry, read on dirs is for readdir */
55333 + if (op & MAY_READ)
55334 + mode |= GR_READ;
55335 + if (op & MAY_WRITE)
55336 + mode |= GR_WRITE;
55337 +
55338 + preempt_disable();
55339 +
55340 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
55341 +
55342 + /* it's only a read/write if it's an actual entry, not a dir
55343 + (which are opened for readdir)
55344 + */
55345 +
55346 + /* convert the requested sysctl entry into a pathname */
55347 +
55348 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
55349 + len += strlen(tmp->procname);
55350 + len++;
55351 + depth++;
55352 + }
55353 +
55354 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
55355 + /* deny */
55356 + goto out;
55357 + }
55358 +
55359 + memset(path, 0, PAGE_SIZE);
55360 +
55361 + memcpy(path, proc_sys, strlen(proc_sys));
55362 +
55363 + pos += strlen(proc_sys);
55364 +
55365 + for (; depth > 0; depth--) {
55366 + path[pos] = '/';
55367 + pos++;
55368 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
55369 + if (depth == i) {
55370 + memcpy(path + pos, tmp->procname,
55371 + strlen(tmp->procname));
55372 + pos += strlen(tmp->procname);
55373 + }
55374 + i++;
55375 + }
55376 + }
55377 +
55378 + obj = gr_lookup_by_name(path, pos);
55379 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
55380 +
55381 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
55382 + ((err & mode) != mode))) {
55383 + __u32 new_mode = mode;
55384 +
55385 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55386 +
55387 + err = 0;
55388 + gr_log_learn_sysctl(path, new_mode);
55389 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
55390 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
55391 + err = -ENOENT;
55392 + } else if (!(err & GR_FIND)) {
55393 + err = -ENOENT;
55394 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
55395 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
55396 + path, (mode & GR_READ) ? " reading" : "",
55397 + (mode & GR_WRITE) ? " writing" : "");
55398 + err = -EACCES;
55399 + } else if ((err & mode) != mode) {
55400 + err = -EACCES;
55401 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
55402 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
55403 + path, (mode & GR_READ) ? " reading" : "",
55404 + (mode & GR_WRITE) ? " writing" : "");
55405 + err = 0;
55406 + } else
55407 + err = 0;
55408 +
55409 + out:
55410 + preempt_enable();
55411 +
55412 + return err;
55413 +}
55414 +#endif
55415 +
55416 +int
55417 +gr_handle_proc_ptrace(struct task_struct *task)
55418 +{
55419 + struct file *filp;
55420 + struct task_struct *tmp = task;
55421 + struct task_struct *curtemp = current;
55422 + __u32 retmode;
55423 +
55424 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55425 + if (unlikely(!(gr_status & GR_READY)))
55426 + return 0;
55427 +#endif
55428 +
55429 + read_lock(&tasklist_lock);
55430 + read_lock(&grsec_exec_file_lock);
55431 + filp = task->exec_file;
55432 +
55433 + while (tmp->pid > 0) {
55434 + if (tmp == curtemp)
55435 + break;
55436 + tmp = tmp->real_parent;
55437 + }
55438 +
55439 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55440 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55441 + read_unlock(&grsec_exec_file_lock);
55442 + read_unlock(&tasklist_lock);
55443 + return 1;
55444 + }
55445 +
55446 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55447 + if (!(gr_status & GR_READY)) {
55448 + read_unlock(&grsec_exec_file_lock);
55449 + read_unlock(&tasklist_lock);
55450 + return 0;
55451 + }
55452 +#endif
55453 +
55454 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55455 + read_unlock(&grsec_exec_file_lock);
55456 + read_unlock(&tasklist_lock);
55457 +
55458 + if (retmode & GR_NOPTRACE)
55459 + return 1;
55460 +
55461 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55462 + && (current->acl != task->acl || (current->acl != current->role->root_label
55463 + && current->pid != task->pid)))
55464 + return 1;
55465 +
55466 + return 0;
55467 +}
55468 +
55469 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55470 +{
55471 + if (unlikely(!(gr_status & GR_READY)))
55472 + return;
55473 +
55474 + if (!(current->role->roletype & GR_ROLE_GOD))
55475 + return;
55476 +
55477 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55478 + p->role->rolename, gr_task_roletype_to_char(p),
55479 + p->acl->filename);
55480 +}
55481 +
55482 +int
55483 +gr_handle_ptrace(struct task_struct *task, const long request)
55484 +{
55485 + struct task_struct *tmp = task;
55486 + struct task_struct *curtemp = current;
55487 + __u32 retmode;
55488 +
55489 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55490 + if (unlikely(!(gr_status & GR_READY)))
55491 + return 0;
55492 +#endif
55493 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55494 + read_lock(&tasklist_lock);
55495 + while (tmp->pid > 0) {
55496 + if (tmp == curtemp)
55497 + break;
55498 + tmp = tmp->real_parent;
55499 + }
55500 +
55501 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
55502 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55503 + read_unlock(&tasklist_lock);
55504 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55505 + return 1;
55506 + }
55507 + read_unlock(&tasklist_lock);
55508 + }
55509 +
55510 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55511 + if (!(gr_status & GR_READY))
55512 + return 0;
55513 +#endif
55514 +
55515 + read_lock(&grsec_exec_file_lock);
55516 + if (unlikely(!task->exec_file)) {
55517 + read_unlock(&grsec_exec_file_lock);
55518 + return 0;
55519 + }
55520 +
55521 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55522 + read_unlock(&grsec_exec_file_lock);
55523 +
55524 + if (retmode & GR_NOPTRACE) {
55525 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55526 + return 1;
55527 + }
55528 +
55529 + if (retmode & GR_PTRACERD) {
55530 + switch (request) {
55531 + case PTRACE_SEIZE:
55532 + case PTRACE_POKETEXT:
55533 + case PTRACE_POKEDATA:
55534 + case PTRACE_POKEUSR:
55535 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55536 + case PTRACE_SETREGS:
55537 + case PTRACE_SETFPREGS:
55538 +#endif
55539 +#ifdef CONFIG_X86
55540 + case PTRACE_SETFPXREGS:
55541 +#endif
55542 +#ifdef CONFIG_ALTIVEC
55543 + case PTRACE_SETVRREGS:
55544 +#endif
55545 + return 1;
55546 + default:
55547 + return 0;
55548 + }
55549 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55550 + !(current->role->roletype & GR_ROLE_GOD) &&
55551 + (current->acl != task->acl)) {
55552 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55553 + return 1;
55554 + }
55555 +
55556 + return 0;
55557 +}
55558 +
55559 +static int is_writable_mmap(const struct file *filp)
55560 +{
55561 + struct task_struct *task = current;
55562 + struct acl_object_label *obj, *obj2;
55563 +
55564 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55565 + !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))) {
55566 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55567 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55568 + task->role->root_label);
55569 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55570 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55571 + return 1;
55572 + }
55573 + }
55574 + return 0;
55575 +}
55576 +
55577 +int
55578 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55579 +{
55580 + __u32 mode;
55581 +
55582 + if (unlikely(!file || !(prot & PROT_EXEC)))
55583 + return 1;
55584 +
55585 + if (is_writable_mmap(file))
55586 + return 0;
55587 +
55588 + mode =
55589 + gr_search_file(file->f_path.dentry,
55590 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55591 + file->f_path.mnt);
55592 +
55593 + if (!gr_tpe_allow(file))
55594 + return 0;
55595 +
55596 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55597 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55598 + return 0;
55599 + } else if (unlikely(!(mode & GR_EXEC))) {
55600 + return 0;
55601 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55602 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55603 + return 1;
55604 + }
55605 +
55606 + return 1;
55607 +}
55608 +
55609 +int
55610 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55611 +{
55612 + __u32 mode;
55613 +
55614 + if (unlikely(!file || !(prot & PROT_EXEC)))
55615 + return 1;
55616 +
55617 + if (is_writable_mmap(file))
55618 + return 0;
55619 +
55620 + mode =
55621 + gr_search_file(file->f_path.dentry,
55622 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55623 + file->f_path.mnt);
55624 +
55625 + if (!gr_tpe_allow(file))
55626 + return 0;
55627 +
55628 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55629 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55630 + return 0;
55631 + } else if (unlikely(!(mode & GR_EXEC))) {
55632 + return 0;
55633 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55634 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55635 + return 1;
55636 + }
55637 +
55638 + return 1;
55639 +}
55640 +
55641 +void
55642 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55643 +{
55644 + unsigned long runtime;
55645 + unsigned long cputime;
55646 + unsigned int wday, cday;
55647 + __u8 whr, chr;
55648 + __u8 wmin, cmin;
55649 + __u8 wsec, csec;
55650 + struct timespec timeval;
55651 +
55652 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55653 + !(task->acl->mode & GR_PROCACCT)))
55654 + return;
55655 +
55656 + do_posix_clock_monotonic_gettime(&timeval);
55657 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55658 + wday = runtime / (3600 * 24);
55659 + runtime -= wday * (3600 * 24);
55660 + whr = runtime / 3600;
55661 + runtime -= whr * 3600;
55662 + wmin = runtime / 60;
55663 + runtime -= wmin * 60;
55664 + wsec = runtime;
55665 +
55666 + cputime = (task->utime + task->stime) / HZ;
55667 + cday = cputime / (3600 * 24);
55668 + cputime -= cday * (3600 * 24);
55669 + chr = cputime / 3600;
55670 + cputime -= chr * 3600;
55671 + cmin = cputime / 60;
55672 + cputime -= cmin * 60;
55673 + csec = cputime;
55674 +
55675 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55676 +
55677 + return;
55678 +}
55679 +
55680 +void gr_set_kernel_label(struct task_struct *task)
55681 +{
55682 + if (gr_status & GR_READY) {
55683 + task->role = kernel_role;
55684 + task->acl = kernel_role->root_label;
55685 + }
55686 + return;
55687 +}
55688 +
55689 +#ifdef CONFIG_TASKSTATS
55690 +int gr_is_taskstats_denied(int pid)
55691 +{
55692 + struct task_struct *task;
55693 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55694 + const struct cred *cred;
55695 +#endif
55696 + int ret = 0;
55697 +
55698 + /* restrict taskstats viewing to un-chrooted root users
55699 + who have the 'view' subject flag if the RBAC system is enabled
55700 + */
55701 +
55702 + rcu_read_lock();
55703 + read_lock(&tasklist_lock);
55704 + task = find_task_by_vpid(pid);
55705 + if (task) {
55706 +#ifdef CONFIG_GRKERNSEC_CHROOT
55707 + if (proc_is_chrooted(task))
55708 + ret = -EACCES;
55709 +#endif
55710 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55711 + cred = __task_cred(task);
55712 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55713 + if (cred->uid != 0)
55714 + ret = -EACCES;
55715 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55716 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55717 + ret = -EACCES;
55718 +#endif
55719 +#endif
55720 + if (gr_status & GR_READY) {
55721 + if (!(task->acl->mode & GR_VIEW))
55722 + ret = -EACCES;
55723 + }
55724 + } else
55725 + ret = -ENOENT;
55726 +
55727 + read_unlock(&tasklist_lock);
55728 + rcu_read_unlock();
55729 +
55730 + return ret;
55731 +}
55732 +#endif
55733 +
55734 +/* AUXV entries are filled via a descendant of search_binary_handler
55735 + after we've already applied the subject for the target
55736 +*/
55737 +int gr_acl_enable_at_secure(void)
55738 +{
55739 + if (unlikely(!(gr_status & GR_READY)))
55740 + return 0;
55741 +
55742 + if (current->acl->mode & GR_ATSECURE)
55743 + return 1;
55744 +
55745 + return 0;
55746 +}
55747 +
55748 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55749 +{
55750 + struct task_struct *task = current;
55751 + struct dentry *dentry = file->f_path.dentry;
55752 + struct vfsmount *mnt = file->f_path.mnt;
55753 + struct acl_object_label *obj, *tmp;
55754 + struct acl_subject_label *subj;
55755 + unsigned int bufsize;
55756 + int is_not_root;
55757 + char *path;
55758 + dev_t dev = __get_dev(dentry);
55759 +
55760 + if (unlikely(!(gr_status & GR_READY)))
55761 + return 1;
55762 +
55763 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55764 + return 1;
55765 +
55766 + /* ignore Eric Biederman */
55767 + if (IS_PRIVATE(dentry->d_inode))
55768 + return 1;
55769 +
55770 + subj = task->acl;
55771 + do {
55772 + obj = lookup_acl_obj_label(ino, dev, subj);
55773 + if (obj != NULL)
55774 + return (obj->mode & GR_FIND) ? 1 : 0;
55775 + } while ((subj = subj->parent_subject));
55776 +
55777 + /* this is purely an optimization since we're looking for an object
55778 + for the directory we're doing a readdir on
55779 + if it's possible for any globbed object to match the entry we're
55780 + filling into the directory, then the object we find here will be
55781 + an anchor point with attached globbed objects
55782 + */
55783 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55784 + if (obj->globbed == NULL)
55785 + return (obj->mode & GR_FIND) ? 1 : 0;
55786 +
55787 + is_not_root = ((obj->filename[0] == '/') &&
55788 + (obj->filename[1] == '\0')) ? 0 : 1;
55789 + bufsize = PAGE_SIZE - namelen - is_not_root;
55790 +
55791 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55792 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55793 + return 1;
55794 +
55795 + preempt_disable();
55796 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55797 + bufsize);
55798 +
55799 + bufsize = strlen(path);
55800 +
55801 + /* if base is "/", don't append an additional slash */
55802 + if (is_not_root)
55803 + *(path + bufsize) = '/';
55804 + memcpy(path + bufsize + is_not_root, name, namelen);
55805 + *(path + bufsize + namelen + is_not_root) = '\0';
55806 +
55807 + tmp = obj->globbed;
55808 + while (tmp) {
55809 + if (!glob_match(tmp->filename, path)) {
55810 + preempt_enable();
55811 + return (tmp->mode & GR_FIND) ? 1 : 0;
55812 + }
55813 + tmp = tmp->next;
55814 + }
55815 + preempt_enable();
55816 + return (obj->mode & GR_FIND) ? 1 : 0;
55817 +}
55818 +
55819 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55820 +EXPORT_SYMBOL(gr_acl_is_enabled);
55821 +#endif
55822 +EXPORT_SYMBOL(gr_learn_resource);
55823 +EXPORT_SYMBOL(gr_set_kernel_label);
55824 +#ifdef CONFIG_SECURITY
55825 +EXPORT_SYMBOL(gr_check_user_change);
55826 +EXPORT_SYMBOL(gr_check_group_change);
55827 +#endif
55828 +
55829 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55830 new file mode 100644
55831 index 0000000..34fefda
55832 --- /dev/null
55833 +++ b/grsecurity/gracl_alloc.c
55834 @@ -0,0 +1,105 @@
55835 +#include <linux/kernel.h>
55836 +#include <linux/mm.h>
55837 +#include <linux/slab.h>
55838 +#include <linux/vmalloc.h>
55839 +#include <linux/gracl.h>
55840 +#include <linux/grsecurity.h>
55841 +
55842 +static unsigned long alloc_stack_next = 1;
55843 +static unsigned long alloc_stack_size = 1;
55844 +static void **alloc_stack;
55845 +
55846 +static __inline__ int
55847 +alloc_pop(void)
55848 +{
55849 + if (alloc_stack_next == 1)
55850 + return 0;
55851 +
55852 + kfree(alloc_stack[alloc_stack_next - 2]);
55853 +
55854 + alloc_stack_next--;
55855 +
55856 + return 1;
55857 +}
55858 +
55859 +static __inline__ int
55860 +alloc_push(void *buf)
55861 +{
55862 + if (alloc_stack_next >= alloc_stack_size)
55863 + return 1;
55864 +
55865 + alloc_stack[alloc_stack_next - 1] = buf;
55866 +
55867 + alloc_stack_next++;
55868 +
55869 + return 0;
55870 +}
55871 +
55872 +void *
55873 +acl_alloc(unsigned long len)
55874 +{
55875 + void *ret = NULL;
55876 +
55877 + if (!len || len > PAGE_SIZE)
55878 + goto out;
55879 +
55880 + ret = kmalloc(len, GFP_KERNEL);
55881 +
55882 + if (ret) {
55883 + if (alloc_push(ret)) {
55884 + kfree(ret);
55885 + ret = NULL;
55886 + }
55887 + }
55888 +
55889 +out:
55890 + return ret;
55891 +}
55892 +
55893 +void *
55894 +acl_alloc_num(unsigned long num, unsigned long len)
55895 +{
55896 + if (!len || (num > (PAGE_SIZE / len)))
55897 + return NULL;
55898 +
55899 + return acl_alloc(num * len);
55900 +}
55901 +
55902 +void
55903 +acl_free_all(void)
55904 +{
55905 + if (gr_acl_is_enabled() || !alloc_stack)
55906 + return;
55907 +
55908 + while (alloc_pop()) ;
55909 +
55910 + if (alloc_stack) {
55911 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55912 + kfree(alloc_stack);
55913 + else
55914 + vfree(alloc_stack);
55915 + }
55916 +
55917 + alloc_stack = NULL;
55918 + alloc_stack_size = 1;
55919 + alloc_stack_next = 1;
55920 +
55921 + return;
55922 +}
55923 +
55924 +int
55925 +acl_alloc_stack_init(unsigned long size)
55926 +{
55927 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55928 + alloc_stack =
55929 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55930 + else
55931 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55932 +
55933 + alloc_stack_size = size;
55934 +
55935 + if (!alloc_stack)
55936 + return 0;
55937 + else
55938 + return 1;
55939 +}
55940 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55941 new file mode 100644
55942 index 0000000..6d21049
55943 --- /dev/null
55944 +++ b/grsecurity/gracl_cap.c
55945 @@ -0,0 +1,110 @@
55946 +#include <linux/kernel.h>
55947 +#include <linux/module.h>
55948 +#include <linux/sched.h>
55949 +#include <linux/gracl.h>
55950 +#include <linux/grsecurity.h>
55951 +#include <linux/grinternal.h>
55952 +
55953 +extern const char *captab_log[];
55954 +extern int captab_log_entries;
55955 +
55956 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55957 +{
55958 + struct acl_subject_label *curracl;
55959 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55960 + kernel_cap_t cap_audit = __cap_empty_set;
55961 +
55962 + if (!gr_acl_is_enabled())
55963 + return 1;
55964 +
55965 + curracl = task->acl;
55966 +
55967 + cap_drop = curracl->cap_lower;
55968 + cap_mask = curracl->cap_mask;
55969 + cap_audit = curracl->cap_invert_audit;
55970 +
55971 + while ((curracl = curracl->parent_subject)) {
55972 + /* if the cap isn't specified in the current computed mask but is specified in the
55973 + current level subject, and is lowered in the current level subject, then add
55974 + it to the set of dropped capabilities
55975 + otherwise, add the current level subject's mask to the current computed mask
55976 + */
55977 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55978 + cap_raise(cap_mask, cap);
55979 + if (cap_raised(curracl->cap_lower, cap))
55980 + cap_raise(cap_drop, cap);
55981 + if (cap_raised(curracl->cap_invert_audit, cap))
55982 + cap_raise(cap_audit, cap);
55983 + }
55984 + }
55985 +
55986 + if (!cap_raised(cap_drop, cap)) {
55987 + if (cap_raised(cap_audit, cap))
55988 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55989 + return 1;
55990 + }
55991 +
55992 + curracl = task->acl;
55993 +
55994 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55995 + && cap_raised(cred->cap_effective, cap)) {
55996 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55997 + task->role->roletype, cred->uid,
55998 + cred->gid, task->exec_file ?
55999 + gr_to_filename(task->exec_file->f_path.dentry,
56000 + task->exec_file->f_path.mnt) : curracl->filename,
56001 + curracl->filename, 0UL,
56002 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
56003 + return 1;
56004 + }
56005 +
56006 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
56007 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
56008 +
56009 + return 0;
56010 +}
56011 +
56012 +int
56013 +gr_acl_is_capable(const int cap)
56014 +{
56015 + return gr_task_acl_is_capable(current, current_cred(), cap);
56016 +}
56017 +
56018 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
56019 +{
56020 + struct acl_subject_label *curracl;
56021 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
56022 +
56023 + if (!gr_acl_is_enabled())
56024 + return 1;
56025 +
56026 + curracl = task->acl;
56027 +
56028 + cap_drop = curracl->cap_lower;
56029 + cap_mask = curracl->cap_mask;
56030 +
56031 + while ((curracl = curracl->parent_subject)) {
56032 + /* if the cap isn't specified in the current computed mask but is specified in the
56033 + current level subject, and is lowered in the current level subject, then add
56034 + it to the set of dropped capabilities
56035 + otherwise, add the current level subject's mask to the current computed mask
56036 + */
56037 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
56038 + cap_raise(cap_mask, cap);
56039 + if (cap_raised(curracl->cap_lower, cap))
56040 + cap_raise(cap_drop, cap);
56041 + }
56042 + }
56043 +
56044 + if (!cap_raised(cap_drop, cap))
56045 + return 1;
56046 +
56047 + return 0;
56048 +}
56049 +
56050 +int
56051 +gr_acl_is_capable_nolog(const int cap)
56052 +{
56053 + return gr_task_acl_is_capable_nolog(current, cap);
56054 +}
56055 +
56056 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
56057 new file mode 100644
56058 index 0000000..88d0e87
56059 --- /dev/null
56060 +++ b/grsecurity/gracl_fs.c
56061 @@ -0,0 +1,435 @@
56062 +#include <linux/kernel.h>
56063 +#include <linux/sched.h>
56064 +#include <linux/types.h>
56065 +#include <linux/fs.h>
56066 +#include <linux/file.h>
56067 +#include <linux/stat.h>
56068 +#include <linux/grsecurity.h>
56069 +#include <linux/grinternal.h>
56070 +#include <linux/gracl.h>
56071 +
56072 +umode_t
56073 +gr_acl_umask(void)
56074 +{
56075 + if (unlikely(!gr_acl_is_enabled()))
56076 + return 0;
56077 +
56078 + return current->role->umask;
56079 +}
56080 +
56081 +__u32
56082 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56083 + const struct vfsmount * mnt)
56084 +{
56085 + __u32 mode;
56086 +
56087 + if (unlikely(!dentry->d_inode))
56088 + return GR_FIND;
56089 +
56090 + mode =
56091 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56092 +
56093 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56094 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56095 + return mode;
56096 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56097 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56098 + return 0;
56099 + } else if (unlikely(!(mode & GR_FIND)))
56100 + return 0;
56101 +
56102 + return GR_FIND;
56103 +}
56104 +
56105 +__u32
56106 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56107 + int acc_mode)
56108 +{
56109 + __u32 reqmode = GR_FIND;
56110 + __u32 mode;
56111 +
56112 + if (unlikely(!dentry->d_inode))
56113 + return reqmode;
56114 +
56115 + if (acc_mode & MAY_APPEND)
56116 + reqmode |= GR_APPEND;
56117 + else if (acc_mode & MAY_WRITE)
56118 + reqmode |= GR_WRITE;
56119 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56120 + reqmode |= GR_READ;
56121 +
56122 + mode =
56123 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56124 + mnt);
56125 +
56126 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56127 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56128 + reqmode & GR_READ ? " reading" : "",
56129 + reqmode & GR_WRITE ? " writing" : reqmode &
56130 + GR_APPEND ? " appending" : "");
56131 + return reqmode;
56132 + } else
56133 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56134 + {
56135 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56136 + reqmode & GR_READ ? " reading" : "",
56137 + reqmode & GR_WRITE ? " writing" : reqmode &
56138 + GR_APPEND ? " appending" : "");
56139 + return 0;
56140 + } else if (unlikely((mode & reqmode) != reqmode))
56141 + return 0;
56142 +
56143 + return reqmode;
56144 +}
56145 +
56146 +__u32
56147 +gr_acl_handle_creat(const struct dentry * dentry,
56148 + const struct dentry * p_dentry,
56149 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56150 + const int imode)
56151 +{
56152 + __u32 reqmode = GR_WRITE | GR_CREATE;
56153 + __u32 mode;
56154 +
56155 + if (acc_mode & MAY_APPEND)
56156 + reqmode |= GR_APPEND;
56157 + // if a directory was required or the directory already exists, then
56158 + // don't count this open as a read
56159 + if ((acc_mode & MAY_READ) &&
56160 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56161 + reqmode |= GR_READ;
56162 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
56163 + reqmode |= GR_SETID;
56164 +
56165 + mode =
56166 + gr_check_create(dentry, p_dentry, p_mnt,
56167 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56168 +
56169 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56170 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56171 + reqmode & GR_READ ? " reading" : "",
56172 + reqmode & GR_WRITE ? " writing" : reqmode &
56173 + GR_APPEND ? " appending" : "");
56174 + return reqmode;
56175 + } else
56176 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56177 + {
56178 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56179 + reqmode & GR_READ ? " reading" : "",
56180 + reqmode & GR_WRITE ? " writing" : reqmode &
56181 + GR_APPEND ? " appending" : "");
56182 + return 0;
56183 + } else if (unlikely((mode & reqmode) != reqmode))
56184 + return 0;
56185 +
56186 + return reqmode;
56187 +}
56188 +
56189 +__u32
56190 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56191 + const int fmode)
56192 +{
56193 + __u32 mode, reqmode = GR_FIND;
56194 +
56195 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56196 + reqmode |= GR_EXEC;
56197 + if (fmode & S_IWOTH)
56198 + reqmode |= GR_WRITE;
56199 + if (fmode & S_IROTH)
56200 + reqmode |= GR_READ;
56201 +
56202 + mode =
56203 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56204 + mnt);
56205 +
56206 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56207 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56208 + reqmode & GR_READ ? " reading" : "",
56209 + reqmode & GR_WRITE ? " writing" : "",
56210 + reqmode & GR_EXEC ? " executing" : "");
56211 + return reqmode;
56212 + } else
56213 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56214 + {
56215 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56216 + reqmode & GR_READ ? " reading" : "",
56217 + reqmode & GR_WRITE ? " writing" : "",
56218 + reqmode & GR_EXEC ? " executing" : "");
56219 + return 0;
56220 + } else if (unlikely((mode & reqmode) != reqmode))
56221 + return 0;
56222 +
56223 + return reqmode;
56224 +}
56225 +
56226 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56227 +{
56228 + __u32 mode;
56229 +
56230 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56231 +
56232 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56233 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56234 + return mode;
56235 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56236 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56237 + return 0;
56238 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56239 + return 0;
56240 +
56241 + return (reqmode);
56242 +}
56243 +
56244 +__u32
56245 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56246 +{
56247 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56248 +}
56249 +
56250 +__u32
56251 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56252 +{
56253 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56254 +}
56255 +
56256 +__u32
56257 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56258 +{
56259 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56260 +}
56261 +
56262 +__u32
56263 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56264 +{
56265 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56266 +}
56267 +
56268 +__u32
56269 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56270 + umode_t *modeptr)
56271 +{
56272 + umode_t mode;
56273 +
56274 + *modeptr &= ~gr_acl_umask();
56275 + mode = *modeptr;
56276 +
56277 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56278 + return 1;
56279 +
56280 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
56281 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56282 + GR_CHMOD_ACL_MSG);
56283 + } else {
56284 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56285 + }
56286 +}
56287 +
56288 +__u32
56289 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56290 +{
56291 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56292 +}
56293 +
56294 +__u32
56295 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56296 +{
56297 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56298 +}
56299 +
56300 +__u32
56301 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56302 +{
56303 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56304 +}
56305 +
56306 +__u32
56307 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56308 +{
56309 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56310 + GR_UNIXCONNECT_ACL_MSG);
56311 +}
56312 +
56313 +/* hardlinks require at minimum create and link permission,
56314 + any additional privilege required is based on the
56315 + privilege of the file being linked to
56316 +*/
56317 +__u32
56318 +gr_acl_handle_link(const struct dentry * new_dentry,
56319 + const struct dentry * parent_dentry,
56320 + const struct vfsmount * parent_mnt,
56321 + const struct dentry * old_dentry,
56322 + const struct vfsmount * old_mnt, const char *to)
56323 +{
56324 + __u32 mode;
56325 + __u32 needmode = GR_CREATE | GR_LINK;
56326 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56327 +
56328 + mode =
56329 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56330 + old_mnt);
56331 +
56332 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56333 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56334 + return mode;
56335 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56336 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56337 + return 0;
56338 + } else if (unlikely((mode & needmode) != needmode))
56339 + return 0;
56340 +
56341 + return 1;
56342 +}
56343 +
56344 +__u32
56345 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56346 + const struct dentry * parent_dentry,
56347 + const struct vfsmount * parent_mnt, const char *from)
56348 +{
56349 + __u32 needmode = GR_WRITE | GR_CREATE;
56350 + __u32 mode;
56351 +
56352 + mode =
56353 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56354 + GR_CREATE | GR_AUDIT_CREATE |
56355 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56356 +
56357 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56358 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56359 + return mode;
56360 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56361 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56362 + return 0;
56363 + } else if (unlikely((mode & needmode) != needmode))
56364 + return 0;
56365 +
56366 + return (GR_WRITE | GR_CREATE);
56367 +}
56368 +
56369 +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)
56370 +{
56371 + __u32 mode;
56372 +
56373 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56374 +
56375 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56376 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56377 + return mode;
56378 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56379 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56380 + return 0;
56381 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56382 + return 0;
56383 +
56384 + return (reqmode);
56385 +}
56386 +
56387 +__u32
56388 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56389 + const struct dentry * parent_dentry,
56390 + const struct vfsmount * parent_mnt,
56391 + const int mode)
56392 +{
56393 + __u32 reqmode = GR_WRITE | GR_CREATE;
56394 + if (unlikely(mode & (S_ISUID | S_ISGID)))
56395 + reqmode |= GR_SETID;
56396 +
56397 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56398 + reqmode, GR_MKNOD_ACL_MSG);
56399 +}
56400 +
56401 +__u32
56402 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56403 + const struct dentry *parent_dentry,
56404 + const struct vfsmount *parent_mnt)
56405 +{
56406 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56407 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56408 +}
56409 +
56410 +#define RENAME_CHECK_SUCCESS(old, new) \
56411 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56412 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56413 +
56414 +int
56415 +gr_acl_handle_rename(struct dentry *new_dentry,
56416 + struct dentry *parent_dentry,
56417 + const struct vfsmount *parent_mnt,
56418 + struct dentry *old_dentry,
56419 + struct inode *old_parent_inode,
56420 + struct vfsmount *old_mnt, const char *newname)
56421 +{
56422 + __u32 comp1, comp2;
56423 + int error = 0;
56424 +
56425 + if (unlikely(!gr_acl_is_enabled()))
56426 + return 0;
56427 +
56428 + if (!new_dentry->d_inode) {
56429 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56430 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56431 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56432 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56433 + GR_DELETE | GR_AUDIT_DELETE |
56434 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56435 + GR_SUPPRESS, old_mnt);
56436 + } else {
56437 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56438 + GR_CREATE | GR_DELETE |
56439 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56440 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56441 + GR_SUPPRESS, parent_mnt);
56442 + comp2 =
56443 + gr_search_file(old_dentry,
56444 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56445 + GR_DELETE | GR_AUDIT_DELETE |
56446 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56447 + }
56448 +
56449 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56450 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56451 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56452 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56453 + && !(comp2 & GR_SUPPRESS)) {
56454 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56455 + error = -EACCES;
56456 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56457 + error = -EACCES;
56458 +
56459 + return error;
56460 +}
56461 +
56462 +void
56463 +gr_acl_handle_exit(void)
56464 +{
56465 + u16 id;
56466 + char *rolename;
56467 + struct file *exec_file;
56468 +
56469 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56470 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56471 + id = current->acl_role_id;
56472 + rolename = current->role->rolename;
56473 + gr_set_acls(1);
56474 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56475 + }
56476 +
56477 + write_lock(&grsec_exec_file_lock);
56478 + exec_file = current->exec_file;
56479 + current->exec_file = NULL;
56480 + write_unlock(&grsec_exec_file_lock);
56481 +
56482 + if (exec_file)
56483 + fput(exec_file);
56484 +}
56485 +
56486 +int
56487 +gr_acl_handle_procpidmem(const struct task_struct *task)
56488 +{
56489 + if (unlikely(!gr_acl_is_enabled()))
56490 + return 0;
56491 +
56492 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56493 + return -EACCES;
56494 +
56495 + return 0;
56496 +}
56497 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56498 new file mode 100644
56499 index 0000000..58800a7
56500 --- /dev/null
56501 +++ b/grsecurity/gracl_ip.c
56502 @@ -0,0 +1,384 @@
56503 +#include <linux/kernel.h>
56504 +#include <asm/uaccess.h>
56505 +#include <asm/errno.h>
56506 +#include <net/sock.h>
56507 +#include <linux/file.h>
56508 +#include <linux/fs.h>
56509 +#include <linux/net.h>
56510 +#include <linux/in.h>
56511 +#include <linux/skbuff.h>
56512 +#include <linux/ip.h>
56513 +#include <linux/udp.h>
56514 +#include <linux/types.h>
56515 +#include <linux/sched.h>
56516 +#include <linux/netdevice.h>
56517 +#include <linux/inetdevice.h>
56518 +#include <linux/gracl.h>
56519 +#include <linux/grsecurity.h>
56520 +#include <linux/grinternal.h>
56521 +
56522 +#define GR_BIND 0x01
56523 +#define GR_CONNECT 0x02
56524 +#define GR_INVERT 0x04
56525 +#define GR_BINDOVERRIDE 0x08
56526 +#define GR_CONNECTOVERRIDE 0x10
56527 +#define GR_SOCK_FAMILY 0x20
56528 +
56529 +static const char * gr_protocols[IPPROTO_MAX] = {
56530 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56531 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56532 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56533 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56534 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56535 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56536 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56537 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56538 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56539 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56540 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56541 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56542 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56543 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56544 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56545 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56546 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56547 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56548 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56549 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56550 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56551 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56552 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56553 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56554 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56555 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56556 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56557 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56558 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56559 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56560 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56561 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56562 + };
56563 +
56564 +static const char * gr_socktypes[SOCK_MAX] = {
56565 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56566 + "unknown:7", "unknown:8", "unknown:9", "packet"
56567 + };
56568 +
56569 +static const char * gr_sockfamilies[AF_MAX+1] = {
56570 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56571 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56572 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56573 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56574 + };
56575 +
56576 +const char *
56577 +gr_proto_to_name(unsigned char proto)
56578 +{
56579 + return gr_protocols[proto];
56580 +}
56581 +
56582 +const char *
56583 +gr_socktype_to_name(unsigned char type)
56584 +{
56585 + return gr_socktypes[type];
56586 +}
56587 +
56588 +const char *
56589 +gr_sockfamily_to_name(unsigned char family)
56590 +{
56591 + return gr_sockfamilies[family];
56592 +}
56593 +
56594 +int
56595 +gr_search_socket(const int domain, const int type, const int protocol)
56596 +{
56597 + struct acl_subject_label *curr;
56598 + const struct cred *cred = current_cred();
56599 +
56600 + if (unlikely(!gr_acl_is_enabled()))
56601 + goto exit;
56602 +
56603 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56604 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56605 + goto exit; // let the kernel handle it
56606 +
56607 + curr = current->acl;
56608 +
56609 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56610 + /* the family is allowed, if this is PF_INET allow it only if
56611 + the extra sock type/protocol checks pass */
56612 + if (domain == PF_INET)
56613 + goto inet_check;
56614 + goto exit;
56615 + } else {
56616 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56617 + __u32 fakeip = 0;
56618 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56619 + current->role->roletype, cred->uid,
56620 + cred->gid, current->exec_file ?
56621 + gr_to_filename(current->exec_file->f_path.dentry,
56622 + current->exec_file->f_path.mnt) :
56623 + curr->filename, curr->filename,
56624 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56625 + &current->signal->saved_ip);
56626 + goto exit;
56627 + }
56628 + goto exit_fail;
56629 + }
56630 +
56631 +inet_check:
56632 + /* the rest of this checking is for IPv4 only */
56633 + if (!curr->ips)
56634 + goto exit;
56635 +
56636 + if ((curr->ip_type & (1 << type)) &&
56637 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56638 + goto exit;
56639 +
56640 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56641 + /* we don't place acls on raw sockets , and sometimes
56642 + dgram/ip sockets are opened for ioctl and not
56643 + bind/connect, so we'll fake a bind learn log */
56644 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56645 + __u32 fakeip = 0;
56646 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56647 + current->role->roletype, cred->uid,
56648 + cred->gid, current->exec_file ?
56649 + gr_to_filename(current->exec_file->f_path.dentry,
56650 + current->exec_file->f_path.mnt) :
56651 + curr->filename, curr->filename,
56652 + &fakeip, 0, type,
56653 + protocol, GR_CONNECT, &current->signal->saved_ip);
56654 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56655 + __u32 fakeip = 0;
56656 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56657 + current->role->roletype, cred->uid,
56658 + cred->gid, current->exec_file ?
56659 + gr_to_filename(current->exec_file->f_path.dentry,
56660 + current->exec_file->f_path.mnt) :
56661 + curr->filename, curr->filename,
56662 + &fakeip, 0, type,
56663 + protocol, GR_BIND, &current->signal->saved_ip);
56664 + }
56665 + /* we'll log when they use connect or bind */
56666 + goto exit;
56667 + }
56668 +
56669 +exit_fail:
56670 + if (domain == PF_INET)
56671 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56672 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56673 + else
56674 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56675 + gr_socktype_to_name(type), protocol);
56676 +
56677 + return 0;
56678 +exit:
56679 + return 1;
56680 +}
56681 +
56682 +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)
56683 +{
56684 + if ((ip->mode & mode) &&
56685 + (ip_port >= ip->low) &&
56686 + (ip_port <= ip->high) &&
56687 + ((ntohl(ip_addr) & our_netmask) ==
56688 + (ntohl(our_addr) & our_netmask))
56689 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56690 + && (ip->type & (1 << type))) {
56691 + if (ip->mode & GR_INVERT)
56692 + return 2; // specifically denied
56693 + else
56694 + return 1; // allowed
56695 + }
56696 +
56697 + return 0; // not specifically allowed, may continue parsing
56698 +}
56699 +
56700 +static int
56701 +gr_search_connectbind(const int full_mode, struct sock *sk,
56702 + struct sockaddr_in *addr, const int type)
56703 +{
56704 + char iface[IFNAMSIZ] = {0};
56705 + struct acl_subject_label *curr;
56706 + struct acl_ip_label *ip;
56707 + struct inet_sock *isk;
56708 + struct net_device *dev;
56709 + struct in_device *idev;
56710 + unsigned long i;
56711 + int ret;
56712 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56713 + __u32 ip_addr = 0;
56714 + __u32 our_addr;
56715 + __u32 our_netmask;
56716 + char *p;
56717 + __u16 ip_port = 0;
56718 + const struct cred *cred = current_cred();
56719 +
56720 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56721 + return 0;
56722 +
56723 + curr = current->acl;
56724 + isk = inet_sk(sk);
56725 +
56726 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56727 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56728 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56729 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56730 + struct sockaddr_in saddr;
56731 + int err;
56732 +
56733 + saddr.sin_family = AF_INET;
56734 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56735 + saddr.sin_port = isk->inet_sport;
56736 +
56737 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56738 + if (err)
56739 + return err;
56740 +
56741 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56742 + if (err)
56743 + return err;
56744 + }
56745 +
56746 + if (!curr->ips)
56747 + return 0;
56748 +
56749 + ip_addr = addr->sin_addr.s_addr;
56750 + ip_port = ntohs(addr->sin_port);
56751 +
56752 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56753 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56754 + current->role->roletype, cred->uid,
56755 + cred->gid, current->exec_file ?
56756 + gr_to_filename(current->exec_file->f_path.dentry,
56757 + current->exec_file->f_path.mnt) :
56758 + curr->filename, curr->filename,
56759 + &ip_addr, ip_port, type,
56760 + sk->sk_protocol, mode, &current->signal->saved_ip);
56761 + return 0;
56762 + }
56763 +
56764 + for (i = 0; i < curr->ip_num; i++) {
56765 + ip = *(curr->ips + i);
56766 + if (ip->iface != NULL) {
56767 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56768 + p = strchr(iface, ':');
56769 + if (p != NULL)
56770 + *p = '\0';
56771 + dev = dev_get_by_name(sock_net(sk), iface);
56772 + if (dev == NULL)
56773 + continue;
56774 + idev = in_dev_get(dev);
56775 + if (idev == NULL) {
56776 + dev_put(dev);
56777 + continue;
56778 + }
56779 + rcu_read_lock();
56780 + for_ifa(idev) {
56781 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56782 + our_addr = ifa->ifa_address;
56783 + our_netmask = 0xffffffff;
56784 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56785 + if (ret == 1) {
56786 + rcu_read_unlock();
56787 + in_dev_put(idev);
56788 + dev_put(dev);
56789 + return 0;
56790 + } else if (ret == 2) {
56791 + rcu_read_unlock();
56792 + in_dev_put(idev);
56793 + dev_put(dev);
56794 + goto denied;
56795 + }
56796 + }
56797 + } endfor_ifa(idev);
56798 + rcu_read_unlock();
56799 + in_dev_put(idev);
56800 + dev_put(dev);
56801 + } else {
56802 + our_addr = ip->addr;
56803 + our_netmask = ip->netmask;
56804 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56805 + if (ret == 1)
56806 + return 0;
56807 + else if (ret == 2)
56808 + goto denied;
56809 + }
56810 + }
56811 +
56812 +denied:
56813 + if (mode == GR_BIND)
56814 + 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));
56815 + else if (mode == GR_CONNECT)
56816 + 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));
56817 +
56818 + return -EACCES;
56819 +}
56820 +
56821 +int
56822 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56823 +{
56824 + /* always allow disconnection of dgram sockets with connect */
56825 + if (addr->sin_family == AF_UNSPEC)
56826 + return 0;
56827 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56828 +}
56829 +
56830 +int
56831 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56832 +{
56833 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56834 +}
56835 +
56836 +int gr_search_listen(struct socket *sock)
56837 +{
56838 + struct sock *sk = sock->sk;
56839 + struct sockaddr_in addr;
56840 +
56841 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56842 + addr.sin_port = inet_sk(sk)->inet_sport;
56843 +
56844 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56845 +}
56846 +
56847 +int gr_search_accept(struct socket *sock)
56848 +{
56849 + struct sock *sk = sock->sk;
56850 + struct sockaddr_in addr;
56851 +
56852 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56853 + addr.sin_port = inet_sk(sk)->inet_sport;
56854 +
56855 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56856 +}
56857 +
56858 +int
56859 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56860 +{
56861 + if (addr)
56862 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56863 + else {
56864 + struct sockaddr_in sin;
56865 + const struct inet_sock *inet = inet_sk(sk);
56866 +
56867 + sin.sin_addr.s_addr = inet->inet_daddr;
56868 + sin.sin_port = inet->inet_dport;
56869 +
56870 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56871 + }
56872 +}
56873 +
56874 +int
56875 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56876 +{
56877 + struct sockaddr_in sin;
56878 +
56879 + if (unlikely(skb->len < sizeof (struct udphdr)))
56880 + return 0; // skip this packet
56881 +
56882 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56883 + sin.sin_port = udp_hdr(skb)->source;
56884 +
56885 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56886 +}
56887 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56888 new file mode 100644
56889 index 0000000..25f54ef
56890 --- /dev/null
56891 +++ b/grsecurity/gracl_learn.c
56892 @@ -0,0 +1,207 @@
56893 +#include <linux/kernel.h>
56894 +#include <linux/mm.h>
56895 +#include <linux/sched.h>
56896 +#include <linux/poll.h>
56897 +#include <linux/string.h>
56898 +#include <linux/file.h>
56899 +#include <linux/types.h>
56900 +#include <linux/vmalloc.h>
56901 +#include <linux/grinternal.h>
56902 +
56903 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56904 + size_t count, loff_t *ppos);
56905 +extern int gr_acl_is_enabled(void);
56906 +
56907 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56908 +static int gr_learn_attached;
56909 +
56910 +/* use a 512k buffer */
56911 +#define LEARN_BUFFER_SIZE (512 * 1024)
56912 +
56913 +static DEFINE_SPINLOCK(gr_learn_lock);
56914 +static DEFINE_MUTEX(gr_learn_user_mutex);
56915 +
56916 +/* we need to maintain two buffers, so that the kernel context of grlearn
56917 + uses a semaphore around the userspace copying, and the other kernel contexts
56918 + use a spinlock when copying into the buffer, since they cannot sleep
56919 +*/
56920 +static char *learn_buffer;
56921 +static char *learn_buffer_user;
56922 +static int learn_buffer_len;
56923 +static int learn_buffer_user_len;
56924 +
56925 +static ssize_t
56926 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56927 +{
56928 + DECLARE_WAITQUEUE(wait, current);
56929 + ssize_t retval = 0;
56930 +
56931 + add_wait_queue(&learn_wait, &wait);
56932 + set_current_state(TASK_INTERRUPTIBLE);
56933 + do {
56934 + mutex_lock(&gr_learn_user_mutex);
56935 + spin_lock(&gr_learn_lock);
56936 + if (learn_buffer_len)
56937 + break;
56938 + spin_unlock(&gr_learn_lock);
56939 + mutex_unlock(&gr_learn_user_mutex);
56940 + if (file->f_flags & O_NONBLOCK) {
56941 + retval = -EAGAIN;
56942 + goto out;
56943 + }
56944 + if (signal_pending(current)) {
56945 + retval = -ERESTARTSYS;
56946 + goto out;
56947 + }
56948 +
56949 + schedule();
56950 + } while (1);
56951 +
56952 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56953 + learn_buffer_user_len = learn_buffer_len;
56954 + retval = learn_buffer_len;
56955 + learn_buffer_len = 0;
56956 +
56957 + spin_unlock(&gr_learn_lock);
56958 +
56959 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56960 + retval = -EFAULT;
56961 +
56962 + mutex_unlock(&gr_learn_user_mutex);
56963 +out:
56964 + set_current_state(TASK_RUNNING);
56965 + remove_wait_queue(&learn_wait, &wait);
56966 + return retval;
56967 +}
56968 +
56969 +static unsigned int
56970 +poll_learn(struct file * file, poll_table * wait)
56971 +{
56972 + poll_wait(file, &learn_wait, wait);
56973 +
56974 + if (learn_buffer_len)
56975 + return (POLLIN | POLLRDNORM);
56976 +
56977 + return 0;
56978 +}
56979 +
56980 +void
56981 +gr_clear_learn_entries(void)
56982 +{
56983 + char *tmp;
56984 +
56985 + mutex_lock(&gr_learn_user_mutex);
56986 + spin_lock(&gr_learn_lock);
56987 + tmp = learn_buffer;
56988 + learn_buffer = NULL;
56989 + spin_unlock(&gr_learn_lock);
56990 + if (tmp)
56991 + vfree(tmp);
56992 + if (learn_buffer_user != NULL) {
56993 + vfree(learn_buffer_user);
56994 + learn_buffer_user = NULL;
56995 + }
56996 + learn_buffer_len = 0;
56997 + mutex_unlock(&gr_learn_user_mutex);
56998 +
56999 + return;
57000 +}
57001 +
57002 +void
57003 +gr_add_learn_entry(const char *fmt, ...)
57004 +{
57005 + va_list args;
57006 + unsigned int len;
57007 +
57008 + if (!gr_learn_attached)
57009 + return;
57010 +
57011 + spin_lock(&gr_learn_lock);
57012 +
57013 + /* leave a gap at the end so we know when it's "full" but don't have to
57014 + compute the exact length of the string we're trying to append
57015 + */
57016 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
57017 + spin_unlock(&gr_learn_lock);
57018 + wake_up_interruptible(&learn_wait);
57019 + return;
57020 + }
57021 + if (learn_buffer == NULL) {
57022 + spin_unlock(&gr_learn_lock);
57023 + return;
57024 + }
57025 +
57026 + va_start(args, fmt);
57027 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
57028 + va_end(args);
57029 +
57030 + learn_buffer_len += len + 1;
57031 +
57032 + spin_unlock(&gr_learn_lock);
57033 + wake_up_interruptible(&learn_wait);
57034 +
57035 + return;
57036 +}
57037 +
57038 +static int
57039 +open_learn(struct inode *inode, struct file *file)
57040 +{
57041 + if (file->f_mode & FMODE_READ && gr_learn_attached)
57042 + return -EBUSY;
57043 + if (file->f_mode & FMODE_READ) {
57044 + int retval = 0;
57045 + mutex_lock(&gr_learn_user_mutex);
57046 + if (learn_buffer == NULL)
57047 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
57048 + if (learn_buffer_user == NULL)
57049 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
57050 + if (learn_buffer == NULL) {
57051 + retval = -ENOMEM;
57052 + goto out_error;
57053 + }
57054 + if (learn_buffer_user == NULL) {
57055 + retval = -ENOMEM;
57056 + goto out_error;
57057 + }
57058 + learn_buffer_len = 0;
57059 + learn_buffer_user_len = 0;
57060 + gr_learn_attached = 1;
57061 +out_error:
57062 + mutex_unlock(&gr_learn_user_mutex);
57063 + return retval;
57064 + }
57065 + return 0;
57066 +}
57067 +
57068 +static int
57069 +close_learn(struct inode *inode, struct file *file)
57070 +{
57071 + if (file->f_mode & FMODE_READ) {
57072 + char *tmp = NULL;
57073 + mutex_lock(&gr_learn_user_mutex);
57074 + spin_lock(&gr_learn_lock);
57075 + tmp = learn_buffer;
57076 + learn_buffer = NULL;
57077 + spin_unlock(&gr_learn_lock);
57078 + if (tmp)
57079 + vfree(tmp);
57080 + if (learn_buffer_user != NULL) {
57081 + vfree(learn_buffer_user);
57082 + learn_buffer_user = NULL;
57083 + }
57084 + learn_buffer_len = 0;
57085 + learn_buffer_user_len = 0;
57086 + gr_learn_attached = 0;
57087 + mutex_unlock(&gr_learn_user_mutex);
57088 + }
57089 +
57090 + return 0;
57091 +}
57092 +
57093 +const struct file_operations grsec_fops = {
57094 + .read = read_learn,
57095 + .write = write_grsec_handler,
57096 + .open = open_learn,
57097 + .release = close_learn,
57098 + .poll = poll_learn,
57099 +};
57100 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57101 new file mode 100644
57102 index 0000000..39645c9
57103 --- /dev/null
57104 +++ b/grsecurity/gracl_res.c
57105 @@ -0,0 +1,68 @@
57106 +#include <linux/kernel.h>
57107 +#include <linux/sched.h>
57108 +#include <linux/gracl.h>
57109 +#include <linux/grinternal.h>
57110 +
57111 +static const char *restab_log[] = {
57112 + [RLIMIT_CPU] = "RLIMIT_CPU",
57113 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57114 + [RLIMIT_DATA] = "RLIMIT_DATA",
57115 + [RLIMIT_STACK] = "RLIMIT_STACK",
57116 + [RLIMIT_CORE] = "RLIMIT_CORE",
57117 + [RLIMIT_RSS] = "RLIMIT_RSS",
57118 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57119 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57120 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57121 + [RLIMIT_AS] = "RLIMIT_AS",
57122 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57123 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57124 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57125 + [RLIMIT_NICE] = "RLIMIT_NICE",
57126 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57127 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57128 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57129 +};
57130 +
57131 +void
57132 +gr_log_resource(const struct task_struct *task,
57133 + const int res, const unsigned long wanted, const int gt)
57134 +{
57135 + const struct cred *cred;
57136 + unsigned long rlim;
57137 +
57138 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57139 + return;
57140 +
57141 + // not yet supported resource
57142 + if (unlikely(!restab_log[res]))
57143 + return;
57144 +
57145 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57146 + rlim = task_rlimit_max(task, res);
57147 + else
57148 + rlim = task_rlimit(task, res);
57149 +
57150 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57151 + return;
57152 +
57153 + rcu_read_lock();
57154 + cred = __task_cred(task);
57155 +
57156 + if (res == RLIMIT_NPROC &&
57157 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57158 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57159 + goto out_rcu_unlock;
57160 + else if (res == RLIMIT_MEMLOCK &&
57161 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57162 + goto out_rcu_unlock;
57163 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57164 + goto out_rcu_unlock;
57165 + rcu_read_unlock();
57166 +
57167 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57168 +
57169 + return;
57170 +out_rcu_unlock:
57171 + rcu_read_unlock();
57172 + return;
57173 +}
57174 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57175 new file mode 100644
57176 index 0000000..5556be3
57177 --- /dev/null
57178 +++ b/grsecurity/gracl_segv.c
57179 @@ -0,0 +1,299 @@
57180 +#include <linux/kernel.h>
57181 +#include <linux/mm.h>
57182 +#include <asm/uaccess.h>
57183 +#include <asm/errno.h>
57184 +#include <asm/mman.h>
57185 +#include <net/sock.h>
57186 +#include <linux/file.h>
57187 +#include <linux/fs.h>
57188 +#include <linux/net.h>
57189 +#include <linux/in.h>
57190 +#include <linux/slab.h>
57191 +#include <linux/types.h>
57192 +#include <linux/sched.h>
57193 +#include <linux/timer.h>
57194 +#include <linux/gracl.h>
57195 +#include <linux/grsecurity.h>
57196 +#include <linux/grinternal.h>
57197 +
57198 +static struct crash_uid *uid_set;
57199 +static unsigned short uid_used;
57200 +static DEFINE_SPINLOCK(gr_uid_lock);
57201 +extern rwlock_t gr_inode_lock;
57202 +extern struct acl_subject_label *
57203 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57204 + struct acl_role_label *role);
57205 +
57206 +#ifdef CONFIG_BTRFS_FS
57207 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57208 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57209 +#endif
57210 +
57211 +static inline dev_t __get_dev(const struct dentry *dentry)
57212 +{
57213 +#ifdef CONFIG_BTRFS_FS
57214 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57215 + return get_btrfs_dev_from_inode(dentry->d_inode);
57216 + else
57217 +#endif
57218 + return dentry->d_inode->i_sb->s_dev;
57219 +}
57220 +
57221 +int
57222 +gr_init_uidset(void)
57223 +{
57224 + uid_set =
57225 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57226 + uid_used = 0;
57227 +
57228 + return uid_set ? 1 : 0;
57229 +}
57230 +
57231 +void
57232 +gr_free_uidset(void)
57233 +{
57234 + if (uid_set)
57235 + kfree(uid_set);
57236 +
57237 + return;
57238 +}
57239 +
57240 +int
57241 +gr_find_uid(const uid_t uid)
57242 +{
57243 + struct crash_uid *tmp = uid_set;
57244 + uid_t buid;
57245 + int low = 0, high = uid_used - 1, mid;
57246 +
57247 + while (high >= low) {
57248 + mid = (low + high) >> 1;
57249 + buid = tmp[mid].uid;
57250 + if (buid == uid)
57251 + return mid;
57252 + if (buid > uid)
57253 + high = mid - 1;
57254 + if (buid < uid)
57255 + low = mid + 1;
57256 + }
57257 +
57258 + return -1;
57259 +}
57260 +
57261 +static __inline__ void
57262 +gr_insertsort(void)
57263 +{
57264 + unsigned short i, j;
57265 + struct crash_uid index;
57266 +
57267 + for (i = 1; i < uid_used; i++) {
57268 + index = uid_set[i];
57269 + j = i;
57270 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57271 + uid_set[j] = uid_set[j - 1];
57272 + j--;
57273 + }
57274 + uid_set[j] = index;
57275 + }
57276 +
57277 + return;
57278 +}
57279 +
57280 +static __inline__ void
57281 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57282 +{
57283 + int loc;
57284 +
57285 + if (uid_used == GR_UIDTABLE_MAX)
57286 + return;
57287 +
57288 + loc = gr_find_uid(uid);
57289 +
57290 + if (loc >= 0) {
57291 + uid_set[loc].expires = expires;
57292 + return;
57293 + }
57294 +
57295 + uid_set[uid_used].uid = uid;
57296 + uid_set[uid_used].expires = expires;
57297 + uid_used++;
57298 +
57299 + gr_insertsort();
57300 +
57301 + return;
57302 +}
57303 +
57304 +void
57305 +gr_remove_uid(const unsigned short loc)
57306 +{
57307 + unsigned short i;
57308 +
57309 + for (i = loc + 1; i < uid_used; i++)
57310 + uid_set[i - 1] = uid_set[i];
57311 +
57312 + uid_used--;
57313 +
57314 + return;
57315 +}
57316 +
57317 +int
57318 +gr_check_crash_uid(const uid_t uid)
57319 +{
57320 + int loc;
57321 + int ret = 0;
57322 +
57323 + if (unlikely(!gr_acl_is_enabled()))
57324 + return 0;
57325 +
57326 + spin_lock(&gr_uid_lock);
57327 + loc = gr_find_uid(uid);
57328 +
57329 + if (loc < 0)
57330 + goto out_unlock;
57331 +
57332 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57333 + gr_remove_uid(loc);
57334 + else
57335 + ret = 1;
57336 +
57337 +out_unlock:
57338 + spin_unlock(&gr_uid_lock);
57339 + return ret;
57340 +}
57341 +
57342 +static __inline__ int
57343 +proc_is_setxid(const struct cred *cred)
57344 +{
57345 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
57346 + cred->uid != cred->fsuid)
57347 + return 1;
57348 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
57349 + cred->gid != cred->fsgid)
57350 + return 1;
57351 +
57352 + return 0;
57353 +}
57354 +
57355 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57356 +
57357 +void
57358 +gr_handle_crash(struct task_struct *task, const int sig)
57359 +{
57360 + struct acl_subject_label *curr;
57361 + struct task_struct *tsk, *tsk2;
57362 + const struct cred *cred;
57363 + const struct cred *cred2;
57364 +
57365 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57366 + return;
57367 +
57368 + if (unlikely(!gr_acl_is_enabled()))
57369 + return;
57370 +
57371 + curr = task->acl;
57372 +
57373 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57374 + return;
57375 +
57376 + if (time_before_eq(curr->expires, get_seconds())) {
57377 + curr->expires = 0;
57378 + curr->crashes = 0;
57379 + }
57380 +
57381 + curr->crashes++;
57382 +
57383 + if (!curr->expires)
57384 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57385 +
57386 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57387 + time_after(curr->expires, get_seconds())) {
57388 + rcu_read_lock();
57389 + cred = __task_cred(task);
57390 + if (cred->uid && proc_is_setxid(cred)) {
57391 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57392 + spin_lock(&gr_uid_lock);
57393 + gr_insert_uid(cred->uid, curr->expires);
57394 + spin_unlock(&gr_uid_lock);
57395 + curr->expires = 0;
57396 + curr->crashes = 0;
57397 + read_lock(&tasklist_lock);
57398 + do_each_thread(tsk2, tsk) {
57399 + cred2 = __task_cred(tsk);
57400 + if (tsk != task && cred2->uid == cred->uid)
57401 + gr_fake_force_sig(SIGKILL, tsk);
57402 + } while_each_thread(tsk2, tsk);
57403 + read_unlock(&tasklist_lock);
57404 + } else {
57405 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57406 + read_lock(&tasklist_lock);
57407 + read_lock(&grsec_exec_file_lock);
57408 + do_each_thread(tsk2, tsk) {
57409 + if (likely(tsk != task)) {
57410 + // if this thread has the same subject as the one that triggered
57411 + // RES_CRASH and it's the same binary, kill it
57412 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57413 + gr_fake_force_sig(SIGKILL, tsk);
57414 + }
57415 + } while_each_thread(tsk2, tsk);
57416 + read_unlock(&grsec_exec_file_lock);
57417 + read_unlock(&tasklist_lock);
57418 + }
57419 + rcu_read_unlock();
57420 + }
57421 +
57422 + return;
57423 +}
57424 +
57425 +int
57426 +gr_check_crash_exec(const struct file *filp)
57427 +{
57428 + struct acl_subject_label *curr;
57429 +
57430 + if (unlikely(!gr_acl_is_enabled()))
57431 + return 0;
57432 +
57433 + read_lock(&gr_inode_lock);
57434 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57435 + __get_dev(filp->f_path.dentry),
57436 + current->role);
57437 + read_unlock(&gr_inode_lock);
57438 +
57439 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57440 + (!curr->crashes && !curr->expires))
57441 + return 0;
57442 +
57443 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57444 + time_after(curr->expires, get_seconds()))
57445 + return 1;
57446 + else if (time_before_eq(curr->expires, get_seconds())) {
57447 + curr->crashes = 0;
57448 + curr->expires = 0;
57449 + }
57450 +
57451 + return 0;
57452 +}
57453 +
57454 +void
57455 +gr_handle_alertkill(struct task_struct *task)
57456 +{
57457 + struct acl_subject_label *curracl;
57458 + __u32 curr_ip;
57459 + struct task_struct *p, *p2;
57460 +
57461 + if (unlikely(!gr_acl_is_enabled()))
57462 + return;
57463 +
57464 + curracl = task->acl;
57465 + curr_ip = task->signal->curr_ip;
57466 +
57467 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57468 + read_lock(&tasklist_lock);
57469 + do_each_thread(p2, p) {
57470 + if (p->signal->curr_ip == curr_ip)
57471 + gr_fake_force_sig(SIGKILL, p);
57472 + } while_each_thread(p2, p);
57473 + read_unlock(&tasklist_lock);
57474 + } else if (curracl->mode & GR_KILLPROC)
57475 + gr_fake_force_sig(SIGKILL, task);
57476 +
57477 + return;
57478 +}
57479 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57480 new file mode 100644
57481 index 0000000..9d83a69
57482 --- /dev/null
57483 +++ b/grsecurity/gracl_shm.c
57484 @@ -0,0 +1,40 @@
57485 +#include <linux/kernel.h>
57486 +#include <linux/mm.h>
57487 +#include <linux/sched.h>
57488 +#include <linux/file.h>
57489 +#include <linux/ipc.h>
57490 +#include <linux/gracl.h>
57491 +#include <linux/grsecurity.h>
57492 +#include <linux/grinternal.h>
57493 +
57494 +int
57495 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57496 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57497 +{
57498 + struct task_struct *task;
57499 +
57500 + if (!gr_acl_is_enabled())
57501 + return 1;
57502 +
57503 + rcu_read_lock();
57504 + read_lock(&tasklist_lock);
57505 +
57506 + task = find_task_by_vpid(shm_cprid);
57507 +
57508 + if (unlikely(!task))
57509 + task = find_task_by_vpid(shm_lapid);
57510 +
57511 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57512 + (task->pid == shm_lapid)) &&
57513 + (task->acl->mode & GR_PROTSHM) &&
57514 + (task->acl != current->acl))) {
57515 + read_unlock(&tasklist_lock);
57516 + rcu_read_unlock();
57517 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57518 + return 0;
57519 + }
57520 + read_unlock(&tasklist_lock);
57521 + rcu_read_unlock();
57522 +
57523 + return 1;
57524 +}
57525 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57526 new file mode 100644
57527 index 0000000..bc0be01
57528 --- /dev/null
57529 +++ b/grsecurity/grsec_chdir.c
57530 @@ -0,0 +1,19 @@
57531 +#include <linux/kernel.h>
57532 +#include <linux/sched.h>
57533 +#include <linux/fs.h>
57534 +#include <linux/file.h>
57535 +#include <linux/grsecurity.h>
57536 +#include <linux/grinternal.h>
57537 +
57538 +void
57539 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57540 +{
57541 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57542 + if ((grsec_enable_chdir && grsec_enable_group &&
57543 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57544 + !grsec_enable_group)) {
57545 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57546 + }
57547 +#endif
57548 + return;
57549 +}
57550 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57551 new file mode 100644
57552 index 0000000..9807ee2
57553 --- /dev/null
57554 +++ b/grsecurity/grsec_chroot.c
57555 @@ -0,0 +1,368 @@
57556 +#include <linux/kernel.h>
57557 +#include <linux/module.h>
57558 +#include <linux/sched.h>
57559 +#include <linux/file.h>
57560 +#include <linux/fs.h>
57561 +#include <linux/mount.h>
57562 +#include <linux/types.h>
57563 +#include "../fs/mount.h"
57564 +#include <linux/grsecurity.h>
57565 +#include <linux/grinternal.h>
57566 +
57567 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57568 +{
57569 +#ifdef CONFIG_GRKERNSEC
57570 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57571 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57572 + task->gr_is_chrooted = 1;
57573 + else
57574 + task->gr_is_chrooted = 0;
57575 +
57576 + task->gr_chroot_dentry = path->dentry;
57577 +#endif
57578 + return;
57579 +}
57580 +
57581 +void gr_clear_chroot_entries(struct task_struct *task)
57582 +{
57583 +#ifdef CONFIG_GRKERNSEC
57584 + task->gr_is_chrooted = 0;
57585 + task->gr_chroot_dentry = NULL;
57586 +#endif
57587 + return;
57588 +}
57589 +
57590 +int
57591 +gr_handle_chroot_unix(const pid_t pid)
57592 +{
57593 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57594 + struct task_struct *p;
57595 +
57596 + if (unlikely(!grsec_enable_chroot_unix))
57597 + return 1;
57598 +
57599 + if (likely(!proc_is_chrooted(current)))
57600 + return 1;
57601 +
57602 + rcu_read_lock();
57603 + read_lock(&tasklist_lock);
57604 + p = find_task_by_vpid_unrestricted(pid);
57605 + if (unlikely(p && !have_same_root(current, p))) {
57606 + read_unlock(&tasklist_lock);
57607 + rcu_read_unlock();
57608 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57609 + return 0;
57610 + }
57611 + read_unlock(&tasklist_lock);
57612 + rcu_read_unlock();
57613 +#endif
57614 + return 1;
57615 +}
57616 +
57617 +int
57618 +gr_handle_chroot_nice(void)
57619 +{
57620 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57621 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57622 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57623 + return -EPERM;
57624 + }
57625 +#endif
57626 + return 0;
57627 +}
57628 +
57629 +int
57630 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57631 +{
57632 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57633 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57634 + && proc_is_chrooted(current)) {
57635 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57636 + return -EACCES;
57637 + }
57638 +#endif
57639 + return 0;
57640 +}
57641 +
57642 +int
57643 +gr_handle_chroot_rawio(const struct inode *inode)
57644 +{
57645 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57646 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57647 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57648 + return 1;
57649 +#endif
57650 + return 0;
57651 +}
57652 +
57653 +int
57654 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57655 +{
57656 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57657 + struct task_struct *p;
57658 + int ret = 0;
57659 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57660 + return ret;
57661 +
57662 + read_lock(&tasklist_lock);
57663 + do_each_pid_task(pid, type, p) {
57664 + if (!have_same_root(current, p)) {
57665 + ret = 1;
57666 + goto out;
57667 + }
57668 + } while_each_pid_task(pid, type, p);
57669 +out:
57670 + read_unlock(&tasklist_lock);
57671 + return ret;
57672 +#endif
57673 + return 0;
57674 +}
57675 +
57676 +int
57677 +gr_pid_is_chrooted(struct task_struct *p)
57678 +{
57679 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57680 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57681 + return 0;
57682 +
57683 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57684 + !have_same_root(current, p)) {
57685 + return 1;
57686 + }
57687 +#endif
57688 + return 0;
57689 +}
57690 +
57691 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57692 +
57693 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57694 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57695 +{
57696 + struct path path, currentroot;
57697 + int ret = 0;
57698 +
57699 + path.dentry = (struct dentry *)u_dentry;
57700 + path.mnt = (struct vfsmount *)u_mnt;
57701 + get_fs_root(current->fs, &currentroot);
57702 + if (path_is_under(&path, &currentroot))
57703 + ret = 1;
57704 + path_put(&currentroot);
57705 +
57706 + return ret;
57707 +}
57708 +#endif
57709 +
57710 +int
57711 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57712 +{
57713 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57714 + if (!grsec_enable_chroot_fchdir)
57715 + return 1;
57716 +
57717 + if (!proc_is_chrooted(current))
57718 + return 1;
57719 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57720 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57721 + return 0;
57722 + }
57723 +#endif
57724 + return 1;
57725 +}
57726 +
57727 +int
57728 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57729 + const time_t shm_createtime)
57730 +{
57731 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57732 + struct task_struct *p;
57733 + time_t starttime;
57734 +
57735 + if (unlikely(!grsec_enable_chroot_shmat))
57736 + return 1;
57737 +
57738 + if (likely(!proc_is_chrooted(current)))
57739 + return 1;
57740 +
57741 + rcu_read_lock();
57742 + read_lock(&tasklist_lock);
57743 +
57744 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57745 + starttime = p->start_time.tv_sec;
57746 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57747 + if (have_same_root(current, p)) {
57748 + goto allow;
57749 + } else {
57750 + read_unlock(&tasklist_lock);
57751 + rcu_read_unlock();
57752 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57753 + return 0;
57754 + }
57755 + }
57756 + /* creator exited, pid reuse, fall through to next check */
57757 + }
57758 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57759 + if (unlikely(!have_same_root(current, p))) {
57760 + read_unlock(&tasklist_lock);
57761 + rcu_read_unlock();
57762 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57763 + return 0;
57764 + }
57765 + }
57766 +
57767 +allow:
57768 + read_unlock(&tasklist_lock);
57769 + rcu_read_unlock();
57770 +#endif
57771 + return 1;
57772 +}
57773 +
57774 +void
57775 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57776 +{
57777 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57778 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57779 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57780 +#endif
57781 + return;
57782 +}
57783 +
57784 +int
57785 +gr_handle_chroot_mknod(const struct dentry *dentry,
57786 + const struct vfsmount *mnt, const int mode)
57787 +{
57788 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57789 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57790 + proc_is_chrooted(current)) {
57791 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57792 + return -EPERM;
57793 + }
57794 +#endif
57795 + return 0;
57796 +}
57797 +
57798 +int
57799 +gr_handle_chroot_mount(const struct dentry *dentry,
57800 + const struct vfsmount *mnt, const char *dev_name)
57801 +{
57802 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57803 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57804 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57805 + return -EPERM;
57806 + }
57807 +#endif
57808 + return 0;
57809 +}
57810 +
57811 +int
57812 +gr_handle_chroot_pivot(void)
57813 +{
57814 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57815 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57816 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57817 + return -EPERM;
57818 + }
57819 +#endif
57820 + return 0;
57821 +}
57822 +
57823 +int
57824 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57825 +{
57826 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57827 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57828 + !gr_is_outside_chroot(dentry, mnt)) {
57829 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57830 + return -EPERM;
57831 + }
57832 +#endif
57833 + return 0;
57834 +}
57835 +
57836 +extern const char *captab_log[];
57837 +extern int captab_log_entries;
57838 +
57839 +int
57840 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57841 +{
57842 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57843 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57844 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57845 + if (cap_raised(chroot_caps, cap)) {
57846 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57847 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57848 + }
57849 + return 0;
57850 + }
57851 + }
57852 +#endif
57853 + return 1;
57854 +}
57855 +
57856 +int
57857 +gr_chroot_is_capable(const int cap)
57858 +{
57859 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57860 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57861 +#endif
57862 + return 1;
57863 +}
57864 +
57865 +int
57866 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57867 +{
57868 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57869 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57870 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57871 + if (cap_raised(chroot_caps, cap)) {
57872 + return 0;
57873 + }
57874 + }
57875 +#endif
57876 + return 1;
57877 +}
57878 +
57879 +int
57880 +gr_chroot_is_capable_nolog(const int cap)
57881 +{
57882 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57883 + return gr_task_chroot_is_capable_nolog(current, cap);
57884 +#endif
57885 + return 1;
57886 +}
57887 +
57888 +int
57889 +gr_handle_chroot_sysctl(const int op)
57890 +{
57891 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57892 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57893 + proc_is_chrooted(current))
57894 + return -EACCES;
57895 +#endif
57896 + return 0;
57897 +}
57898 +
57899 +void
57900 +gr_handle_chroot_chdir(struct path *path)
57901 +{
57902 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57903 + if (grsec_enable_chroot_chdir)
57904 + set_fs_pwd(current->fs, path);
57905 +#endif
57906 + return;
57907 +}
57908 +
57909 +int
57910 +gr_handle_chroot_chmod(const struct dentry *dentry,
57911 + const struct vfsmount *mnt, const int mode)
57912 +{
57913 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57914 + /* allow chmod +s on directories, but not files */
57915 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57916 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57917 + proc_is_chrooted(current)) {
57918 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57919 + return -EPERM;
57920 + }
57921 +#endif
57922 + return 0;
57923 +}
57924 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57925 new file mode 100644
57926 index 0000000..213ad8b
57927 --- /dev/null
57928 +++ b/grsecurity/grsec_disabled.c
57929 @@ -0,0 +1,437 @@
57930 +#include <linux/kernel.h>
57931 +#include <linux/module.h>
57932 +#include <linux/sched.h>
57933 +#include <linux/file.h>
57934 +#include <linux/fs.h>
57935 +#include <linux/kdev_t.h>
57936 +#include <linux/net.h>
57937 +#include <linux/in.h>
57938 +#include <linux/ip.h>
57939 +#include <linux/skbuff.h>
57940 +#include <linux/sysctl.h>
57941 +
57942 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57943 +void
57944 +pax_set_initial_flags(struct linux_binprm *bprm)
57945 +{
57946 + return;
57947 +}
57948 +#endif
57949 +
57950 +#ifdef CONFIG_SYSCTL
57951 +__u32
57952 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57953 +{
57954 + return 0;
57955 +}
57956 +#endif
57957 +
57958 +#ifdef CONFIG_TASKSTATS
57959 +int gr_is_taskstats_denied(int pid)
57960 +{
57961 + return 0;
57962 +}
57963 +#endif
57964 +
57965 +int
57966 +gr_acl_is_enabled(void)
57967 +{
57968 + return 0;
57969 +}
57970 +
57971 +void
57972 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57973 +{
57974 + return;
57975 +}
57976 +
57977 +int
57978 +gr_handle_rawio(const struct inode *inode)
57979 +{
57980 + return 0;
57981 +}
57982 +
57983 +void
57984 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57985 +{
57986 + return;
57987 +}
57988 +
57989 +int
57990 +gr_handle_ptrace(struct task_struct *task, const long request)
57991 +{
57992 + return 0;
57993 +}
57994 +
57995 +int
57996 +gr_handle_proc_ptrace(struct task_struct *task)
57997 +{
57998 + return 0;
57999 +}
58000 +
58001 +void
58002 +gr_learn_resource(const struct task_struct *task,
58003 + const int res, const unsigned long wanted, const int gt)
58004 +{
58005 + return;
58006 +}
58007 +
58008 +int
58009 +gr_set_acls(const int type)
58010 +{
58011 + return 0;
58012 +}
58013 +
58014 +int
58015 +gr_check_hidden_task(const struct task_struct *tsk)
58016 +{
58017 + return 0;
58018 +}
58019 +
58020 +int
58021 +gr_check_protected_task(const struct task_struct *task)
58022 +{
58023 + return 0;
58024 +}
58025 +
58026 +int
58027 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58028 +{
58029 + return 0;
58030 +}
58031 +
58032 +void
58033 +gr_copy_label(struct task_struct *tsk)
58034 +{
58035 + return;
58036 +}
58037 +
58038 +void
58039 +gr_set_pax_flags(struct task_struct *task)
58040 +{
58041 + return;
58042 +}
58043 +
58044 +int
58045 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58046 + const int unsafe_share)
58047 +{
58048 + return 0;
58049 +}
58050 +
58051 +void
58052 +gr_handle_delete(const ino_t ino, const dev_t dev)
58053 +{
58054 + return;
58055 +}
58056 +
58057 +void
58058 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58059 +{
58060 + return;
58061 +}
58062 +
58063 +void
58064 +gr_handle_crash(struct task_struct *task, const int sig)
58065 +{
58066 + return;
58067 +}
58068 +
58069 +int
58070 +gr_check_crash_exec(const struct file *filp)
58071 +{
58072 + return 0;
58073 +}
58074 +
58075 +int
58076 +gr_check_crash_uid(const uid_t uid)
58077 +{
58078 + return 0;
58079 +}
58080 +
58081 +void
58082 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58083 + struct dentry *old_dentry,
58084 + struct dentry *new_dentry,
58085 + struct vfsmount *mnt, const __u8 replace)
58086 +{
58087 + return;
58088 +}
58089 +
58090 +int
58091 +gr_search_socket(const int family, const int type, const int protocol)
58092 +{
58093 + return 1;
58094 +}
58095 +
58096 +int
58097 +gr_search_connectbind(const int mode, const struct socket *sock,
58098 + const struct sockaddr_in *addr)
58099 +{
58100 + return 0;
58101 +}
58102 +
58103 +void
58104 +gr_handle_alertkill(struct task_struct *task)
58105 +{
58106 + return;
58107 +}
58108 +
58109 +__u32
58110 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58111 +{
58112 + return 1;
58113 +}
58114 +
58115 +__u32
58116 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58117 + const struct vfsmount * mnt)
58118 +{
58119 + return 1;
58120 +}
58121 +
58122 +__u32
58123 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58124 + int acc_mode)
58125 +{
58126 + return 1;
58127 +}
58128 +
58129 +__u32
58130 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58131 +{
58132 + return 1;
58133 +}
58134 +
58135 +__u32
58136 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58137 +{
58138 + return 1;
58139 +}
58140 +
58141 +int
58142 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58143 + unsigned int *vm_flags)
58144 +{
58145 + return 1;
58146 +}
58147 +
58148 +__u32
58149 +gr_acl_handle_truncate(const struct dentry * dentry,
58150 + const struct vfsmount * mnt)
58151 +{
58152 + return 1;
58153 +}
58154 +
58155 +__u32
58156 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58157 +{
58158 + return 1;
58159 +}
58160 +
58161 +__u32
58162 +gr_acl_handle_access(const struct dentry * dentry,
58163 + const struct vfsmount * mnt, const int fmode)
58164 +{
58165 + return 1;
58166 +}
58167 +
58168 +__u32
58169 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58170 + umode_t *mode)
58171 +{
58172 + return 1;
58173 +}
58174 +
58175 +__u32
58176 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58177 +{
58178 + return 1;
58179 +}
58180 +
58181 +__u32
58182 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58183 +{
58184 + return 1;
58185 +}
58186 +
58187 +void
58188 +grsecurity_init(void)
58189 +{
58190 + return;
58191 +}
58192 +
58193 +umode_t gr_acl_umask(void)
58194 +{
58195 + return 0;
58196 +}
58197 +
58198 +__u32
58199 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58200 + const struct dentry * parent_dentry,
58201 + const struct vfsmount * parent_mnt,
58202 + const int mode)
58203 +{
58204 + return 1;
58205 +}
58206 +
58207 +__u32
58208 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58209 + const struct dentry * parent_dentry,
58210 + const struct vfsmount * parent_mnt)
58211 +{
58212 + return 1;
58213 +}
58214 +
58215 +__u32
58216 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58217 + const struct dentry * parent_dentry,
58218 + const struct vfsmount * parent_mnt, const char *from)
58219 +{
58220 + return 1;
58221 +}
58222 +
58223 +__u32
58224 +gr_acl_handle_link(const struct dentry * new_dentry,
58225 + const struct dentry * parent_dentry,
58226 + const struct vfsmount * parent_mnt,
58227 + const struct dentry * old_dentry,
58228 + const struct vfsmount * old_mnt, const char *to)
58229 +{
58230 + return 1;
58231 +}
58232 +
58233 +int
58234 +gr_acl_handle_rename(const struct dentry *new_dentry,
58235 + const struct dentry *parent_dentry,
58236 + const struct vfsmount *parent_mnt,
58237 + const struct dentry *old_dentry,
58238 + const struct inode *old_parent_inode,
58239 + const struct vfsmount *old_mnt, const char *newname)
58240 +{
58241 + return 0;
58242 +}
58243 +
58244 +int
58245 +gr_acl_handle_filldir(const struct file *file, const char *name,
58246 + const int namelen, const ino_t ino)
58247 +{
58248 + return 1;
58249 +}
58250 +
58251 +int
58252 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58253 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58254 +{
58255 + return 1;
58256 +}
58257 +
58258 +int
58259 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58260 +{
58261 + return 0;
58262 +}
58263 +
58264 +int
58265 +gr_search_accept(const struct socket *sock)
58266 +{
58267 + return 0;
58268 +}
58269 +
58270 +int
58271 +gr_search_listen(const struct socket *sock)
58272 +{
58273 + return 0;
58274 +}
58275 +
58276 +int
58277 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58278 +{
58279 + return 0;
58280 +}
58281 +
58282 +__u32
58283 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58284 +{
58285 + return 1;
58286 +}
58287 +
58288 +__u32
58289 +gr_acl_handle_creat(const struct dentry * dentry,
58290 + const struct dentry * p_dentry,
58291 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58292 + const int imode)
58293 +{
58294 + return 1;
58295 +}
58296 +
58297 +void
58298 +gr_acl_handle_exit(void)
58299 +{
58300 + return;
58301 +}
58302 +
58303 +int
58304 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58305 +{
58306 + return 1;
58307 +}
58308 +
58309 +void
58310 +gr_set_role_label(const uid_t uid, const gid_t gid)
58311 +{
58312 + return;
58313 +}
58314 +
58315 +int
58316 +gr_acl_handle_procpidmem(const struct task_struct *task)
58317 +{
58318 + return 0;
58319 +}
58320 +
58321 +int
58322 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58323 +{
58324 + return 0;
58325 +}
58326 +
58327 +int
58328 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58329 +{
58330 + return 0;
58331 +}
58332 +
58333 +void
58334 +gr_set_kernel_label(struct task_struct *task)
58335 +{
58336 + return;
58337 +}
58338 +
58339 +int
58340 +gr_check_user_change(int real, int effective, int fs)
58341 +{
58342 + return 0;
58343 +}
58344 +
58345 +int
58346 +gr_check_group_change(int real, int effective, int fs)
58347 +{
58348 + return 0;
58349 +}
58350 +
58351 +int gr_acl_enable_at_secure(void)
58352 +{
58353 + return 0;
58354 +}
58355 +
58356 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58357 +{
58358 + return dentry->d_inode->i_sb->s_dev;
58359 +}
58360 +
58361 +EXPORT_SYMBOL(gr_learn_resource);
58362 +EXPORT_SYMBOL(gr_set_kernel_label);
58363 +#ifdef CONFIG_SECURITY
58364 +EXPORT_SYMBOL(gr_check_user_change);
58365 +EXPORT_SYMBOL(gr_check_group_change);
58366 +#endif
58367 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58368 new file mode 100644
58369 index 0000000..abfa971
58370 --- /dev/null
58371 +++ b/grsecurity/grsec_exec.c
58372 @@ -0,0 +1,174 @@
58373 +#include <linux/kernel.h>
58374 +#include <linux/sched.h>
58375 +#include <linux/file.h>
58376 +#include <linux/binfmts.h>
58377 +#include <linux/fs.h>
58378 +#include <linux/types.h>
58379 +#include <linux/grdefs.h>
58380 +#include <linux/grsecurity.h>
58381 +#include <linux/grinternal.h>
58382 +#include <linux/capability.h>
58383 +#include <linux/module.h>
58384 +
58385 +#include <asm/uaccess.h>
58386 +
58387 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58388 +static char gr_exec_arg_buf[132];
58389 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58390 +#endif
58391 +
58392 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58393 +
58394 +void
58395 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58396 +{
58397 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58398 + char *grarg = gr_exec_arg_buf;
58399 + unsigned int i, x, execlen = 0;
58400 + char c;
58401 +
58402 + if (!((grsec_enable_execlog && grsec_enable_group &&
58403 + in_group_p(grsec_audit_gid))
58404 + || (grsec_enable_execlog && !grsec_enable_group)))
58405 + return;
58406 +
58407 + mutex_lock(&gr_exec_arg_mutex);
58408 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58409 +
58410 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58411 + const char __user *p;
58412 + unsigned int len;
58413 +
58414 + p = get_user_arg_ptr(argv, i);
58415 + if (IS_ERR(p))
58416 + goto log;
58417 +
58418 + len = strnlen_user(p, 128 - execlen);
58419 + if (len > 128 - execlen)
58420 + len = 128 - execlen;
58421 + else if (len > 0)
58422 + len--;
58423 + if (copy_from_user(grarg + execlen, p, len))
58424 + goto log;
58425 +
58426 + /* rewrite unprintable characters */
58427 + for (x = 0; x < len; x++) {
58428 + c = *(grarg + execlen + x);
58429 + if (c < 32 || c > 126)
58430 + *(grarg + execlen + x) = ' ';
58431 + }
58432 +
58433 + execlen += len;
58434 + *(grarg + execlen) = ' ';
58435 + *(grarg + execlen + 1) = '\0';
58436 + execlen++;
58437 + }
58438 +
58439 + log:
58440 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58441 + bprm->file->f_path.mnt, grarg);
58442 + mutex_unlock(&gr_exec_arg_mutex);
58443 +#endif
58444 + return;
58445 +}
58446 +
58447 +#ifdef CONFIG_GRKERNSEC
58448 +extern int gr_acl_is_capable(const int cap);
58449 +extern int gr_acl_is_capable_nolog(const int cap);
58450 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58451 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58452 +extern int gr_chroot_is_capable(const int cap);
58453 +extern int gr_chroot_is_capable_nolog(const int cap);
58454 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58455 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58456 +#endif
58457 +
58458 +const char *captab_log[] = {
58459 + "CAP_CHOWN",
58460 + "CAP_DAC_OVERRIDE",
58461 + "CAP_DAC_READ_SEARCH",
58462 + "CAP_FOWNER",
58463 + "CAP_FSETID",
58464 + "CAP_KILL",
58465 + "CAP_SETGID",
58466 + "CAP_SETUID",
58467 + "CAP_SETPCAP",
58468 + "CAP_LINUX_IMMUTABLE",
58469 + "CAP_NET_BIND_SERVICE",
58470 + "CAP_NET_BROADCAST",
58471 + "CAP_NET_ADMIN",
58472 + "CAP_NET_RAW",
58473 + "CAP_IPC_LOCK",
58474 + "CAP_IPC_OWNER",
58475 + "CAP_SYS_MODULE",
58476 + "CAP_SYS_RAWIO",
58477 + "CAP_SYS_CHROOT",
58478 + "CAP_SYS_PTRACE",
58479 + "CAP_SYS_PACCT",
58480 + "CAP_SYS_ADMIN",
58481 + "CAP_SYS_BOOT",
58482 + "CAP_SYS_NICE",
58483 + "CAP_SYS_RESOURCE",
58484 + "CAP_SYS_TIME",
58485 + "CAP_SYS_TTY_CONFIG",
58486 + "CAP_MKNOD",
58487 + "CAP_LEASE",
58488 + "CAP_AUDIT_WRITE",
58489 + "CAP_AUDIT_CONTROL",
58490 + "CAP_SETFCAP",
58491 + "CAP_MAC_OVERRIDE",
58492 + "CAP_MAC_ADMIN",
58493 + "CAP_SYSLOG",
58494 + "CAP_WAKE_ALARM"
58495 +};
58496 +
58497 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58498 +
58499 +int gr_is_capable(const int cap)
58500 +{
58501 +#ifdef CONFIG_GRKERNSEC
58502 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58503 + return 1;
58504 + return 0;
58505 +#else
58506 + return 1;
58507 +#endif
58508 +}
58509 +
58510 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58511 +{
58512 +#ifdef CONFIG_GRKERNSEC
58513 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58514 + return 1;
58515 + return 0;
58516 +#else
58517 + return 1;
58518 +#endif
58519 +}
58520 +
58521 +int gr_is_capable_nolog(const int cap)
58522 +{
58523 +#ifdef CONFIG_GRKERNSEC
58524 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58525 + return 1;
58526 + return 0;
58527 +#else
58528 + return 1;
58529 +#endif
58530 +}
58531 +
58532 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58533 +{
58534 +#ifdef CONFIG_GRKERNSEC
58535 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58536 + return 1;
58537 + return 0;
58538 +#else
58539 + return 1;
58540 +#endif
58541 +}
58542 +
58543 +EXPORT_SYMBOL(gr_is_capable);
58544 +EXPORT_SYMBOL(gr_is_capable_nolog);
58545 +EXPORT_SYMBOL(gr_task_is_capable);
58546 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58547 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58548 new file mode 100644
58549 index 0000000..d3ee748
58550 --- /dev/null
58551 +++ b/grsecurity/grsec_fifo.c
58552 @@ -0,0 +1,24 @@
58553 +#include <linux/kernel.h>
58554 +#include <linux/sched.h>
58555 +#include <linux/fs.h>
58556 +#include <linux/file.h>
58557 +#include <linux/grinternal.h>
58558 +
58559 +int
58560 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58561 + const struct dentry *dir, const int flag, const int acc_mode)
58562 +{
58563 +#ifdef CONFIG_GRKERNSEC_FIFO
58564 + const struct cred *cred = current_cred();
58565 +
58566 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58567 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58568 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58569 + (cred->fsuid != dentry->d_inode->i_uid)) {
58570 + if (!inode_permission(dentry->d_inode, acc_mode))
58571 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58572 + return -EACCES;
58573 + }
58574 +#endif
58575 + return 0;
58576 +}
58577 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58578 new file mode 100644
58579 index 0000000..8ca18bf
58580 --- /dev/null
58581 +++ b/grsecurity/grsec_fork.c
58582 @@ -0,0 +1,23 @@
58583 +#include <linux/kernel.h>
58584 +#include <linux/sched.h>
58585 +#include <linux/grsecurity.h>
58586 +#include <linux/grinternal.h>
58587 +#include <linux/errno.h>
58588 +
58589 +void
58590 +gr_log_forkfail(const int retval)
58591 +{
58592 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58593 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58594 + switch (retval) {
58595 + case -EAGAIN:
58596 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58597 + break;
58598 + case -ENOMEM:
58599 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58600 + break;
58601 + }
58602 + }
58603 +#endif
58604 + return;
58605 +}
58606 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58607 new file mode 100644
58608 index 0000000..01ddde4
58609 --- /dev/null
58610 +++ b/grsecurity/grsec_init.c
58611 @@ -0,0 +1,277 @@
58612 +#include <linux/kernel.h>
58613 +#include <linux/sched.h>
58614 +#include <linux/mm.h>
58615 +#include <linux/gracl.h>
58616 +#include <linux/slab.h>
58617 +#include <linux/vmalloc.h>
58618 +#include <linux/percpu.h>
58619 +#include <linux/module.h>
58620 +
58621 +int grsec_enable_ptrace_readexec;
58622 +int grsec_enable_setxid;
58623 +int grsec_enable_brute;
58624 +int grsec_enable_link;
58625 +int grsec_enable_dmesg;
58626 +int grsec_enable_harden_ptrace;
58627 +int grsec_enable_fifo;
58628 +int grsec_enable_execlog;
58629 +int grsec_enable_signal;
58630 +int grsec_enable_forkfail;
58631 +int grsec_enable_audit_ptrace;
58632 +int grsec_enable_time;
58633 +int grsec_enable_audit_textrel;
58634 +int grsec_enable_group;
58635 +int grsec_audit_gid;
58636 +int grsec_enable_chdir;
58637 +int grsec_enable_mount;
58638 +int grsec_enable_rofs;
58639 +int grsec_enable_chroot_findtask;
58640 +int grsec_enable_chroot_mount;
58641 +int grsec_enable_chroot_shmat;
58642 +int grsec_enable_chroot_fchdir;
58643 +int grsec_enable_chroot_double;
58644 +int grsec_enable_chroot_pivot;
58645 +int grsec_enable_chroot_chdir;
58646 +int grsec_enable_chroot_chmod;
58647 +int grsec_enable_chroot_mknod;
58648 +int grsec_enable_chroot_nice;
58649 +int grsec_enable_chroot_execlog;
58650 +int grsec_enable_chroot_caps;
58651 +int grsec_enable_chroot_sysctl;
58652 +int grsec_enable_chroot_unix;
58653 +int grsec_enable_tpe;
58654 +int grsec_tpe_gid;
58655 +int grsec_enable_blackhole;
58656 +#ifdef CONFIG_IPV6_MODULE
58657 +EXPORT_SYMBOL(grsec_enable_blackhole);
58658 +#endif
58659 +int grsec_lastack_retries;
58660 +int grsec_enable_tpe_all;
58661 +int grsec_enable_tpe_invert;
58662 +int grsec_enable_socket_all;
58663 +int grsec_socket_all_gid;
58664 +int grsec_enable_socket_client;
58665 +int grsec_socket_client_gid;
58666 +int grsec_enable_socket_server;
58667 +int grsec_socket_server_gid;
58668 +int grsec_resource_logging;
58669 +int grsec_disable_privio;
58670 +int grsec_enable_log_rwxmaps;
58671 +int grsec_lock;
58672 +
58673 +DEFINE_SPINLOCK(grsec_alert_lock);
58674 +unsigned long grsec_alert_wtime = 0;
58675 +unsigned long grsec_alert_fyet = 0;
58676 +
58677 +DEFINE_SPINLOCK(grsec_audit_lock);
58678 +
58679 +DEFINE_RWLOCK(grsec_exec_file_lock);
58680 +
58681 +char *gr_shared_page[4];
58682 +
58683 +char *gr_alert_log_fmt;
58684 +char *gr_audit_log_fmt;
58685 +char *gr_alert_log_buf;
58686 +char *gr_audit_log_buf;
58687 +
58688 +extern struct gr_arg *gr_usermode;
58689 +extern unsigned char *gr_system_salt;
58690 +extern unsigned char *gr_system_sum;
58691 +
58692 +void __init
58693 +grsecurity_init(void)
58694 +{
58695 + int j;
58696 + /* create the per-cpu shared pages */
58697 +
58698 +#ifdef CONFIG_X86
58699 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58700 +#endif
58701 +
58702 + for (j = 0; j < 4; j++) {
58703 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58704 + if (gr_shared_page[j] == NULL) {
58705 + panic("Unable to allocate grsecurity shared page");
58706 + return;
58707 + }
58708 + }
58709 +
58710 + /* allocate log buffers */
58711 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58712 + if (!gr_alert_log_fmt) {
58713 + panic("Unable to allocate grsecurity alert log format buffer");
58714 + return;
58715 + }
58716 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58717 + if (!gr_audit_log_fmt) {
58718 + panic("Unable to allocate grsecurity audit log format buffer");
58719 + return;
58720 + }
58721 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58722 + if (!gr_alert_log_buf) {
58723 + panic("Unable to allocate grsecurity alert log buffer");
58724 + return;
58725 + }
58726 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58727 + if (!gr_audit_log_buf) {
58728 + panic("Unable to allocate grsecurity audit log buffer");
58729 + return;
58730 + }
58731 +
58732 + /* allocate memory for authentication structure */
58733 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58734 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58735 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58736 +
58737 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58738 + panic("Unable to allocate grsecurity authentication structure");
58739 + return;
58740 + }
58741 +
58742 +
58743 +#ifdef CONFIG_GRKERNSEC_IO
58744 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58745 + grsec_disable_privio = 1;
58746 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58747 + grsec_disable_privio = 1;
58748 +#else
58749 + grsec_disable_privio = 0;
58750 +#endif
58751 +#endif
58752 +
58753 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58754 + /* for backward compatibility, tpe_invert always defaults to on if
58755 + enabled in the kernel
58756 + */
58757 + grsec_enable_tpe_invert = 1;
58758 +#endif
58759 +
58760 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58761 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58762 + grsec_lock = 1;
58763 +#endif
58764 +
58765 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58766 + grsec_enable_audit_textrel = 1;
58767 +#endif
58768 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58769 + grsec_enable_log_rwxmaps = 1;
58770 +#endif
58771 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58772 + grsec_enable_group = 1;
58773 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58774 +#endif
58775 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58776 + grsec_enable_ptrace_readexec = 1;
58777 +#endif
58778 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58779 + grsec_enable_chdir = 1;
58780 +#endif
58781 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58782 + grsec_enable_harden_ptrace = 1;
58783 +#endif
58784 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58785 + grsec_enable_mount = 1;
58786 +#endif
58787 +#ifdef CONFIG_GRKERNSEC_LINK
58788 + grsec_enable_link = 1;
58789 +#endif
58790 +#ifdef CONFIG_GRKERNSEC_BRUTE
58791 + grsec_enable_brute = 1;
58792 +#endif
58793 +#ifdef CONFIG_GRKERNSEC_DMESG
58794 + grsec_enable_dmesg = 1;
58795 +#endif
58796 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58797 + grsec_enable_blackhole = 1;
58798 + grsec_lastack_retries = 4;
58799 +#endif
58800 +#ifdef CONFIG_GRKERNSEC_FIFO
58801 + grsec_enable_fifo = 1;
58802 +#endif
58803 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58804 + grsec_enable_execlog = 1;
58805 +#endif
58806 +#ifdef CONFIG_GRKERNSEC_SETXID
58807 + grsec_enable_setxid = 1;
58808 +#endif
58809 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58810 + grsec_enable_signal = 1;
58811 +#endif
58812 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58813 + grsec_enable_forkfail = 1;
58814 +#endif
58815 +#ifdef CONFIG_GRKERNSEC_TIME
58816 + grsec_enable_time = 1;
58817 +#endif
58818 +#ifdef CONFIG_GRKERNSEC_RESLOG
58819 + grsec_resource_logging = 1;
58820 +#endif
58821 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58822 + grsec_enable_chroot_findtask = 1;
58823 +#endif
58824 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58825 + grsec_enable_chroot_unix = 1;
58826 +#endif
58827 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58828 + grsec_enable_chroot_mount = 1;
58829 +#endif
58830 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58831 + grsec_enable_chroot_fchdir = 1;
58832 +#endif
58833 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58834 + grsec_enable_chroot_shmat = 1;
58835 +#endif
58836 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58837 + grsec_enable_audit_ptrace = 1;
58838 +#endif
58839 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58840 + grsec_enable_chroot_double = 1;
58841 +#endif
58842 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58843 + grsec_enable_chroot_pivot = 1;
58844 +#endif
58845 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58846 + grsec_enable_chroot_chdir = 1;
58847 +#endif
58848 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58849 + grsec_enable_chroot_chmod = 1;
58850 +#endif
58851 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58852 + grsec_enable_chroot_mknod = 1;
58853 +#endif
58854 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58855 + grsec_enable_chroot_nice = 1;
58856 +#endif
58857 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58858 + grsec_enable_chroot_execlog = 1;
58859 +#endif
58860 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58861 + grsec_enable_chroot_caps = 1;
58862 +#endif
58863 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58864 + grsec_enable_chroot_sysctl = 1;
58865 +#endif
58866 +#ifdef CONFIG_GRKERNSEC_TPE
58867 + grsec_enable_tpe = 1;
58868 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58869 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58870 + grsec_enable_tpe_all = 1;
58871 +#endif
58872 +#endif
58873 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58874 + grsec_enable_socket_all = 1;
58875 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58876 +#endif
58877 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58878 + grsec_enable_socket_client = 1;
58879 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58880 +#endif
58881 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58882 + grsec_enable_socket_server = 1;
58883 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58884 +#endif
58885 +#endif
58886 +
58887 + return;
58888 +}
58889 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58890 new file mode 100644
58891 index 0000000..3efe141
58892 --- /dev/null
58893 +++ b/grsecurity/grsec_link.c
58894 @@ -0,0 +1,43 @@
58895 +#include <linux/kernel.h>
58896 +#include <linux/sched.h>
58897 +#include <linux/fs.h>
58898 +#include <linux/file.h>
58899 +#include <linux/grinternal.h>
58900 +
58901 +int
58902 +gr_handle_follow_link(const struct inode *parent,
58903 + const struct inode *inode,
58904 + const struct dentry *dentry, const struct vfsmount *mnt)
58905 +{
58906 +#ifdef CONFIG_GRKERNSEC_LINK
58907 + const struct cred *cred = current_cred();
58908 +
58909 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58910 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
58911 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
58912 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58913 + return -EACCES;
58914 + }
58915 +#endif
58916 + return 0;
58917 +}
58918 +
58919 +int
58920 +gr_handle_hardlink(const struct dentry *dentry,
58921 + const struct vfsmount *mnt,
58922 + struct inode *inode, const int mode, const char *to)
58923 +{
58924 +#ifdef CONFIG_GRKERNSEC_LINK
58925 + const struct cred *cred = current_cred();
58926 +
58927 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
58928 + (!S_ISREG(mode) || (mode & S_ISUID) ||
58929 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
58930 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58931 + !capable(CAP_FOWNER) && cred->uid) {
58932 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58933 + return -EPERM;
58934 + }
58935 +#endif
58936 + return 0;
58937 +}
58938 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58939 new file mode 100644
58940 index 0000000..a45d2e9
58941 --- /dev/null
58942 +++ b/grsecurity/grsec_log.c
58943 @@ -0,0 +1,322 @@
58944 +#include <linux/kernel.h>
58945 +#include <linux/sched.h>
58946 +#include <linux/file.h>
58947 +#include <linux/tty.h>
58948 +#include <linux/fs.h>
58949 +#include <linux/grinternal.h>
58950 +
58951 +#ifdef CONFIG_TREE_PREEMPT_RCU
58952 +#define DISABLE_PREEMPT() preempt_disable()
58953 +#define ENABLE_PREEMPT() preempt_enable()
58954 +#else
58955 +#define DISABLE_PREEMPT()
58956 +#define ENABLE_PREEMPT()
58957 +#endif
58958 +
58959 +#define BEGIN_LOCKS(x) \
58960 + DISABLE_PREEMPT(); \
58961 + rcu_read_lock(); \
58962 + read_lock(&tasklist_lock); \
58963 + read_lock(&grsec_exec_file_lock); \
58964 + if (x != GR_DO_AUDIT) \
58965 + spin_lock(&grsec_alert_lock); \
58966 + else \
58967 + spin_lock(&grsec_audit_lock)
58968 +
58969 +#define END_LOCKS(x) \
58970 + if (x != GR_DO_AUDIT) \
58971 + spin_unlock(&grsec_alert_lock); \
58972 + else \
58973 + spin_unlock(&grsec_audit_lock); \
58974 + read_unlock(&grsec_exec_file_lock); \
58975 + read_unlock(&tasklist_lock); \
58976 + rcu_read_unlock(); \
58977 + ENABLE_PREEMPT(); \
58978 + if (x == GR_DONT_AUDIT) \
58979 + gr_handle_alertkill(current)
58980 +
58981 +enum {
58982 + FLOODING,
58983 + NO_FLOODING
58984 +};
58985 +
58986 +extern char *gr_alert_log_fmt;
58987 +extern char *gr_audit_log_fmt;
58988 +extern char *gr_alert_log_buf;
58989 +extern char *gr_audit_log_buf;
58990 +
58991 +static int gr_log_start(int audit)
58992 +{
58993 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58994 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58995 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58996 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58997 + unsigned long curr_secs = get_seconds();
58998 +
58999 + if (audit == GR_DO_AUDIT)
59000 + goto set_fmt;
59001 +
59002 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
59003 + grsec_alert_wtime = curr_secs;
59004 + grsec_alert_fyet = 0;
59005 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
59006 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
59007 + grsec_alert_fyet++;
59008 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
59009 + grsec_alert_wtime = curr_secs;
59010 + grsec_alert_fyet++;
59011 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
59012 + return FLOODING;
59013 + }
59014 + else return FLOODING;
59015 +
59016 +set_fmt:
59017 +#endif
59018 + memset(buf, 0, PAGE_SIZE);
59019 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
59020 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
59021 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59022 + } else if (current->signal->curr_ip) {
59023 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
59024 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
59025 + } else if (gr_acl_is_enabled()) {
59026 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
59027 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
59028 + } else {
59029 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
59030 + strcpy(buf, fmt);
59031 + }
59032 +
59033 + return NO_FLOODING;
59034 +}
59035 +
59036 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59037 + __attribute__ ((format (printf, 2, 0)));
59038 +
59039 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59040 +{
59041 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59042 + unsigned int len = strlen(buf);
59043 +
59044 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59045 +
59046 + return;
59047 +}
59048 +
59049 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59050 + __attribute__ ((format (printf, 2, 3)));
59051 +
59052 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59053 +{
59054 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59055 + unsigned int len = strlen(buf);
59056 + va_list ap;
59057 +
59058 + va_start(ap, msg);
59059 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59060 + va_end(ap);
59061 +
59062 + return;
59063 +}
59064 +
59065 +static void gr_log_end(int audit, int append_default)
59066 +{
59067 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59068 +
59069 + if (append_default) {
59070 + unsigned int len = strlen(buf);
59071 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59072 + }
59073 +
59074 + printk("%s\n", buf);
59075 +
59076 + return;
59077 +}
59078 +
59079 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59080 +{
59081 + int logtype;
59082 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59083 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59084 + void *voidptr = NULL;
59085 + int num1 = 0, num2 = 0;
59086 + unsigned long ulong1 = 0, ulong2 = 0;
59087 + struct dentry *dentry = NULL;
59088 + struct vfsmount *mnt = NULL;
59089 + struct file *file = NULL;
59090 + struct task_struct *task = NULL;
59091 + const struct cred *cred, *pcred;
59092 + va_list ap;
59093 +
59094 + BEGIN_LOCKS(audit);
59095 + logtype = gr_log_start(audit);
59096 + if (logtype == FLOODING) {
59097 + END_LOCKS(audit);
59098 + return;
59099 + }
59100 + va_start(ap, argtypes);
59101 + switch (argtypes) {
59102 + case GR_TTYSNIFF:
59103 + task = va_arg(ap, struct task_struct *);
59104 + 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);
59105 + break;
59106 + case GR_SYSCTL_HIDDEN:
59107 + str1 = va_arg(ap, char *);
59108 + gr_log_middle_varargs(audit, msg, result, str1);
59109 + break;
59110 + case GR_RBAC:
59111 + dentry = va_arg(ap, struct dentry *);
59112 + mnt = va_arg(ap, struct vfsmount *);
59113 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59114 + break;
59115 + case GR_RBAC_STR:
59116 + dentry = va_arg(ap, struct dentry *);
59117 + mnt = va_arg(ap, struct vfsmount *);
59118 + str1 = va_arg(ap, char *);
59119 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59120 + break;
59121 + case GR_STR_RBAC:
59122 + str1 = va_arg(ap, char *);
59123 + dentry = va_arg(ap, struct dentry *);
59124 + mnt = va_arg(ap, struct vfsmount *);
59125 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59126 + break;
59127 + case GR_RBAC_MODE2:
59128 + dentry = va_arg(ap, struct dentry *);
59129 + mnt = va_arg(ap, struct vfsmount *);
59130 + str1 = va_arg(ap, char *);
59131 + str2 = va_arg(ap, char *);
59132 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59133 + break;
59134 + case GR_RBAC_MODE3:
59135 + dentry = va_arg(ap, struct dentry *);
59136 + mnt = va_arg(ap, struct vfsmount *);
59137 + str1 = va_arg(ap, char *);
59138 + str2 = va_arg(ap, char *);
59139 + str3 = va_arg(ap, char *);
59140 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59141 + break;
59142 + case GR_FILENAME:
59143 + dentry = va_arg(ap, struct dentry *);
59144 + mnt = va_arg(ap, struct vfsmount *);
59145 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59146 + break;
59147 + case GR_STR_FILENAME:
59148 + str1 = va_arg(ap, char *);
59149 + dentry = va_arg(ap, struct dentry *);
59150 + mnt = va_arg(ap, struct vfsmount *);
59151 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59152 + break;
59153 + case GR_FILENAME_STR:
59154 + dentry = va_arg(ap, struct dentry *);
59155 + mnt = va_arg(ap, struct vfsmount *);
59156 + str1 = va_arg(ap, char *);
59157 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59158 + break;
59159 + case GR_FILENAME_TWO_INT:
59160 + dentry = va_arg(ap, struct dentry *);
59161 + mnt = va_arg(ap, struct vfsmount *);
59162 + num1 = va_arg(ap, int);
59163 + num2 = va_arg(ap, int);
59164 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59165 + break;
59166 + case GR_FILENAME_TWO_INT_STR:
59167 + dentry = va_arg(ap, struct dentry *);
59168 + mnt = va_arg(ap, struct vfsmount *);
59169 + num1 = va_arg(ap, int);
59170 + num2 = va_arg(ap, int);
59171 + str1 = va_arg(ap, char *);
59172 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59173 + break;
59174 + case GR_TEXTREL:
59175 + file = va_arg(ap, struct file *);
59176 + ulong1 = va_arg(ap, unsigned long);
59177 + ulong2 = va_arg(ap, unsigned long);
59178 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59179 + break;
59180 + case GR_PTRACE:
59181 + task = va_arg(ap, struct task_struct *);
59182 + 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);
59183 + break;
59184 + case GR_RESOURCE:
59185 + task = va_arg(ap, struct task_struct *);
59186 + cred = __task_cred(task);
59187 + pcred = __task_cred(task->real_parent);
59188 + ulong1 = va_arg(ap, unsigned long);
59189 + str1 = va_arg(ap, char *);
59190 + ulong2 = va_arg(ap, unsigned long);
59191 + 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);
59192 + break;
59193 + case GR_CAP:
59194 + task = va_arg(ap, struct task_struct *);
59195 + cred = __task_cred(task);
59196 + pcred = __task_cred(task->real_parent);
59197 + str1 = va_arg(ap, char *);
59198 + 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);
59199 + break;
59200 + case GR_SIG:
59201 + str1 = va_arg(ap, char *);
59202 + voidptr = va_arg(ap, void *);
59203 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59204 + break;
59205 + case GR_SIG2:
59206 + task = va_arg(ap, struct task_struct *);
59207 + cred = __task_cred(task);
59208 + pcred = __task_cred(task->real_parent);
59209 + num1 = va_arg(ap, int);
59210 + 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);
59211 + break;
59212 + case GR_CRASH1:
59213 + task = va_arg(ap, struct task_struct *);
59214 + cred = __task_cred(task);
59215 + pcred = __task_cred(task->real_parent);
59216 + ulong1 = va_arg(ap, unsigned long);
59217 + 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);
59218 + break;
59219 + case GR_CRASH2:
59220 + task = va_arg(ap, struct task_struct *);
59221 + cred = __task_cred(task);
59222 + pcred = __task_cred(task->real_parent);
59223 + ulong1 = va_arg(ap, unsigned long);
59224 + 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);
59225 + break;
59226 + case GR_RWXMAP:
59227 + file = va_arg(ap, struct file *);
59228 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59229 + break;
59230 + case GR_PSACCT:
59231 + {
59232 + unsigned int wday, cday;
59233 + __u8 whr, chr;
59234 + __u8 wmin, cmin;
59235 + __u8 wsec, csec;
59236 + char cur_tty[64] = { 0 };
59237 + char parent_tty[64] = { 0 };
59238 +
59239 + task = va_arg(ap, struct task_struct *);
59240 + wday = va_arg(ap, unsigned int);
59241 + cday = va_arg(ap, unsigned int);
59242 + whr = va_arg(ap, int);
59243 + chr = va_arg(ap, int);
59244 + wmin = va_arg(ap, int);
59245 + cmin = va_arg(ap, int);
59246 + wsec = va_arg(ap, int);
59247 + csec = va_arg(ap, int);
59248 + ulong1 = va_arg(ap, unsigned long);
59249 + cred = __task_cred(task);
59250 + pcred = __task_cred(task->real_parent);
59251 +
59252 + 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);
59253 + }
59254 + break;
59255 + default:
59256 + gr_log_middle(audit, msg, ap);
59257 + }
59258 + va_end(ap);
59259 + // these don't need DEFAULTSECARGS printed on the end
59260 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59261 + gr_log_end(audit, 0);
59262 + else
59263 + gr_log_end(audit, 1);
59264 + END_LOCKS(audit);
59265 +}
59266 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59267 new file mode 100644
59268 index 0000000..f536303
59269 --- /dev/null
59270 +++ b/grsecurity/grsec_mem.c
59271 @@ -0,0 +1,40 @@
59272 +#include <linux/kernel.h>
59273 +#include <linux/sched.h>
59274 +#include <linux/mm.h>
59275 +#include <linux/mman.h>
59276 +#include <linux/grinternal.h>
59277 +
59278 +void
59279 +gr_handle_ioperm(void)
59280 +{
59281 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59282 + return;
59283 +}
59284 +
59285 +void
59286 +gr_handle_iopl(void)
59287 +{
59288 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59289 + return;
59290 +}
59291 +
59292 +void
59293 +gr_handle_mem_readwrite(u64 from, u64 to)
59294 +{
59295 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59296 + return;
59297 +}
59298 +
59299 +void
59300 +gr_handle_vm86(void)
59301 +{
59302 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59303 + return;
59304 +}
59305 +
59306 +void
59307 +gr_log_badprocpid(const char *entry)
59308 +{
59309 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59310 + return;
59311 +}
59312 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59313 new file mode 100644
59314 index 0000000..2131422
59315 --- /dev/null
59316 +++ b/grsecurity/grsec_mount.c
59317 @@ -0,0 +1,62 @@
59318 +#include <linux/kernel.h>
59319 +#include <linux/sched.h>
59320 +#include <linux/mount.h>
59321 +#include <linux/grsecurity.h>
59322 +#include <linux/grinternal.h>
59323 +
59324 +void
59325 +gr_log_remount(const char *devname, const int retval)
59326 +{
59327 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59328 + if (grsec_enable_mount && (retval >= 0))
59329 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59330 +#endif
59331 + return;
59332 +}
59333 +
59334 +void
59335 +gr_log_unmount(const char *devname, const int retval)
59336 +{
59337 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59338 + if (grsec_enable_mount && (retval >= 0))
59339 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59340 +#endif
59341 + return;
59342 +}
59343 +
59344 +void
59345 +gr_log_mount(const char *from, const char *to, const int retval)
59346 +{
59347 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59348 + if (grsec_enable_mount && (retval >= 0))
59349 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59350 +#endif
59351 + return;
59352 +}
59353 +
59354 +int
59355 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59356 +{
59357 +#ifdef CONFIG_GRKERNSEC_ROFS
59358 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59359 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59360 + return -EPERM;
59361 + } else
59362 + return 0;
59363 +#endif
59364 + return 0;
59365 +}
59366 +
59367 +int
59368 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59369 +{
59370 +#ifdef CONFIG_GRKERNSEC_ROFS
59371 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59372 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59373 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59374 + return -EPERM;
59375 + } else
59376 + return 0;
59377 +#endif
59378 + return 0;
59379 +}
59380 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59381 new file mode 100644
59382 index 0000000..a3b12a0
59383 --- /dev/null
59384 +++ b/grsecurity/grsec_pax.c
59385 @@ -0,0 +1,36 @@
59386 +#include <linux/kernel.h>
59387 +#include <linux/sched.h>
59388 +#include <linux/mm.h>
59389 +#include <linux/file.h>
59390 +#include <linux/grinternal.h>
59391 +#include <linux/grsecurity.h>
59392 +
59393 +void
59394 +gr_log_textrel(struct vm_area_struct * vma)
59395 +{
59396 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59397 + if (grsec_enable_audit_textrel)
59398 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59399 +#endif
59400 + return;
59401 +}
59402 +
59403 +void
59404 +gr_log_rwxmmap(struct file *file)
59405 +{
59406 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59407 + if (grsec_enable_log_rwxmaps)
59408 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59409 +#endif
59410 + return;
59411 +}
59412 +
59413 +void
59414 +gr_log_rwxmprotect(struct file *file)
59415 +{
59416 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59417 + if (grsec_enable_log_rwxmaps)
59418 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59419 +#endif
59420 + return;
59421 +}
59422 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59423 new file mode 100644
59424 index 0000000..f7f29aa
59425 --- /dev/null
59426 +++ b/grsecurity/grsec_ptrace.c
59427 @@ -0,0 +1,30 @@
59428 +#include <linux/kernel.h>
59429 +#include <linux/sched.h>
59430 +#include <linux/grinternal.h>
59431 +#include <linux/security.h>
59432 +
59433 +void
59434 +gr_audit_ptrace(struct task_struct *task)
59435 +{
59436 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59437 + if (grsec_enable_audit_ptrace)
59438 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59439 +#endif
59440 + return;
59441 +}
59442 +
59443 +int
59444 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59445 +{
59446 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59447 + const struct dentry *dentry = file->f_path.dentry;
59448 + const struct vfsmount *mnt = file->f_path.mnt;
59449 +
59450 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59451 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59452 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59453 + return -EACCES;
59454 + }
59455 +#endif
59456 + return 0;
59457 +}
59458 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59459 new file mode 100644
59460 index 0000000..7a5b2de
59461 --- /dev/null
59462 +++ b/grsecurity/grsec_sig.c
59463 @@ -0,0 +1,207 @@
59464 +#include <linux/kernel.h>
59465 +#include <linux/sched.h>
59466 +#include <linux/delay.h>
59467 +#include <linux/grsecurity.h>
59468 +#include <linux/grinternal.h>
59469 +#include <linux/hardirq.h>
59470 +
59471 +char *signames[] = {
59472 + [SIGSEGV] = "Segmentation fault",
59473 + [SIGILL] = "Illegal instruction",
59474 + [SIGABRT] = "Abort",
59475 + [SIGBUS] = "Invalid alignment/Bus error"
59476 +};
59477 +
59478 +void
59479 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59480 +{
59481 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59482 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59483 + (sig == SIGABRT) || (sig == SIGBUS))) {
59484 + if (t->pid == current->pid) {
59485 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59486 + } else {
59487 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59488 + }
59489 + }
59490 +#endif
59491 + return;
59492 +}
59493 +
59494 +int
59495 +gr_handle_signal(const struct task_struct *p, const int sig)
59496 +{
59497 +#ifdef CONFIG_GRKERNSEC
59498 + /* ignore the 0 signal for protected task checks */
59499 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59500 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59501 + return -EPERM;
59502 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59503 + return -EPERM;
59504 + }
59505 +#endif
59506 + return 0;
59507 +}
59508 +
59509 +#ifdef CONFIG_GRKERNSEC
59510 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59511 +
59512 +int gr_fake_force_sig(int sig, struct task_struct *t)
59513 +{
59514 + unsigned long int flags;
59515 + int ret, blocked, ignored;
59516 + struct k_sigaction *action;
59517 +
59518 + spin_lock_irqsave(&t->sighand->siglock, flags);
59519 + action = &t->sighand->action[sig-1];
59520 + ignored = action->sa.sa_handler == SIG_IGN;
59521 + blocked = sigismember(&t->blocked, sig);
59522 + if (blocked || ignored) {
59523 + action->sa.sa_handler = SIG_DFL;
59524 + if (blocked) {
59525 + sigdelset(&t->blocked, sig);
59526 + recalc_sigpending_and_wake(t);
59527 + }
59528 + }
59529 + if (action->sa.sa_handler == SIG_DFL)
59530 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59531 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59532 +
59533 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59534 +
59535 + return ret;
59536 +}
59537 +#endif
59538 +
59539 +#ifdef CONFIG_GRKERNSEC_BRUTE
59540 +#define GR_USER_BAN_TIME (15 * 60)
59541 +
59542 +static int __get_dumpable(unsigned long mm_flags)
59543 +{
59544 + int ret;
59545 +
59546 + ret = mm_flags & MMF_DUMPABLE_MASK;
59547 + return (ret >= 2) ? 2 : ret;
59548 +}
59549 +#endif
59550 +
59551 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59552 +{
59553 +#ifdef CONFIG_GRKERNSEC_BRUTE
59554 + uid_t uid = 0;
59555 +
59556 + if (!grsec_enable_brute)
59557 + return;
59558 +
59559 + rcu_read_lock();
59560 + read_lock(&tasklist_lock);
59561 + read_lock(&grsec_exec_file_lock);
59562 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59563 + p->real_parent->brute = 1;
59564 + else {
59565 + const struct cred *cred = __task_cred(p), *cred2;
59566 + struct task_struct *tsk, *tsk2;
59567 +
59568 + if (!__get_dumpable(mm_flags) && cred->uid) {
59569 + struct user_struct *user;
59570 +
59571 + uid = cred->uid;
59572 +
59573 + /* this is put upon execution past expiration */
59574 + user = find_user(uid);
59575 + if (user == NULL)
59576 + goto unlock;
59577 + user->banned = 1;
59578 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59579 + if (user->ban_expires == ~0UL)
59580 + user->ban_expires--;
59581 +
59582 + do_each_thread(tsk2, tsk) {
59583 + cred2 = __task_cred(tsk);
59584 + if (tsk != p && cred2->uid == uid)
59585 + gr_fake_force_sig(SIGKILL, tsk);
59586 + } while_each_thread(tsk2, tsk);
59587 + }
59588 + }
59589 +unlock:
59590 + read_unlock(&grsec_exec_file_lock);
59591 + read_unlock(&tasklist_lock);
59592 + rcu_read_unlock();
59593 +
59594 + if (uid)
59595 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
59596 +
59597 +#endif
59598 + return;
59599 +}
59600 +
59601 +void gr_handle_brute_check(void)
59602 +{
59603 +#ifdef CONFIG_GRKERNSEC_BRUTE
59604 + if (current->brute)
59605 + msleep(30 * 1000);
59606 +#endif
59607 + return;
59608 +}
59609 +
59610 +void gr_handle_kernel_exploit(void)
59611 +{
59612 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59613 + const struct cred *cred;
59614 + struct task_struct *tsk, *tsk2;
59615 + struct user_struct *user;
59616 + uid_t uid;
59617 +
59618 + if (in_irq() || in_serving_softirq() || in_nmi())
59619 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59620 +
59621 + uid = current_uid();
59622 +
59623 + if (uid == 0)
59624 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59625 + else {
59626 + /* kill all the processes of this user, hold a reference
59627 + to their creds struct, and prevent them from creating
59628 + another process until system reset
59629 + */
59630 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
59631 + /* we intentionally leak this ref */
59632 + user = get_uid(current->cred->user);
59633 + if (user) {
59634 + user->banned = 1;
59635 + user->ban_expires = ~0UL;
59636 + }
59637 +
59638 + read_lock(&tasklist_lock);
59639 + do_each_thread(tsk2, tsk) {
59640 + cred = __task_cred(tsk);
59641 + if (cred->uid == uid)
59642 + gr_fake_force_sig(SIGKILL, tsk);
59643 + } while_each_thread(tsk2, tsk);
59644 + read_unlock(&tasklist_lock);
59645 + }
59646 +#endif
59647 +}
59648 +
59649 +int __gr_process_user_ban(struct user_struct *user)
59650 +{
59651 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59652 + if (unlikely(user->banned)) {
59653 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59654 + user->banned = 0;
59655 + user->ban_expires = 0;
59656 + free_uid(user);
59657 + } else
59658 + return -EPERM;
59659 + }
59660 +#endif
59661 + return 0;
59662 +}
59663 +
59664 +int gr_process_user_ban(void)
59665 +{
59666 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59667 + return __gr_process_user_ban(current->cred->user);
59668 +#endif
59669 + return 0;
59670 +}
59671 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59672 new file mode 100644
59673 index 0000000..4030d57
59674 --- /dev/null
59675 +++ b/grsecurity/grsec_sock.c
59676 @@ -0,0 +1,244 @@
59677 +#include <linux/kernel.h>
59678 +#include <linux/module.h>
59679 +#include <linux/sched.h>
59680 +#include <linux/file.h>
59681 +#include <linux/net.h>
59682 +#include <linux/in.h>
59683 +#include <linux/ip.h>
59684 +#include <net/sock.h>
59685 +#include <net/inet_sock.h>
59686 +#include <linux/grsecurity.h>
59687 +#include <linux/grinternal.h>
59688 +#include <linux/gracl.h>
59689 +
59690 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59691 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59692 +
59693 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59694 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59695 +
59696 +#ifdef CONFIG_UNIX_MODULE
59697 +EXPORT_SYMBOL(gr_acl_handle_unix);
59698 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59699 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59700 +EXPORT_SYMBOL(gr_handle_create);
59701 +#endif
59702 +
59703 +#ifdef CONFIG_GRKERNSEC
59704 +#define gr_conn_table_size 32749
59705 +struct conn_table_entry {
59706 + struct conn_table_entry *next;
59707 + struct signal_struct *sig;
59708 +};
59709 +
59710 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59711 +DEFINE_SPINLOCK(gr_conn_table_lock);
59712 +
59713 +extern const char * gr_socktype_to_name(unsigned char type);
59714 +extern const char * gr_proto_to_name(unsigned char proto);
59715 +extern const char * gr_sockfamily_to_name(unsigned char family);
59716 +
59717 +static __inline__ int
59718 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59719 +{
59720 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59721 +}
59722 +
59723 +static __inline__ int
59724 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59725 + __u16 sport, __u16 dport)
59726 +{
59727 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59728 + sig->gr_sport == sport && sig->gr_dport == dport))
59729 + return 1;
59730 + else
59731 + return 0;
59732 +}
59733 +
59734 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59735 +{
59736 + struct conn_table_entry **match;
59737 + unsigned int index;
59738 +
59739 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59740 + sig->gr_sport, sig->gr_dport,
59741 + gr_conn_table_size);
59742 +
59743 + newent->sig = sig;
59744 +
59745 + match = &gr_conn_table[index];
59746 + newent->next = *match;
59747 + *match = newent;
59748 +
59749 + return;
59750 +}
59751 +
59752 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59753 +{
59754 + struct conn_table_entry *match, *last = NULL;
59755 + unsigned int index;
59756 +
59757 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59758 + sig->gr_sport, sig->gr_dport,
59759 + gr_conn_table_size);
59760 +
59761 + match = gr_conn_table[index];
59762 + while (match && !conn_match(match->sig,
59763 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59764 + sig->gr_dport)) {
59765 + last = match;
59766 + match = match->next;
59767 + }
59768 +
59769 + if (match) {
59770 + if (last)
59771 + last->next = match->next;
59772 + else
59773 + gr_conn_table[index] = NULL;
59774 + kfree(match);
59775 + }
59776 +
59777 + return;
59778 +}
59779 +
59780 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59781 + __u16 sport, __u16 dport)
59782 +{
59783 + struct conn_table_entry *match;
59784 + unsigned int index;
59785 +
59786 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59787 +
59788 + match = gr_conn_table[index];
59789 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59790 + match = match->next;
59791 +
59792 + if (match)
59793 + return match->sig;
59794 + else
59795 + return NULL;
59796 +}
59797 +
59798 +#endif
59799 +
59800 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59801 +{
59802 +#ifdef CONFIG_GRKERNSEC
59803 + struct signal_struct *sig = task->signal;
59804 + struct conn_table_entry *newent;
59805 +
59806 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59807 + if (newent == NULL)
59808 + return;
59809 + /* no bh lock needed since we are called with bh disabled */
59810 + spin_lock(&gr_conn_table_lock);
59811 + gr_del_task_from_ip_table_nolock(sig);
59812 + sig->gr_saddr = inet->inet_rcv_saddr;
59813 + sig->gr_daddr = inet->inet_daddr;
59814 + sig->gr_sport = inet->inet_sport;
59815 + sig->gr_dport = inet->inet_dport;
59816 + gr_add_to_task_ip_table_nolock(sig, newent);
59817 + spin_unlock(&gr_conn_table_lock);
59818 +#endif
59819 + return;
59820 +}
59821 +
59822 +void gr_del_task_from_ip_table(struct task_struct *task)
59823 +{
59824 +#ifdef CONFIG_GRKERNSEC
59825 + spin_lock_bh(&gr_conn_table_lock);
59826 + gr_del_task_from_ip_table_nolock(task->signal);
59827 + spin_unlock_bh(&gr_conn_table_lock);
59828 +#endif
59829 + return;
59830 +}
59831 +
59832 +void
59833 +gr_attach_curr_ip(const struct sock *sk)
59834 +{
59835 +#ifdef CONFIG_GRKERNSEC
59836 + struct signal_struct *p, *set;
59837 + const struct inet_sock *inet = inet_sk(sk);
59838 +
59839 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59840 + return;
59841 +
59842 + set = current->signal;
59843 +
59844 + spin_lock_bh(&gr_conn_table_lock);
59845 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59846 + inet->inet_dport, inet->inet_sport);
59847 + if (unlikely(p != NULL)) {
59848 + set->curr_ip = p->curr_ip;
59849 + set->used_accept = 1;
59850 + gr_del_task_from_ip_table_nolock(p);
59851 + spin_unlock_bh(&gr_conn_table_lock);
59852 + return;
59853 + }
59854 + spin_unlock_bh(&gr_conn_table_lock);
59855 +
59856 + set->curr_ip = inet->inet_daddr;
59857 + set->used_accept = 1;
59858 +#endif
59859 + return;
59860 +}
59861 +
59862 +int
59863 +gr_handle_sock_all(const int family, const int type, const int protocol)
59864 +{
59865 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59866 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59867 + (family != AF_UNIX)) {
59868 + if (family == AF_INET)
59869 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59870 + else
59871 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59872 + return -EACCES;
59873 + }
59874 +#endif
59875 + return 0;
59876 +}
59877 +
59878 +int
59879 +gr_handle_sock_server(const struct sockaddr *sck)
59880 +{
59881 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59882 + if (grsec_enable_socket_server &&
59883 + in_group_p(grsec_socket_server_gid) &&
59884 + sck && (sck->sa_family != AF_UNIX) &&
59885 + (sck->sa_family != AF_LOCAL)) {
59886 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59887 + return -EACCES;
59888 + }
59889 +#endif
59890 + return 0;
59891 +}
59892 +
59893 +int
59894 +gr_handle_sock_server_other(const struct sock *sck)
59895 +{
59896 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59897 + if (grsec_enable_socket_server &&
59898 + in_group_p(grsec_socket_server_gid) &&
59899 + sck && (sck->sk_family != AF_UNIX) &&
59900 + (sck->sk_family != AF_LOCAL)) {
59901 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59902 + return -EACCES;
59903 + }
59904 +#endif
59905 + return 0;
59906 +}
59907 +
59908 +int
59909 +gr_handle_sock_client(const struct sockaddr *sck)
59910 +{
59911 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59912 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59913 + sck && (sck->sa_family != AF_UNIX) &&
59914 + (sck->sa_family != AF_LOCAL)) {
59915 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59916 + return -EACCES;
59917 + }
59918 +#endif
59919 + return 0;
59920 +}
59921 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59922 new file mode 100644
59923 index 0000000..a1aedd7
59924 --- /dev/null
59925 +++ b/grsecurity/grsec_sysctl.c
59926 @@ -0,0 +1,451 @@
59927 +#include <linux/kernel.h>
59928 +#include <linux/sched.h>
59929 +#include <linux/sysctl.h>
59930 +#include <linux/grsecurity.h>
59931 +#include <linux/grinternal.h>
59932 +
59933 +int
59934 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59935 +{
59936 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59937 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59938 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59939 + return -EACCES;
59940 + }
59941 +#endif
59942 + return 0;
59943 +}
59944 +
59945 +#ifdef CONFIG_GRKERNSEC_ROFS
59946 +static int __maybe_unused one = 1;
59947 +#endif
59948 +
59949 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59950 +struct ctl_table grsecurity_table[] = {
59951 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59952 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59953 +#ifdef CONFIG_GRKERNSEC_IO
59954 + {
59955 + .procname = "disable_priv_io",
59956 + .data = &grsec_disable_privio,
59957 + .maxlen = sizeof(int),
59958 + .mode = 0600,
59959 + .proc_handler = &proc_dointvec,
59960 + },
59961 +#endif
59962 +#endif
59963 +#ifdef CONFIG_GRKERNSEC_LINK
59964 + {
59965 + .procname = "linking_restrictions",
59966 + .data = &grsec_enable_link,
59967 + .maxlen = sizeof(int),
59968 + .mode = 0600,
59969 + .proc_handler = &proc_dointvec,
59970 + },
59971 +#endif
59972 +#ifdef CONFIG_GRKERNSEC_BRUTE
59973 + {
59974 + .procname = "deter_bruteforce",
59975 + .data = &grsec_enable_brute,
59976 + .maxlen = sizeof(int),
59977 + .mode = 0600,
59978 + .proc_handler = &proc_dointvec,
59979 + },
59980 +#endif
59981 +#ifdef CONFIG_GRKERNSEC_FIFO
59982 + {
59983 + .procname = "fifo_restrictions",
59984 + .data = &grsec_enable_fifo,
59985 + .maxlen = sizeof(int),
59986 + .mode = 0600,
59987 + .proc_handler = &proc_dointvec,
59988 + },
59989 +#endif
59990 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59991 + {
59992 + .procname = "ptrace_readexec",
59993 + .data = &grsec_enable_ptrace_readexec,
59994 + .maxlen = sizeof(int),
59995 + .mode = 0600,
59996 + .proc_handler = &proc_dointvec,
59997 + },
59998 +#endif
59999 +#ifdef CONFIG_GRKERNSEC_SETXID
60000 + {
60001 + .procname = "consistent_setxid",
60002 + .data = &grsec_enable_setxid,
60003 + .maxlen = sizeof(int),
60004 + .mode = 0600,
60005 + .proc_handler = &proc_dointvec,
60006 + },
60007 +#endif
60008 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60009 + {
60010 + .procname = "ip_blackhole",
60011 + .data = &grsec_enable_blackhole,
60012 + .maxlen = sizeof(int),
60013 + .mode = 0600,
60014 + .proc_handler = &proc_dointvec,
60015 + },
60016 + {
60017 + .procname = "lastack_retries",
60018 + .data = &grsec_lastack_retries,
60019 + .maxlen = sizeof(int),
60020 + .mode = 0600,
60021 + .proc_handler = &proc_dointvec,
60022 + },
60023 +#endif
60024 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60025 + {
60026 + .procname = "exec_logging",
60027 + .data = &grsec_enable_execlog,
60028 + .maxlen = sizeof(int),
60029 + .mode = 0600,
60030 + .proc_handler = &proc_dointvec,
60031 + },
60032 +#endif
60033 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60034 + {
60035 + .procname = "rwxmap_logging",
60036 + .data = &grsec_enable_log_rwxmaps,
60037 + .maxlen = sizeof(int),
60038 + .mode = 0600,
60039 + .proc_handler = &proc_dointvec,
60040 + },
60041 +#endif
60042 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60043 + {
60044 + .procname = "signal_logging",
60045 + .data = &grsec_enable_signal,
60046 + .maxlen = sizeof(int),
60047 + .mode = 0600,
60048 + .proc_handler = &proc_dointvec,
60049 + },
60050 +#endif
60051 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60052 + {
60053 + .procname = "forkfail_logging",
60054 + .data = &grsec_enable_forkfail,
60055 + .maxlen = sizeof(int),
60056 + .mode = 0600,
60057 + .proc_handler = &proc_dointvec,
60058 + },
60059 +#endif
60060 +#ifdef CONFIG_GRKERNSEC_TIME
60061 + {
60062 + .procname = "timechange_logging",
60063 + .data = &grsec_enable_time,
60064 + .maxlen = sizeof(int),
60065 + .mode = 0600,
60066 + .proc_handler = &proc_dointvec,
60067 + },
60068 +#endif
60069 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60070 + {
60071 + .procname = "chroot_deny_shmat",
60072 + .data = &grsec_enable_chroot_shmat,
60073 + .maxlen = sizeof(int),
60074 + .mode = 0600,
60075 + .proc_handler = &proc_dointvec,
60076 + },
60077 +#endif
60078 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60079 + {
60080 + .procname = "chroot_deny_unix",
60081 + .data = &grsec_enable_chroot_unix,
60082 + .maxlen = sizeof(int),
60083 + .mode = 0600,
60084 + .proc_handler = &proc_dointvec,
60085 + },
60086 +#endif
60087 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60088 + {
60089 + .procname = "chroot_deny_mount",
60090 + .data = &grsec_enable_chroot_mount,
60091 + .maxlen = sizeof(int),
60092 + .mode = 0600,
60093 + .proc_handler = &proc_dointvec,
60094 + },
60095 +#endif
60096 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60097 + {
60098 + .procname = "chroot_deny_fchdir",
60099 + .data = &grsec_enable_chroot_fchdir,
60100 + .maxlen = sizeof(int),
60101 + .mode = 0600,
60102 + .proc_handler = &proc_dointvec,
60103 + },
60104 +#endif
60105 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60106 + {
60107 + .procname = "chroot_deny_chroot",
60108 + .data = &grsec_enable_chroot_double,
60109 + .maxlen = sizeof(int),
60110 + .mode = 0600,
60111 + .proc_handler = &proc_dointvec,
60112 + },
60113 +#endif
60114 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60115 + {
60116 + .procname = "chroot_deny_pivot",
60117 + .data = &grsec_enable_chroot_pivot,
60118 + .maxlen = sizeof(int),
60119 + .mode = 0600,
60120 + .proc_handler = &proc_dointvec,
60121 + },
60122 +#endif
60123 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60124 + {
60125 + .procname = "chroot_enforce_chdir",
60126 + .data = &grsec_enable_chroot_chdir,
60127 + .maxlen = sizeof(int),
60128 + .mode = 0600,
60129 + .proc_handler = &proc_dointvec,
60130 + },
60131 +#endif
60132 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60133 + {
60134 + .procname = "chroot_deny_chmod",
60135 + .data = &grsec_enable_chroot_chmod,
60136 + .maxlen = sizeof(int),
60137 + .mode = 0600,
60138 + .proc_handler = &proc_dointvec,
60139 + },
60140 +#endif
60141 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60142 + {
60143 + .procname = "chroot_deny_mknod",
60144 + .data = &grsec_enable_chroot_mknod,
60145 + .maxlen = sizeof(int),
60146 + .mode = 0600,
60147 + .proc_handler = &proc_dointvec,
60148 + },
60149 +#endif
60150 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60151 + {
60152 + .procname = "chroot_restrict_nice",
60153 + .data = &grsec_enable_chroot_nice,
60154 + .maxlen = sizeof(int),
60155 + .mode = 0600,
60156 + .proc_handler = &proc_dointvec,
60157 + },
60158 +#endif
60159 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60160 + {
60161 + .procname = "chroot_execlog",
60162 + .data = &grsec_enable_chroot_execlog,
60163 + .maxlen = sizeof(int),
60164 + .mode = 0600,
60165 + .proc_handler = &proc_dointvec,
60166 + },
60167 +#endif
60168 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60169 + {
60170 + .procname = "chroot_caps",
60171 + .data = &grsec_enable_chroot_caps,
60172 + .maxlen = sizeof(int),
60173 + .mode = 0600,
60174 + .proc_handler = &proc_dointvec,
60175 + },
60176 +#endif
60177 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60178 + {
60179 + .procname = "chroot_deny_sysctl",
60180 + .data = &grsec_enable_chroot_sysctl,
60181 + .maxlen = sizeof(int),
60182 + .mode = 0600,
60183 + .proc_handler = &proc_dointvec,
60184 + },
60185 +#endif
60186 +#ifdef CONFIG_GRKERNSEC_TPE
60187 + {
60188 + .procname = "tpe",
60189 + .data = &grsec_enable_tpe,
60190 + .maxlen = sizeof(int),
60191 + .mode = 0600,
60192 + .proc_handler = &proc_dointvec,
60193 + },
60194 + {
60195 + .procname = "tpe_gid",
60196 + .data = &grsec_tpe_gid,
60197 + .maxlen = sizeof(int),
60198 + .mode = 0600,
60199 + .proc_handler = &proc_dointvec,
60200 + },
60201 +#endif
60202 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60203 + {
60204 + .procname = "tpe_invert",
60205 + .data = &grsec_enable_tpe_invert,
60206 + .maxlen = sizeof(int),
60207 + .mode = 0600,
60208 + .proc_handler = &proc_dointvec,
60209 + },
60210 +#endif
60211 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60212 + {
60213 + .procname = "tpe_restrict_all",
60214 + .data = &grsec_enable_tpe_all,
60215 + .maxlen = sizeof(int),
60216 + .mode = 0600,
60217 + .proc_handler = &proc_dointvec,
60218 + },
60219 +#endif
60220 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60221 + {
60222 + .procname = "socket_all",
60223 + .data = &grsec_enable_socket_all,
60224 + .maxlen = sizeof(int),
60225 + .mode = 0600,
60226 + .proc_handler = &proc_dointvec,
60227 + },
60228 + {
60229 + .procname = "socket_all_gid",
60230 + .data = &grsec_socket_all_gid,
60231 + .maxlen = sizeof(int),
60232 + .mode = 0600,
60233 + .proc_handler = &proc_dointvec,
60234 + },
60235 +#endif
60236 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60237 + {
60238 + .procname = "socket_client",
60239 + .data = &grsec_enable_socket_client,
60240 + .maxlen = sizeof(int),
60241 + .mode = 0600,
60242 + .proc_handler = &proc_dointvec,
60243 + },
60244 + {
60245 + .procname = "socket_client_gid",
60246 + .data = &grsec_socket_client_gid,
60247 + .maxlen = sizeof(int),
60248 + .mode = 0600,
60249 + .proc_handler = &proc_dointvec,
60250 + },
60251 +#endif
60252 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60253 + {
60254 + .procname = "socket_server",
60255 + .data = &grsec_enable_socket_server,
60256 + .maxlen = sizeof(int),
60257 + .mode = 0600,
60258 + .proc_handler = &proc_dointvec,
60259 + },
60260 + {
60261 + .procname = "socket_server_gid",
60262 + .data = &grsec_socket_server_gid,
60263 + .maxlen = sizeof(int),
60264 + .mode = 0600,
60265 + .proc_handler = &proc_dointvec,
60266 + },
60267 +#endif
60268 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60269 + {
60270 + .procname = "audit_group",
60271 + .data = &grsec_enable_group,
60272 + .maxlen = sizeof(int),
60273 + .mode = 0600,
60274 + .proc_handler = &proc_dointvec,
60275 + },
60276 + {
60277 + .procname = "audit_gid",
60278 + .data = &grsec_audit_gid,
60279 + .maxlen = sizeof(int),
60280 + .mode = 0600,
60281 + .proc_handler = &proc_dointvec,
60282 + },
60283 +#endif
60284 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60285 + {
60286 + .procname = "audit_chdir",
60287 + .data = &grsec_enable_chdir,
60288 + .maxlen = sizeof(int),
60289 + .mode = 0600,
60290 + .proc_handler = &proc_dointvec,
60291 + },
60292 +#endif
60293 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60294 + {
60295 + .procname = "audit_mount",
60296 + .data = &grsec_enable_mount,
60297 + .maxlen = sizeof(int),
60298 + .mode = 0600,
60299 + .proc_handler = &proc_dointvec,
60300 + },
60301 +#endif
60302 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60303 + {
60304 + .procname = "audit_textrel",
60305 + .data = &grsec_enable_audit_textrel,
60306 + .maxlen = sizeof(int),
60307 + .mode = 0600,
60308 + .proc_handler = &proc_dointvec,
60309 + },
60310 +#endif
60311 +#ifdef CONFIG_GRKERNSEC_DMESG
60312 + {
60313 + .procname = "dmesg",
60314 + .data = &grsec_enable_dmesg,
60315 + .maxlen = sizeof(int),
60316 + .mode = 0600,
60317 + .proc_handler = &proc_dointvec,
60318 + },
60319 +#endif
60320 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60321 + {
60322 + .procname = "chroot_findtask",
60323 + .data = &grsec_enable_chroot_findtask,
60324 + .maxlen = sizeof(int),
60325 + .mode = 0600,
60326 + .proc_handler = &proc_dointvec,
60327 + },
60328 +#endif
60329 +#ifdef CONFIG_GRKERNSEC_RESLOG
60330 + {
60331 + .procname = "resource_logging",
60332 + .data = &grsec_resource_logging,
60333 + .maxlen = sizeof(int),
60334 + .mode = 0600,
60335 + .proc_handler = &proc_dointvec,
60336 + },
60337 +#endif
60338 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60339 + {
60340 + .procname = "audit_ptrace",
60341 + .data = &grsec_enable_audit_ptrace,
60342 + .maxlen = sizeof(int),
60343 + .mode = 0600,
60344 + .proc_handler = &proc_dointvec,
60345 + },
60346 +#endif
60347 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60348 + {
60349 + .procname = "harden_ptrace",
60350 + .data = &grsec_enable_harden_ptrace,
60351 + .maxlen = sizeof(int),
60352 + .mode = 0600,
60353 + .proc_handler = &proc_dointvec,
60354 + },
60355 +#endif
60356 + {
60357 + .procname = "grsec_lock",
60358 + .data = &grsec_lock,
60359 + .maxlen = sizeof(int),
60360 + .mode = 0600,
60361 + .proc_handler = &proc_dointvec,
60362 + },
60363 +#endif
60364 +#ifdef CONFIG_GRKERNSEC_ROFS
60365 + {
60366 + .procname = "romount_protect",
60367 + .data = &grsec_enable_rofs,
60368 + .maxlen = sizeof(int),
60369 + .mode = 0600,
60370 + .proc_handler = &proc_dointvec_minmax,
60371 + .extra1 = &one,
60372 + .extra2 = &one,
60373 + },
60374 +#endif
60375 + { }
60376 +};
60377 +#endif
60378 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60379 new file mode 100644
60380 index 0000000..0dc13c3
60381 --- /dev/null
60382 +++ b/grsecurity/grsec_time.c
60383 @@ -0,0 +1,16 @@
60384 +#include <linux/kernel.h>
60385 +#include <linux/sched.h>
60386 +#include <linux/grinternal.h>
60387 +#include <linux/module.h>
60388 +
60389 +void
60390 +gr_log_timechange(void)
60391 +{
60392 +#ifdef CONFIG_GRKERNSEC_TIME
60393 + if (grsec_enable_time)
60394 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60395 +#endif
60396 + return;
60397 +}
60398 +
60399 +EXPORT_SYMBOL(gr_log_timechange);
60400 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60401 new file mode 100644
60402 index 0000000..07e0dc0
60403 --- /dev/null
60404 +++ b/grsecurity/grsec_tpe.c
60405 @@ -0,0 +1,73 @@
60406 +#include <linux/kernel.h>
60407 +#include <linux/sched.h>
60408 +#include <linux/file.h>
60409 +#include <linux/fs.h>
60410 +#include <linux/grinternal.h>
60411 +
60412 +extern int gr_acl_tpe_check(void);
60413 +
60414 +int
60415 +gr_tpe_allow(const struct file *file)
60416 +{
60417 +#ifdef CONFIG_GRKERNSEC
60418 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60419 + const struct cred *cred = current_cred();
60420 + char *msg = NULL;
60421 + char *msg2 = NULL;
60422 +
60423 + // never restrict root
60424 + if (!cred->uid)
60425 + return 1;
60426 +
60427 + if (grsec_enable_tpe) {
60428 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60429 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60430 + msg = "not being in trusted group";
60431 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60432 + msg = "being in untrusted group";
60433 +#else
60434 + if (in_group_p(grsec_tpe_gid))
60435 + msg = "being in untrusted group";
60436 +#endif
60437 + }
60438 + if (!msg && gr_acl_tpe_check())
60439 + msg = "being in untrusted role";
60440 +
60441 + // not in any affected group/role
60442 + if (!msg)
60443 + goto next_check;
60444 +
60445 + if (inode->i_uid)
60446 + msg2 = "file in non-root-owned directory";
60447 + else if (inode->i_mode & S_IWOTH)
60448 + msg2 = "file in world-writable directory";
60449 + else if (inode->i_mode & S_IWGRP)
60450 + msg2 = "file in group-writable directory";
60451 +
60452 + if (msg && msg2) {
60453 + char fullmsg[70] = {0};
60454 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60455 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60456 + return 0;
60457 + }
60458 + msg = NULL;
60459 +next_check:
60460 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60461 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60462 + return 1;
60463 +
60464 + if (inode->i_uid && (inode->i_uid != cred->uid))
60465 + msg = "directory not owned by user";
60466 + else if (inode->i_mode & S_IWOTH)
60467 + msg = "file in world-writable directory";
60468 + else if (inode->i_mode & S_IWGRP)
60469 + msg = "file in group-writable directory";
60470 +
60471 + if (msg) {
60472 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60473 + return 0;
60474 + }
60475 +#endif
60476 +#endif
60477 + return 1;
60478 +}
60479 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60480 new file mode 100644
60481 index 0000000..9f7b1ac
60482 --- /dev/null
60483 +++ b/grsecurity/grsum.c
60484 @@ -0,0 +1,61 @@
60485 +#include <linux/err.h>
60486 +#include <linux/kernel.h>
60487 +#include <linux/sched.h>
60488 +#include <linux/mm.h>
60489 +#include <linux/scatterlist.h>
60490 +#include <linux/crypto.h>
60491 +#include <linux/gracl.h>
60492 +
60493 +
60494 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60495 +#error "crypto and sha256 must be built into the kernel"
60496 +#endif
60497 +
60498 +int
60499 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60500 +{
60501 + char *p;
60502 + struct crypto_hash *tfm;
60503 + struct hash_desc desc;
60504 + struct scatterlist sg;
60505 + unsigned char temp_sum[GR_SHA_LEN];
60506 + volatile int retval = 0;
60507 + volatile int dummy = 0;
60508 + unsigned int i;
60509 +
60510 + sg_init_table(&sg, 1);
60511 +
60512 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60513 + if (IS_ERR(tfm)) {
60514 + /* should never happen, since sha256 should be built in */
60515 + return 1;
60516 + }
60517 +
60518 + desc.tfm = tfm;
60519 + desc.flags = 0;
60520 +
60521 + crypto_hash_init(&desc);
60522 +
60523 + p = salt;
60524 + sg_set_buf(&sg, p, GR_SALT_LEN);
60525 + crypto_hash_update(&desc, &sg, sg.length);
60526 +
60527 + p = entry->pw;
60528 + sg_set_buf(&sg, p, strlen(p));
60529 +
60530 + crypto_hash_update(&desc, &sg, sg.length);
60531 +
60532 + crypto_hash_final(&desc, temp_sum);
60533 +
60534 + memset(entry->pw, 0, GR_PW_LEN);
60535 +
60536 + for (i = 0; i < GR_SHA_LEN; i++)
60537 + if (sum[i] != temp_sum[i])
60538 + retval = 1;
60539 + else
60540 + dummy = 1; // waste a cycle
60541 +
60542 + crypto_free_hash(tfm);
60543 +
60544 + return retval;
60545 +}
60546 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60547 index 6cd5b64..f620d2d 100644
60548 --- a/include/acpi/acpi_bus.h
60549 +++ b/include/acpi/acpi_bus.h
60550 @@ -107,7 +107,7 @@ struct acpi_device_ops {
60551 acpi_op_bind bind;
60552 acpi_op_unbind unbind;
60553 acpi_op_notify notify;
60554 -};
60555 +} __no_const;
60556
60557 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60558
60559 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60560 index b7babf0..71e4e74 100644
60561 --- a/include/asm-generic/atomic-long.h
60562 +++ b/include/asm-generic/atomic-long.h
60563 @@ -22,6 +22,12 @@
60564
60565 typedef atomic64_t atomic_long_t;
60566
60567 +#ifdef CONFIG_PAX_REFCOUNT
60568 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60569 +#else
60570 +typedef atomic64_t atomic_long_unchecked_t;
60571 +#endif
60572 +
60573 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60574
60575 static inline long atomic_long_read(atomic_long_t *l)
60576 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60577 return (long)atomic64_read(v);
60578 }
60579
60580 +#ifdef CONFIG_PAX_REFCOUNT
60581 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60582 +{
60583 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60584 +
60585 + return (long)atomic64_read_unchecked(v);
60586 +}
60587 +#endif
60588 +
60589 static inline void atomic_long_set(atomic_long_t *l, long i)
60590 {
60591 atomic64_t *v = (atomic64_t *)l;
60592 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60593 atomic64_set(v, i);
60594 }
60595
60596 +#ifdef CONFIG_PAX_REFCOUNT
60597 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60598 +{
60599 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60600 +
60601 + atomic64_set_unchecked(v, i);
60602 +}
60603 +#endif
60604 +
60605 static inline void atomic_long_inc(atomic_long_t *l)
60606 {
60607 atomic64_t *v = (atomic64_t *)l;
60608 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60609 atomic64_inc(v);
60610 }
60611
60612 +#ifdef CONFIG_PAX_REFCOUNT
60613 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60614 +{
60615 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60616 +
60617 + atomic64_inc_unchecked(v);
60618 +}
60619 +#endif
60620 +
60621 static inline void atomic_long_dec(atomic_long_t *l)
60622 {
60623 atomic64_t *v = (atomic64_t *)l;
60624 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60625 atomic64_dec(v);
60626 }
60627
60628 +#ifdef CONFIG_PAX_REFCOUNT
60629 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60630 +{
60631 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60632 +
60633 + atomic64_dec_unchecked(v);
60634 +}
60635 +#endif
60636 +
60637 static inline void atomic_long_add(long i, atomic_long_t *l)
60638 {
60639 atomic64_t *v = (atomic64_t *)l;
60640 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60641 atomic64_add(i, v);
60642 }
60643
60644 +#ifdef CONFIG_PAX_REFCOUNT
60645 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60646 +{
60647 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60648 +
60649 + atomic64_add_unchecked(i, v);
60650 +}
60651 +#endif
60652 +
60653 static inline void atomic_long_sub(long i, atomic_long_t *l)
60654 {
60655 atomic64_t *v = (atomic64_t *)l;
60656 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60657 atomic64_sub(i, v);
60658 }
60659
60660 +#ifdef CONFIG_PAX_REFCOUNT
60661 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60662 +{
60663 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60664 +
60665 + atomic64_sub_unchecked(i, v);
60666 +}
60667 +#endif
60668 +
60669 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60670 {
60671 atomic64_t *v = (atomic64_t *)l;
60672 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60673 return (long)atomic64_inc_return(v);
60674 }
60675
60676 +#ifdef CONFIG_PAX_REFCOUNT
60677 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60678 +{
60679 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60680 +
60681 + return (long)atomic64_inc_return_unchecked(v);
60682 +}
60683 +#endif
60684 +
60685 static inline long atomic_long_dec_return(atomic_long_t *l)
60686 {
60687 atomic64_t *v = (atomic64_t *)l;
60688 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60689
60690 typedef atomic_t atomic_long_t;
60691
60692 +#ifdef CONFIG_PAX_REFCOUNT
60693 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60694 +#else
60695 +typedef atomic_t atomic_long_unchecked_t;
60696 +#endif
60697 +
60698 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60699 static inline long atomic_long_read(atomic_long_t *l)
60700 {
60701 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60702 return (long)atomic_read(v);
60703 }
60704
60705 +#ifdef CONFIG_PAX_REFCOUNT
60706 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60707 +{
60708 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60709 +
60710 + return (long)atomic_read_unchecked(v);
60711 +}
60712 +#endif
60713 +
60714 static inline void atomic_long_set(atomic_long_t *l, long i)
60715 {
60716 atomic_t *v = (atomic_t *)l;
60717 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60718 atomic_set(v, i);
60719 }
60720
60721 +#ifdef CONFIG_PAX_REFCOUNT
60722 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60723 +{
60724 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60725 +
60726 + atomic_set_unchecked(v, i);
60727 +}
60728 +#endif
60729 +
60730 static inline void atomic_long_inc(atomic_long_t *l)
60731 {
60732 atomic_t *v = (atomic_t *)l;
60733 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60734 atomic_inc(v);
60735 }
60736
60737 +#ifdef CONFIG_PAX_REFCOUNT
60738 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60739 +{
60740 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60741 +
60742 + atomic_inc_unchecked(v);
60743 +}
60744 +#endif
60745 +
60746 static inline void atomic_long_dec(atomic_long_t *l)
60747 {
60748 atomic_t *v = (atomic_t *)l;
60749 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60750 atomic_dec(v);
60751 }
60752
60753 +#ifdef CONFIG_PAX_REFCOUNT
60754 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60755 +{
60756 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60757 +
60758 + atomic_dec_unchecked(v);
60759 +}
60760 +#endif
60761 +
60762 static inline void atomic_long_add(long i, atomic_long_t *l)
60763 {
60764 atomic_t *v = (atomic_t *)l;
60765 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60766 atomic_add(i, v);
60767 }
60768
60769 +#ifdef CONFIG_PAX_REFCOUNT
60770 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60771 +{
60772 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60773 +
60774 + atomic_add_unchecked(i, v);
60775 +}
60776 +#endif
60777 +
60778 static inline void atomic_long_sub(long i, atomic_long_t *l)
60779 {
60780 atomic_t *v = (atomic_t *)l;
60781 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60782 atomic_sub(i, v);
60783 }
60784
60785 +#ifdef CONFIG_PAX_REFCOUNT
60786 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60787 +{
60788 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60789 +
60790 + atomic_sub_unchecked(i, v);
60791 +}
60792 +#endif
60793 +
60794 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60795 {
60796 atomic_t *v = (atomic_t *)l;
60797 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60798 return (long)atomic_inc_return(v);
60799 }
60800
60801 +#ifdef CONFIG_PAX_REFCOUNT
60802 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60803 +{
60804 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60805 +
60806 + return (long)atomic_inc_return_unchecked(v);
60807 +}
60808 +#endif
60809 +
60810 static inline long atomic_long_dec_return(atomic_long_t *l)
60811 {
60812 atomic_t *v = (atomic_t *)l;
60813 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60814
60815 #endif /* BITS_PER_LONG == 64 */
60816
60817 +#ifdef CONFIG_PAX_REFCOUNT
60818 +static inline void pax_refcount_needs_these_functions(void)
60819 +{
60820 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60821 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60822 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60823 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60824 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60825 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60826 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60827 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60828 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60829 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60830 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60831 +
60832 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60833 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60834 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60835 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60836 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60837 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60838 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60839 +}
60840 +#else
60841 +#define atomic_read_unchecked(v) atomic_read(v)
60842 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60843 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60844 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60845 +#define atomic_inc_unchecked(v) atomic_inc(v)
60846 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60847 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60848 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60849 +#define atomic_dec_unchecked(v) atomic_dec(v)
60850 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60851 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60852 +
60853 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60854 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60855 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60856 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60857 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60858 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60859 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60860 +#endif
60861 +
60862 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60863 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60864 index b18ce4f..2ee2843 100644
60865 --- a/include/asm-generic/atomic64.h
60866 +++ b/include/asm-generic/atomic64.h
60867 @@ -16,6 +16,8 @@ typedef struct {
60868 long long counter;
60869 } atomic64_t;
60870
60871 +typedef atomic64_t atomic64_unchecked_t;
60872 +
60873 #define ATOMIC64_INIT(i) { (i) }
60874
60875 extern long long atomic64_read(const atomic64_t *v);
60876 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60877 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60878 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60879
60880 +#define atomic64_read_unchecked(v) atomic64_read(v)
60881 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60882 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60883 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60884 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60885 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60886 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60887 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60888 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60889 +
60890 #endif /* _ASM_GENERIC_ATOMIC64_H */
60891 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60892 index 1bfcfe5..e04c5c9 100644
60893 --- a/include/asm-generic/cache.h
60894 +++ b/include/asm-generic/cache.h
60895 @@ -6,7 +6,7 @@
60896 * cache lines need to provide their own cache.h.
60897 */
60898
60899 -#define L1_CACHE_SHIFT 5
60900 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60901 +#define L1_CACHE_SHIFT 5UL
60902 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60903
60904 #endif /* __ASM_GENERIC_CACHE_H */
60905 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60906 index 0d68a1e..b74a761 100644
60907 --- a/include/asm-generic/emergency-restart.h
60908 +++ b/include/asm-generic/emergency-restart.h
60909 @@ -1,7 +1,7 @@
60910 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60911 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60912
60913 -static inline void machine_emergency_restart(void)
60914 +static inline __noreturn void machine_emergency_restart(void)
60915 {
60916 machine_restart(NULL);
60917 }
60918 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60919 index 0232ccb..13d9165 100644
60920 --- a/include/asm-generic/kmap_types.h
60921 +++ b/include/asm-generic/kmap_types.h
60922 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60923 KMAP_D(17) KM_NMI,
60924 KMAP_D(18) KM_NMI_PTE,
60925 KMAP_D(19) KM_KDB,
60926 +KMAP_D(20) KM_CLEARPAGE,
60927 /*
60928 * Remember to update debug_kmap_atomic() when adding new kmap types!
60929 */
60930 -KMAP_D(20) KM_TYPE_NR
60931 +KMAP_D(21) KM_TYPE_NR
60932 };
60933
60934 #undef KMAP_D
60935 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60936 index 9ceb03b..2efbcbd 100644
60937 --- a/include/asm-generic/local.h
60938 +++ b/include/asm-generic/local.h
60939 @@ -39,6 +39,7 @@ typedef struct
60940 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60941 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60942 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60943 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60944
60945 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60946 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60947 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60948 index 725612b..9cc513a 100644
60949 --- a/include/asm-generic/pgtable-nopmd.h
60950 +++ b/include/asm-generic/pgtable-nopmd.h
60951 @@ -1,14 +1,19 @@
60952 #ifndef _PGTABLE_NOPMD_H
60953 #define _PGTABLE_NOPMD_H
60954
60955 -#ifndef __ASSEMBLY__
60956 -
60957 #include <asm-generic/pgtable-nopud.h>
60958
60959 -struct mm_struct;
60960 -
60961 #define __PAGETABLE_PMD_FOLDED
60962
60963 +#define PMD_SHIFT PUD_SHIFT
60964 +#define PTRS_PER_PMD 1
60965 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60966 +#define PMD_MASK (~(PMD_SIZE-1))
60967 +
60968 +#ifndef __ASSEMBLY__
60969 +
60970 +struct mm_struct;
60971 +
60972 /*
60973 * Having the pmd type consist of a pud gets the size right, and allows
60974 * us to conceptually access the pud entry that this pmd is folded into
60975 @@ -16,11 +21,6 @@ struct mm_struct;
60976 */
60977 typedef struct { pud_t pud; } pmd_t;
60978
60979 -#define PMD_SHIFT PUD_SHIFT
60980 -#define PTRS_PER_PMD 1
60981 -#define PMD_SIZE (1UL << PMD_SHIFT)
60982 -#define PMD_MASK (~(PMD_SIZE-1))
60983 -
60984 /*
60985 * The "pud_xxx()" functions here are trivial for a folded two-level
60986 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60987 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60988 index 810431d..ccc3638 100644
60989 --- a/include/asm-generic/pgtable-nopud.h
60990 +++ b/include/asm-generic/pgtable-nopud.h
60991 @@ -1,10 +1,15 @@
60992 #ifndef _PGTABLE_NOPUD_H
60993 #define _PGTABLE_NOPUD_H
60994
60995 -#ifndef __ASSEMBLY__
60996 -
60997 #define __PAGETABLE_PUD_FOLDED
60998
60999 +#define PUD_SHIFT PGDIR_SHIFT
61000 +#define PTRS_PER_PUD 1
61001 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61002 +#define PUD_MASK (~(PUD_SIZE-1))
61003 +
61004 +#ifndef __ASSEMBLY__
61005 +
61006 /*
61007 * Having the pud type consist of a pgd gets the size right, and allows
61008 * us to conceptually access the pgd entry that this pud is folded into
61009 @@ -12,11 +17,6 @@
61010 */
61011 typedef struct { pgd_t pgd; } pud_t;
61012
61013 -#define PUD_SHIFT PGDIR_SHIFT
61014 -#define PTRS_PER_PUD 1
61015 -#define PUD_SIZE (1UL << PUD_SHIFT)
61016 -#define PUD_MASK (~(PUD_SIZE-1))
61017 -
61018 /*
61019 * The "pgd_xxx()" functions here are trivial for a folded two-level
61020 * setup: the pud is never bad, and a pud always exists (as it's folded
61021 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61022 index a03c098..19751cf 100644
61023 --- a/include/asm-generic/pgtable.h
61024 +++ b/include/asm-generic/pgtable.h
61025 @@ -445,6 +445,18 @@ static inline int pmd_write(pmd_t pmd)
61026 #endif /* __HAVE_ARCH_PMD_WRITE */
61027 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
61028
61029 +#ifndef __HAVE_ARCH_READ_PMD_ATOMIC
61030 +static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
61031 +{
61032 + /*
61033 + * Depend on compiler for an atomic pmd read. NOTE: this is
61034 + * only going to work, if the pmdval_t isn't larger than
61035 + * an unsigned long.
61036 + */
61037 + return *pmdp;
61038 +}
61039 +#endif /* __HAVE_ARCH_READ_PMD_ATOMIC */
61040 +
61041 /*
61042 * This function is meant to be used by sites walking pagetables with
61043 * the mmap_sem hold in read mode to protect against MADV_DONTNEED and
61044 @@ -458,11 +470,17 @@ static inline int pmd_write(pmd_t pmd)
61045 * undefined so behaving like if the pmd was none is safe (because it
61046 * can return none anyway). The compiler level barrier() is critically
61047 * important to compute the two checks atomically on the same pmdval.
61048 + *
61049 + * For 32bit kernels with a 64bit large pmd_t this automatically takes
61050 + * care of reading the pmd atomically to avoid SMP race conditions
61051 + * against pmd_populate() when the mmap_sem is hold for reading by the
61052 + * caller (a special atomic read not done by "gcc" as in the generic
61053 + * version above, is also needed when THP is disabled because the page
61054 + * fault can populate the pmd from under us).
61055 */
61056 static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
61057 {
61058 - /* depend on compiler for an atomic pmd read */
61059 - pmd_t pmdval = *pmd;
61060 + pmd_t pmdval = read_pmd_atomic(pmd);
61061 /*
61062 * The barrier will stabilize the pmdval in a register or on
61063 * the stack so that it will stop changing under the code.
61064 @@ -502,6 +520,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61065 #endif
61066 }
61067
61068 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61069 +static inline unsigned long pax_open_kernel(void) { return 0; }
61070 +#endif
61071 +
61072 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61073 +static inline unsigned long pax_close_kernel(void) { return 0; }
61074 +#endif
61075 +
61076 #endif /* CONFIG_MMU */
61077
61078 #endif /* !__ASSEMBLY__ */
61079 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
61080 index 9788568..510dece 100644
61081 --- a/include/asm-generic/uaccess.h
61082 +++ b/include/asm-generic/uaccess.h
61083 @@ -76,6 +76,8 @@ extern unsigned long search_exception_table(unsigned long);
61084 */
61085 #ifndef __copy_from_user
61086 static inline __must_check long __copy_from_user(void *to,
61087 + const void __user * from, unsigned long n) __size_overflow(3);
61088 +static inline __must_check long __copy_from_user(void *to,
61089 const void __user * from, unsigned long n)
61090 {
61091 if (__builtin_constant_p(n)) {
61092 @@ -106,6 +108,8 @@ static inline __must_check long __copy_from_user(void *to,
61093
61094 #ifndef __copy_to_user
61095 static inline __must_check long __copy_to_user(void __user *to,
61096 + const void *from, unsigned long n) __size_overflow(3);
61097 +static inline __must_check long __copy_to_user(void __user *to,
61098 const void *from, unsigned long n)
61099 {
61100 if (__builtin_constant_p(n)) {
61101 @@ -224,6 +228,7 @@ extern int __put_user_bad(void) __attribute__((noreturn));
61102 -EFAULT; \
61103 })
61104
61105 +static inline int __get_user_fn(size_t size, const void __user *ptr, void *x) __size_overflow(1);
61106 static inline int __get_user_fn(size_t size, const void __user *ptr, void *x)
61107 {
61108 size = __copy_from_user(x, ptr, size);
61109 @@ -240,6 +245,7 @@ extern int __get_user_bad(void) __attribute__((noreturn));
61110 #define __copy_to_user_inatomic __copy_to_user
61111 #endif
61112
61113 +static inline long copy_from_user(void *to, const void __user * from, unsigned long n) __size_overflow(3);
61114 static inline long copy_from_user(void *to,
61115 const void __user * from, unsigned long n)
61116 {
61117 @@ -250,6 +256,7 @@ static inline long copy_from_user(void *to,
61118 return n;
61119 }
61120
61121 +static inline long copy_to_user(void __user *to, const void *from, unsigned long n) __size_overflow(3);
61122 static inline long copy_to_user(void __user *to,
61123 const void *from, unsigned long n)
61124 {
61125 @@ -314,6 +321,8 @@ static inline long strlen_user(const char __user *src)
61126 */
61127 #ifndef __clear_user
61128 static inline __must_check unsigned long
61129 +__clear_user(void __user *to, unsigned long n) __size_overflow(2);
61130 +static inline __must_check unsigned long
61131 __clear_user(void __user *to, unsigned long n)
61132 {
61133 memset((void __force *)to, 0, n);
61134 @@ -322,6 +331,8 @@ __clear_user(void __user *to, unsigned long n)
61135 #endif
61136
61137 static inline __must_check unsigned long
61138 +clear_user(void __user *to, unsigned long n) __size_overflow(2);
61139 +static inline __must_check unsigned long
61140 clear_user(void __user *to, unsigned long n)
61141 {
61142 might_sleep();
61143 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61144 index b5e2e4c..6a5373e 100644
61145 --- a/include/asm-generic/vmlinux.lds.h
61146 +++ b/include/asm-generic/vmlinux.lds.h
61147 @@ -217,6 +217,7 @@
61148 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61149 VMLINUX_SYMBOL(__start_rodata) = .; \
61150 *(.rodata) *(.rodata.*) \
61151 + *(.data..read_only) \
61152 *(__vermagic) /* Kernel version magic */ \
61153 . = ALIGN(8); \
61154 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61155 @@ -722,17 +723,18 @@
61156 * section in the linker script will go there too. @phdr should have
61157 * a leading colon.
61158 *
61159 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61160 + * Note that this macros defines per_cpu_load as an absolute symbol.
61161 * If there is no need to put the percpu section at a predetermined
61162 * address, use PERCPU_SECTION.
61163 */
61164 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61165 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61166 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61167 + per_cpu_load = .; \
61168 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61169 - LOAD_OFFSET) { \
61170 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61171 PERCPU_INPUT(cacheline) \
61172 } phdr \
61173 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61174 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61175
61176 /**
61177 * PERCPU_SECTION - define output section for percpu area, simple version
61178 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61179 index 92f0981..d44a37c 100644
61180 --- a/include/drm/drmP.h
61181 +++ b/include/drm/drmP.h
61182 @@ -72,6 +72,7 @@
61183 #include <linux/workqueue.h>
61184 #include <linux/poll.h>
61185 #include <asm/pgalloc.h>
61186 +#include <asm/local.h>
61187 #include "drm.h"
61188
61189 #include <linux/idr.h>
61190 @@ -1038,7 +1039,7 @@ struct drm_device {
61191
61192 /** \name Usage Counters */
61193 /*@{ */
61194 - int open_count; /**< Outstanding files open */
61195 + local_t open_count; /**< Outstanding files open */
61196 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61197 atomic_t vma_count; /**< Outstanding vma areas open */
61198 int buf_use; /**< Buffers in use -- cannot alloc */
61199 @@ -1049,7 +1050,7 @@ struct drm_device {
61200 /*@{ */
61201 unsigned long counters;
61202 enum drm_stat_type types[15];
61203 - atomic_t counts[15];
61204 + atomic_unchecked_t counts[15];
61205 /*@} */
61206
61207 struct list_head filelist;
61208 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61209 index 37515d1..34fa8b0 100644
61210 --- a/include/drm/drm_crtc_helper.h
61211 +++ b/include/drm/drm_crtc_helper.h
61212 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
61213
61214 /* disable crtc when not in use - more explicit than dpms off */
61215 void (*disable)(struct drm_crtc *crtc);
61216 -};
61217 +} __no_const;
61218
61219 struct drm_encoder_helper_funcs {
61220 void (*dpms)(struct drm_encoder *encoder, int mode);
61221 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
61222 struct drm_connector *connector);
61223 /* disable encoder when not in use - more explicit than dpms off */
61224 void (*disable)(struct drm_encoder *encoder);
61225 -};
61226 +} __no_const;
61227
61228 struct drm_connector_helper_funcs {
61229 int (*get_modes)(struct drm_connector *connector);
61230 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61231 index 26c1f78..6722682 100644
61232 --- a/include/drm/ttm/ttm_memory.h
61233 +++ b/include/drm/ttm/ttm_memory.h
61234 @@ -47,7 +47,7 @@
61235
61236 struct ttm_mem_shrink {
61237 int (*do_shrink) (struct ttm_mem_shrink *);
61238 -};
61239 +} __no_const;
61240
61241 /**
61242 * struct ttm_mem_global - Global memory accounting structure.
61243 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61244 index e86dfca..40cc55f 100644
61245 --- a/include/linux/a.out.h
61246 +++ b/include/linux/a.out.h
61247 @@ -39,6 +39,14 @@ enum machine_type {
61248 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61249 };
61250
61251 +/* Constants for the N_FLAGS field */
61252 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61253 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61254 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61255 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61256 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61257 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61258 +
61259 #if !defined (N_MAGIC)
61260 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61261 #endif
61262 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61263 index f4ff882..84b53a6 100644
61264 --- a/include/linux/atmdev.h
61265 +++ b/include/linux/atmdev.h
61266 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61267 #endif
61268
61269 struct k_atm_aal_stats {
61270 -#define __HANDLE_ITEM(i) atomic_t i
61271 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61272 __AAL_STAT_ITEMS
61273 #undef __HANDLE_ITEM
61274 };
61275 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61276 index 0092102..8a801b4 100644
61277 --- a/include/linux/binfmts.h
61278 +++ b/include/linux/binfmts.h
61279 @@ -89,6 +89,7 @@ struct linux_binfmt {
61280 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61281 int (*load_shlib)(struct file *);
61282 int (*core_dump)(struct coredump_params *cprm);
61283 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61284 unsigned long min_coredump; /* minimal dump size */
61285 };
61286
61287 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61288 index 606cf33..b72c577 100644
61289 --- a/include/linux/blkdev.h
61290 +++ b/include/linux/blkdev.h
61291 @@ -1379,7 +1379,7 @@ struct block_device_operations {
61292 /* this callback is with swap_lock and sometimes page table lock held */
61293 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61294 struct module *owner;
61295 -};
61296 +} __do_const;
61297
61298 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61299 unsigned long);
61300 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61301 index 4d1a074..88f929a 100644
61302 --- a/include/linux/blktrace_api.h
61303 +++ b/include/linux/blktrace_api.h
61304 @@ -162,7 +162,7 @@ struct blk_trace {
61305 struct dentry *dir;
61306 struct dentry *dropped_file;
61307 struct dentry *msg_file;
61308 - atomic_t dropped;
61309 + atomic_unchecked_t dropped;
61310 };
61311
61312 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61313 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61314 index 83195fb..0b0f77d 100644
61315 --- a/include/linux/byteorder/little_endian.h
61316 +++ b/include/linux/byteorder/little_endian.h
61317 @@ -42,51 +42,51 @@
61318
61319 static inline __le64 __cpu_to_le64p(const __u64 *p)
61320 {
61321 - return (__force __le64)*p;
61322 + return (__force const __le64)*p;
61323 }
61324 static inline __u64 __le64_to_cpup(const __le64 *p)
61325 {
61326 - return (__force __u64)*p;
61327 + return (__force const __u64)*p;
61328 }
61329 static inline __le32 __cpu_to_le32p(const __u32 *p)
61330 {
61331 - return (__force __le32)*p;
61332 + return (__force const __le32)*p;
61333 }
61334 static inline __u32 __le32_to_cpup(const __le32 *p)
61335 {
61336 - return (__force __u32)*p;
61337 + return (__force const __u32)*p;
61338 }
61339 static inline __le16 __cpu_to_le16p(const __u16 *p)
61340 {
61341 - return (__force __le16)*p;
61342 + return (__force const __le16)*p;
61343 }
61344 static inline __u16 __le16_to_cpup(const __le16 *p)
61345 {
61346 - return (__force __u16)*p;
61347 + return (__force const __u16)*p;
61348 }
61349 static inline __be64 __cpu_to_be64p(const __u64 *p)
61350 {
61351 - return (__force __be64)__swab64p(p);
61352 + return (__force const __be64)__swab64p(p);
61353 }
61354 static inline __u64 __be64_to_cpup(const __be64 *p)
61355 {
61356 - return __swab64p((__u64 *)p);
61357 + return __swab64p((const __u64 *)p);
61358 }
61359 static inline __be32 __cpu_to_be32p(const __u32 *p)
61360 {
61361 - return (__force __be32)__swab32p(p);
61362 + return (__force const __be32)__swab32p(p);
61363 }
61364 static inline __u32 __be32_to_cpup(const __be32 *p)
61365 {
61366 - return __swab32p((__u32 *)p);
61367 + return __swab32p((const __u32 *)p);
61368 }
61369 static inline __be16 __cpu_to_be16p(const __u16 *p)
61370 {
61371 - return (__force __be16)__swab16p(p);
61372 + return (__force const __be16)__swab16p(p);
61373 }
61374 static inline __u16 __be16_to_cpup(const __be16 *p)
61375 {
61376 - return __swab16p((__u16 *)p);
61377 + return __swab16p((const __u16 *)p);
61378 }
61379 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61380 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61381 diff --git a/include/linux/cache.h b/include/linux/cache.h
61382 index 4c57065..4307975 100644
61383 --- a/include/linux/cache.h
61384 +++ b/include/linux/cache.h
61385 @@ -16,6 +16,10 @@
61386 #define __read_mostly
61387 #endif
61388
61389 +#ifndef __read_only
61390 +#define __read_only __read_mostly
61391 +#endif
61392 +
61393 #ifndef ____cacheline_aligned
61394 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61395 #endif
61396 diff --git a/include/linux/capability.h b/include/linux/capability.h
61397 index 12d52de..b5f7fa7 100644
61398 --- a/include/linux/capability.h
61399 +++ b/include/linux/capability.h
61400 @@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
61401 extern bool capable(int cap);
61402 extern bool ns_capable(struct user_namespace *ns, int cap);
61403 extern bool nsown_capable(int cap);
61404 +extern bool capable_nolog(int cap);
61405 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61406
61407 /* audit system wants to get cap info from files as well */
61408 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61409 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61410 index 04ffb2e..6799180 100644
61411 --- a/include/linux/cleancache.h
61412 +++ b/include/linux/cleancache.h
61413 @@ -31,7 +31,7 @@ struct cleancache_ops {
61414 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
61415 void (*flush_inode)(int, struct cleancache_filekey);
61416 void (*flush_fs)(int);
61417 -};
61418 +} __no_const;
61419
61420 extern struct cleancache_ops
61421 cleancache_register_ops(struct cleancache_ops *ops);
61422 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61423 index 2f40791..567b215 100644
61424 --- a/include/linux/compiler-gcc4.h
61425 +++ b/include/linux/compiler-gcc4.h
61426 @@ -32,6 +32,15 @@
61427 #define __linktime_error(message) __attribute__((__error__(message)))
61428
61429 #if __GNUC_MINOR__ >= 5
61430 +
61431 +#ifdef CONSTIFY_PLUGIN
61432 +#define __no_const __attribute__((no_const))
61433 +#define __do_const __attribute__((do_const))
61434 +#endif
61435 +
61436 +#ifdef SIZE_OVERFLOW_PLUGIN
61437 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61438 +#endif
61439 /*
61440 * Mark a position in code as unreachable. This can be used to
61441 * suppress control flow warnings after asm blocks that transfer
61442 @@ -47,6 +56,11 @@
61443 #define __noclone __attribute__((__noclone__))
61444
61445 #endif
61446 +
61447 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61448 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61449 +#define __bos0(ptr) __bos((ptr), 0)
61450 +#define __bos1(ptr) __bos((ptr), 1)
61451 #endif
61452
61453 #if __GNUC_MINOR__ > 0
61454 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61455 index 4a24354..ecaff7a 100644
61456 --- a/include/linux/compiler.h
61457 +++ b/include/linux/compiler.h
61458 @@ -5,31 +5,62 @@
61459
61460 #ifdef __CHECKER__
61461 # define __user __attribute__((noderef, address_space(1)))
61462 +# define __force_user __force __user
61463 # define __kernel __attribute__((address_space(0)))
61464 +# define __force_kernel __force __kernel
61465 # define __safe __attribute__((safe))
61466 # define __force __attribute__((force))
61467 # define __nocast __attribute__((nocast))
61468 # define __iomem __attribute__((noderef, address_space(2)))
61469 +# define __force_iomem __force __iomem
61470 # define __acquires(x) __attribute__((context(x,0,1)))
61471 # define __releases(x) __attribute__((context(x,1,0)))
61472 # define __acquire(x) __context__(x,1)
61473 # define __release(x) __context__(x,-1)
61474 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61475 # define __percpu __attribute__((noderef, address_space(3)))
61476 +# define __force_percpu __force __percpu
61477 #ifdef CONFIG_SPARSE_RCU_POINTER
61478 # define __rcu __attribute__((noderef, address_space(4)))
61479 +# define __force_rcu __force __rcu
61480 #else
61481 # define __rcu
61482 +# define __force_rcu
61483 #endif
61484 extern void __chk_user_ptr(const volatile void __user *);
61485 extern void __chk_io_ptr(const volatile void __iomem *);
61486 +#elif defined(CHECKER_PLUGIN)
61487 +//# define __user
61488 +//# define __force_user
61489 +//# define __kernel
61490 +//# define __force_kernel
61491 +# define __safe
61492 +# define __force
61493 +# define __nocast
61494 +# define __iomem
61495 +# define __force_iomem
61496 +# define __chk_user_ptr(x) (void)0
61497 +# define __chk_io_ptr(x) (void)0
61498 +# define __builtin_warning(x, y...) (1)
61499 +# define __acquires(x)
61500 +# define __releases(x)
61501 +# define __acquire(x) (void)0
61502 +# define __release(x) (void)0
61503 +# define __cond_lock(x,c) (c)
61504 +# define __percpu
61505 +# define __force_percpu
61506 +# define __rcu
61507 +# define __force_rcu
61508 #else
61509 # define __user
61510 +# define __force_user
61511 # define __kernel
61512 +# define __force_kernel
61513 # define __safe
61514 # define __force
61515 # define __nocast
61516 # define __iomem
61517 +# define __force_iomem
61518 # define __chk_user_ptr(x) (void)0
61519 # define __chk_io_ptr(x) (void)0
61520 # define __builtin_warning(x, y...) (1)
61521 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61522 # define __release(x) (void)0
61523 # define __cond_lock(x,c) (c)
61524 # define __percpu
61525 +# define __force_percpu
61526 # define __rcu
61527 +# define __force_rcu
61528 #endif
61529
61530 #ifdef __KERNEL__
61531 @@ -264,6 +297,17 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61532 # define __attribute_const__ /* unimplemented */
61533 #endif
61534
61535 +#ifndef __no_const
61536 +# define __no_const
61537 +#endif
61538 +
61539 +#ifndef __do_const
61540 +# define __do_const
61541 +#endif
61542 +
61543 +#ifndef __size_overflow
61544 +# define __size_overflow(...)
61545 +#endif
61546 /*
61547 * Tell gcc if a function is cold. The compiler will assume any path
61548 * directly leading to the call is unlikely.
61549 @@ -273,6 +317,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61550 #define __cold
61551 #endif
61552
61553 +#ifndef __alloc_size
61554 +#define __alloc_size(...)
61555 +#endif
61556 +
61557 +#ifndef __bos
61558 +#define __bos(ptr, arg)
61559 +#endif
61560 +
61561 +#ifndef __bos0
61562 +#define __bos0(ptr)
61563 +#endif
61564 +
61565 +#ifndef __bos1
61566 +#define __bos1(ptr)
61567 +#endif
61568 +
61569 /* Simple shorthand for a section definition */
61570 #ifndef __section
61571 # define __section(S) __attribute__ ((__section__(#S)))
61572 @@ -308,6 +368,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61573 * use is to mediate communication between process-level code and irq/NMI
61574 * handlers, all running on the same CPU.
61575 */
61576 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61577 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61578 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61579
61580 #endif /* __LINUX_COMPILER_H */
61581 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
61582 index e9eaec5..bfeb9bb 100644
61583 --- a/include/linux/cpuset.h
61584 +++ b/include/linux/cpuset.h
61585 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
61586 * nodemask.
61587 */
61588 smp_mb();
61589 - --ACCESS_ONCE(current->mems_allowed_change_disable);
61590 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
61591 }
61592
61593 static inline void set_mems_allowed(nodemask_t nodemask)
61594 diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
61595 index b936763..48685ee 100644
61596 --- a/include/linux/crash_dump.h
61597 +++ b/include/linux/crash_dump.h
61598 @@ -14,7 +14,7 @@ extern unsigned long long elfcorehdr_addr;
61599 extern unsigned long long elfcorehdr_size;
61600
61601 extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
61602 - unsigned long, int);
61603 + unsigned long, int) __size_overflow(3);
61604
61605 /* Architecture code defines this if there are other possible ELF
61606 * machine types, e.g. on bi-arch capable hardware. */
61607 diff --git a/include/linux/cred.h b/include/linux/cred.h
61608 index adadf71..6af5560 100644
61609 --- a/include/linux/cred.h
61610 +++ b/include/linux/cred.h
61611 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61612 static inline void validate_process_creds(void)
61613 {
61614 }
61615 +static inline void validate_task_creds(struct task_struct *task)
61616 +{
61617 +}
61618 #endif
61619
61620 /**
61621 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61622 index 8a94217..15d49e3 100644
61623 --- a/include/linux/crypto.h
61624 +++ b/include/linux/crypto.h
61625 @@ -365,7 +365,7 @@ struct cipher_tfm {
61626 const u8 *key, unsigned int keylen);
61627 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61628 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61629 -};
61630 +} __no_const;
61631
61632 struct hash_tfm {
61633 int (*init)(struct hash_desc *desc);
61634 @@ -386,13 +386,13 @@ struct compress_tfm {
61635 int (*cot_decompress)(struct crypto_tfm *tfm,
61636 const u8 *src, unsigned int slen,
61637 u8 *dst, unsigned int *dlen);
61638 -};
61639 +} __no_const;
61640
61641 struct rng_tfm {
61642 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61643 unsigned int dlen);
61644 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61645 -};
61646 +} __no_const;
61647
61648 #define crt_ablkcipher crt_u.ablkcipher
61649 #define crt_aead crt_u.aead
61650 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61651 index 7925bf0..d5143d2 100644
61652 --- a/include/linux/decompress/mm.h
61653 +++ b/include/linux/decompress/mm.h
61654 @@ -77,7 +77,7 @@ static void free(void *where)
61655 * warnings when not needed (indeed large_malloc / large_free are not
61656 * needed by inflate */
61657
61658 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61659 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61660 #define free(a) kfree(a)
61661
61662 #define large_malloc(a) vmalloc(a)
61663 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61664 index e13117c..e9fc938 100644
61665 --- a/include/linux/dma-mapping.h
61666 +++ b/include/linux/dma-mapping.h
61667 @@ -46,7 +46,7 @@ struct dma_map_ops {
61668 u64 (*get_required_mask)(struct device *dev);
61669 #endif
61670 int is_phys;
61671 -};
61672 +} __do_const;
61673
61674 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61675
61676 diff --git a/include/linux/efi.h b/include/linux/efi.h
61677 index 7cce0ea..c2085e4 100644
61678 --- a/include/linux/efi.h
61679 +++ b/include/linux/efi.h
61680 @@ -591,7 +591,7 @@ struct efivar_operations {
61681 efi_get_variable_t *get_variable;
61682 efi_get_next_variable_t *get_next_variable;
61683 efi_set_variable_t *set_variable;
61684 -};
61685 +} __no_const;
61686
61687 struct efivars {
61688 /*
61689 diff --git a/include/linux/elf.h b/include/linux/elf.h
61690 index 999b4f5..57753b4 100644
61691 --- a/include/linux/elf.h
61692 +++ b/include/linux/elf.h
61693 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61694 #define PT_GNU_EH_FRAME 0x6474e550
61695
61696 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61697 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61698 +
61699 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61700 +
61701 +/* Constants for the e_flags field */
61702 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61703 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61704 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61705 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61706 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61707 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61708
61709 /*
61710 * Extended Numbering
61711 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61712 #define DT_DEBUG 21
61713 #define DT_TEXTREL 22
61714 #define DT_JMPREL 23
61715 +#define DT_FLAGS 30
61716 + #define DF_TEXTREL 0x00000004
61717 #define DT_ENCODING 32
61718 #define OLD_DT_LOOS 0x60000000
61719 #define DT_LOOS 0x6000000d
61720 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61721 #define PF_W 0x2
61722 #define PF_X 0x1
61723
61724 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61725 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61726 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61727 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61728 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61729 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61730 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61731 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61732 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61733 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61734 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61735 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61736 +
61737 typedef struct elf32_phdr{
61738 Elf32_Word p_type;
61739 Elf32_Off p_offset;
61740 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61741 #define EI_OSABI 7
61742 #define EI_PAD 8
61743
61744 +#define EI_PAX 14
61745 +
61746 #define ELFMAG0 0x7f /* EI_MAG */
61747 #define ELFMAG1 'E'
61748 #define ELFMAG2 'L'
61749 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61750 #define elf_note elf32_note
61751 #define elf_addr_t Elf32_Off
61752 #define Elf_Half Elf32_Half
61753 +#define elf_dyn Elf32_Dyn
61754
61755 #else
61756
61757 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61758 #define elf_note elf64_note
61759 #define elf_addr_t Elf64_Off
61760 #define Elf_Half Elf64_Half
61761 +#define elf_dyn Elf64_Dyn
61762
61763 #endif
61764
61765 diff --git a/include/linux/filter.h b/include/linux/filter.h
61766 index 8eeb205..d59bfa2 100644
61767 --- a/include/linux/filter.h
61768 +++ b/include/linux/filter.h
61769 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
61770
61771 struct sk_buff;
61772 struct sock;
61773 +struct bpf_jit_work;
61774
61775 struct sk_filter
61776 {
61777 @@ -141,6 +142,9 @@ struct sk_filter
61778 unsigned int len; /* Number of filter blocks */
61779 unsigned int (*bpf_func)(const struct sk_buff *skb,
61780 const struct sock_filter *filter);
61781 +#ifdef CONFIG_BPF_JIT
61782 + struct bpf_jit_work *work;
61783 +#endif
61784 struct rcu_head rcu;
61785 struct sock_filter insns[0];
61786 };
61787 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61788 index 84ccf8e..2e9b14c 100644
61789 --- a/include/linux/firewire.h
61790 +++ b/include/linux/firewire.h
61791 @@ -428,7 +428,7 @@ struct fw_iso_context {
61792 union {
61793 fw_iso_callback_t sc;
61794 fw_iso_mc_callback_t mc;
61795 - } callback;
61796 + } __no_const callback;
61797 void *callback_data;
61798 };
61799
61800 diff --git a/include/linux/fs.h b/include/linux/fs.h
61801 index f4b6e06..d6ba573 100644
61802 --- a/include/linux/fs.h
61803 +++ b/include/linux/fs.h
61804 @@ -1628,7 +1628,8 @@ struct file_operations {
61805 int (*setlease)(struct file *, long, struct file_lock **);
61806 long (*fallocate)(struct file *file, int mode, loff_t offset,
61807 loff_t len);
61808 -};
61809 +} __do_const;
61810 +typedef struct file_operations __no_const file_operations_no_const;
61811
61812 struct inode_operations {
61813 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
61814 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61815 index 003dc0f..3c4ea97 100644
61816 --- a/include/linux/fs_struct.h
61817 +++ b/include/linux/fs_struct.h
61818 @@ -6,7 +6,7 @@
61819 #include <linux/seqlock.h>
61820
61821 struct fs_struct {
61822 - int users;
61823 + atomic_t users;
61824 spinlock_t lock;
61825 seqcount_t seq;
61826 int umask;
61827 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61828 index ce31408..b1ad003 100644
61829 --- a/include/linux/fscache-cache.h
61830 +++ b/include/linux/fscache-cache.h
61831 @@ -102,7 +102,7 @@ struct fscache_operation {
61832 fscache_operation_release_t release;
61833 };
61834
61835 -extern atomic_t fscache_op_debug_id;
61836 +extern atomic_unchecked_t fscache_op_debug_id;
61837 extern void fscache_op_work_func(struct work_struct *work);
61838
61839 extern void fscache_enqueue_operation(struct fscache_operation *);
61840 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61841 {
61842 INIT_WORK(&op->work, fscache_op_work_func);
61843 atomic_set(&op->usage, 1);
61844 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61845 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61846 op->processor = processor;
61847 op->release = release;
61848 INIT_LIST_HEAD(&op->pend_link);
61849 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61850 index 2a53f10..0187fdf 100644
61851 --- a/include/linux/fsnotify.h
61852 +++ b/include/linux/fsnotify.h
61853 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61854 */
61855 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61856 {
61857 - return kstrdup(name, GFP_KERNEL);
61858 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61859 }
61860
61861 /*
61862 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61863 index 91d0e0a3..035666b 100644
61864 --- a/include/linux/fsnotify_backend.h
61865 +++ b/include/linux/fsnotify_backend.h
61866 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61867 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61868 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61869 };
61870 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61871
61872 /*
61873 * A group is a "thing" that wants to receive notification about filesystem
61874 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61875 index c3da42d..c70e0df 100644
61876 --- a/include/linux/ftrace_event.h
61877 +++ b/include/linux/ftrace_event.h
61878 @@ -97,7 +97,7 @@ struct trace_event_functions {
61879 trace_print_func raw;
61880 trace_print_func hex;
61881 trace_print_func binary;
61882 -};
61883 +} __no_const;
61884
61885 struct trace_event {
61886 struct hlist_node node;
61887 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61888 extern int trace_add_event_call(struct ftrace_event_call *call);
61889 extern void trace_remove_event_call(struct ftrace_event_call *call);
61890
61891 -#define is_signed_type(type) (((type)(-1)) < 0)
61892 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61893
61894 int trace_set_clr_event(const char *system, const char *event, int set);
61895
61896 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61897 index e61d319..0da8505 100644
61898 --- a/include/linux/genhd.h
61899 +++ b/include/linux/genhd.h
61900 @@ -185,7 +185,7 @@ struct gendisk {
61901 struct kobject *slave_dir;
61902
61903 struct timer_rand_state *random;
61904 - atomic_t sync_io; /* RAID */
61905 + atomic_unchecked_t sync_io; /* RAID */
61906 struct disk_events *ev;
61907 #ifdef CONFIG_BLK_DEV_INTEGRITY
61908 struct blk_integrity *integrity;
61909 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61910 new file mode 100644
61911 index 0000000..8a130b6
61912 --- /dev/null
61913 +++ b/include/linux/gracl.h
61914 @@ -0,0 +1,319 @@
61915 +#ifndef GR_ACL_H
61916 +#define GR_ACL_H
61917 +
61918 +#include <linux/grdefs.h>
61919 +#include <linux/resource.h>
61920 +#include <linux/capability.h>
61921 +#include <linux/dcache.h>
61922 +#include <asm/resource.h>
61923 +
61924 +/* Major status information */
61925 +
61926 +#define GR_VERSION "grsecurity 2.9"
61927 +#define GRSECURITY_VERSION 0x2900
61928 +
61929 +enum {
61930 + GR_SHUTDOWN = 0,
61931 + GR_ENABLE = 1,
61932 + GR_SPROLE = 2,
61933 + GR_RELOAD = 3,
61934 + GR_SEGVMOD = 4,
61935 + GR_STATUS = 5,
61936 + GR_UNSPROLE = 6,
61937 + GR_PASSSET = 7,
61938 + GR_SPROLEPAM = 8,
61939 +};
61940 +
61941 +/* Password setup definitions
61942 + * kernel/grhash.c */
61943 +enum {
61944 + GR_PW_LEN = 128,
61945 + GR_SALT_LEN = 16,
61946 + GR_SHA_LEN = 32,
61947 +};
61948 +
61949 +enum {
61950 + GR_SPROLE_LEN = 64,
61951 +};
61952 +
61953 +enum {
61954 + GR_NO_GLOB = 0,
61955 + GR_REG_GLOB,
61956 + GR_CREATE_GLOB
61957 +};
61958 +
61959 +#define GR_NLIMITS 32
61960 +
61961 +/* Begin Data Structures */
61962 +
61963 +struct sprole_pw {
61964 + unsigned char *rolename;
61965 + unsigned char salt[GR_SALT_LEN];
61966 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61967 +};
61968 +
61969 +struct name_entry {
61970 + __u32 key;
61971 + ino_t inode;
61972 + dev_t device;
61973 + char *name;
61974 + __u16 len;
61975 + __u8 deleted;
61976 + struct name_entry *prev;
61977 + struct name_entry *next;
61978 +};
61979 +
61980 +struct inodev_entry {
61981 + struct name_entry *nentry;
61982 + struct inodev_entry *prev;
61983 + struct inodev_entry *next;
61984 +};
61985 +
61986 +struct acl_role_db {
61987 + struct acl_role_label **r_hash;
61988 + __u32 r_size;
61989 +};
61990 +
61991 +struct inodev_db {
61992 + struct inodev_entry **i_hash;
61993 + __u32 i_size;
61994 +};
61995 +
61996 +struct name_db {
61997 + struct name_entry **n_hash;
61998 + __u32 n_size;
61999 +};
62000 +
62001 +struct crash_uid {
62002 + uid_t uid;
62003 + unsigned long expires;
62004 +};
62005 +
62006 +struct gr_hash_struct {
62007 + void **table;
62008 + void **nametable;
62009 + void *first;
62010 + __u32 table_size;
62011 + __u32 used_size;
62012 + int type;
62013 +};
62014 +
62015 +/* Userspace Grsecurity ACL data structures */
62016 +
62017 +struct acl_subject_label {
62018 + char *filename;
62019 + ino_t inode;
62020 + dev_t device;
62021 + __u32 mode;
62022 + kernel_cap_t cap_mask;
62023 + kernel_cap_t cap_lower;
62024 + kernel_cap_t cap_invert_audit;
62025 +
62026 + struct rlimit res[GR_NLIMITS];
62027 + __u32 resmask;
62028 +
62029 + __u8 user_trans_type;
62030 + __u8 group_trans_type;
62031 + uid_t *user_transitions;
62032 + gid_t *group_transitions;
62033 + __u16 user_trans_num;
62034 + __u16 group_trans_num;
62035 +
62036 + __u32 sock_families[2];
62037 + __u32 ip_proto[8];
62038 + __u32 ip_type;
62039 + struct acl_ip_label **ips;
62040 + __u32 ip_num;
62041 + __u32 inaddr_any_override;
62042 +
62043 + __u32 crashes;
62044 + unsigned long expires;
62045 +
62046 + struct acl_subject_label *parent_subject;
62047 + struct gr_hash_struct *hash;
62048 + struct acl_subject_label *prev;
62049 + struct acl_subject_label *next;
62050 +
62051 + struct acl_object_label **obj_hash;
62052 + __u32 obj_hash_size;
62053 + __u16 pax_flags;
62054 +};
62055 +
62056 +struct role_allowed_ip {
62057 + __u32 addr;
62058 + __u32 netmask;
62059 +
62060 + struct role_allowed_ip *prev;
62061 + struct role_allowed_ip *next;
62062 +};
62063 +
62064 +struct role_transition {
62065 + char *rolename;
62066 +
62067 + struct role_transition *prev;
62068 + struct role_transition *next;
62069 +};
62070 +
62071 +struct acl_role_label {
62072 + char *rolename;
62073 + uid_t uidgid;
62074 + __u16 roletype;
62075 +
62076 + __u16 auth_attempts;
62077 + unsigned long expires;
62078 +
62079 + struct acl_subject_label *root_label;
62080 + struct gr_hash_struct *hash;
62081 +
62082 + struct acl_role_label *prev;
62083 + struct acl_role_label *next;
62084 +
62085 + struct role_transition *transitions;
62086 + struct role_allowed_ip *allowed_ips;
62087 + uid_t *domain_children;
62088 + __u16 domain_child_num;
62089 +
62090 + umode_t umask;
62091 +
62092 + struct acl_subject_label **subj_hash;
62093 + __u32 subj_hash_size;
62094 +};
62095 +
62096 +struct user_acl_role_db {
62097 + struct acl_role_label **r_table;
62098 + __u32 num_pointers; /* Number of allocations to track */
62099 + __u32 num_roles; /* Number of roles */
62100 + __u32 num_domain_children; /* Number of domain children */
62101 + __u32 num_subjects; /* Number of subjects */
62102 + __u32 num_objects; /* Number of objects */
62103 +};
62104 +
62105 +struct acl_object_label {
62106 + char *filename;
62107 + ino_t inode;
62108 + dev_t device;
62109 + __u32 mode;
62110 +
62111 + struct acl_subject_label *nested;
62112 + struct acl_object_label *globbed;
62113 +
62114 + /* next two structures not used */
62115 +
62116 + struct acl_object_label *prev;
62117 + struct acl_object_label *next;
62118 +};
62119 +
62120 +struct acl_ip_label {
62121 + char *iface;
62122 + __u32 addr;
62123 + __u32 netmask;
62124 + __u16 low, high;
62125 + __u8 mode;
62126 + __u32 type;
62127 + __u32 proto[8];
62128 +
62129 + /* next two structures not used */
62130 +
62131 + struct acl_ip_label *prev;
62132 + struct acl_ip_label *next;
62133 +};
62134 +
62135 +struct gr_arg {
62136 + struct user_acl_role_db role_db;
62137 + unsigned char pw[GR_PW_LEN];
62138 + unsigned char salt[GR_SALT_LEN];
62139 + unsigned char sum[GR_SHA_LEN];
62140 + unsigned char sp_role[GR_SPROLE_LEN];
62141 + struct sprole_pw *sprole_pws;
62142 + dev_t segv_device;
62143 + ino_t segv_inode;
62144 + uid_t segv_uid;
62145 + __u16 num_sprole_pws;
62146 + __u16 mode;
62147 +};
62148 +
62149 +struct gr_arg_wrapper {
62150 + struct gr_arg *arg;
62151 + __u32 version;
62152 + __u32 size;
62153 +};
62154 +
62155 +struct subject_map {
62156 + struct acl_subject_label *user;
62157 + struct acl_subject_label *kernel;
62158 + struct subject_map *prev;
62159 + struct subject_map *next;
62160 +};
62161 +
62162 +struct acl_subj_map_db {
62163 + struct subject_map **s_hash;
62164 + __u32 s_size;
62165 +};
62166 +
62167 +/* End Data Structures Section */
62168 +
62169 +/* Hash functions generated by empirical testing by Brad Spengler
62170 + Makes good use of the low bits of the inode. Generally 0-1 times
62171 + in loop for successful match. 0-3 for unsuccessful match.
62172 + Shift/add algorithm with modulus of table size and an XOR*/
62173 +
62174 +static __inline__ unsigned int
62175 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62176 +{
62177 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62178 +}
62179 +
62180 + static __inline__ unsigned int
62181 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62182 +{
62183 + return ((const unsigned long)userp % sz);
62184 +}
62185 +
62186 +static __inline__ unsigned int
62187 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62188 +{
62189 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62190 +}
62191 +
62192 +static __inline__ unsigned int
62193 +nhash(const char *name, const __u16 len, const unsigned int sz)
62194 +{
62195 + return full_name_hash((const unsigned char *)name, len) % sz;
62196 +}
62197 +
62198 +#define FOR_EACH_ROLE_START(role) \
62199 + role = role_list; \
62200 + while (role) {
62201 +
62202 +#define FOR_EACH_ROLE_END(role) \
62203 + role = role->prev; \
62204 + }
62205 +
62206 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62207 + subj = NULL; \
62208 + iter = 0; \
62209 + while (iter < role->subj_hash_size) { \
62210 + if (subj == NULL) \
62211 + subj = role->subj_hash[iter]; \
62212 + if (subj == NULL) { \
62213 + iter++; \
62214 + continue; \
62215 + }
62216 +
62217 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62218 + subj = subj->next; \
62219 + if (subj == NULL) \
62220 + iter++; \
62221 + }
62222 +
62223 +
62224 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62225 + subj = role->hash->first; \
62226 + while (subj != NULL) {
62227 +
62228 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62229 + subj = subj->next; \
62230 + }
62231 +
62232 +#endif
62233 +
62234 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62235 new file mode 100644
62236 index 0000000..323ecf2
62237 --- /dev/null
62238 +++ b/include/linux/gralloc.h
62239 @@ -0,0 +1,9 @@
62240 +#ifndef __GRALLOC_H
62241 +#define __GRALLOC_H
62242 +
62243 +void acl_free_all(void);
62244 +int acl_alloc_stack_init(unsigned long size);
62245 +void *acl_alloc(unsigned long len);
62246 +void *acl_alloc_num(unsigned long num, unsigned long len);
62247 +
62248 +#endif
62249 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62250 new file mode 100644
62251 index 0000000..b30e9bc
62252 --- /dev/null
62253 +++ b/include/linux/grdefs.h
62254 @@ -0,0 +1,140 @@
62255 +#ifndef GRDEFS_H
62256 +#define GRDEFS_H
62257 +
62258 +/* Begin grsecurity status declarations */
62259 +
62260 +enum {
62261 + GR_READY = 0x01,
62262 + GR_STATUS_INIT = 0x00 // disabled state
62263 +};
62264 +
62265 +/* Begin ACL declarations */
62266 +
62267 +/* Role flags */
62268 +
62269 +enum {
62270 + GR_ROLE_USER = 0x0001,
62271 + GR_ROLE_GROUP = 0x0002,
62272 + GR_ROLE_DEFAULT = 0x0004,
62273 + GR_ROLE_SPECIAL = 0x0008,
62274 + GR_ROLE_AUTH = 0x0010,
62275 + GR_ROLE_NOPW = 0x0020,
62276 + GR_ROLE_GOD = 0x0040,
62277 + GR_ROLE_LEARN = 0x0080,
62278 + GR_ROLE_TPE = 0x0100,
62279 + GR_ROLE_DOMAIN = 0x0200,
62280 + GR_ROLE_PAM = 0x0400,
62281 + GR_ROLE_PERSIST = 0x0800
62282 +};
62283 +
62284 +/* ACL Subject and Object mode flags */
62285 +enum {
62286 + GR_DELETED = 0x80000000
62287 +};
62288 +
62289 +/* ACL Object-only mode flags */
62290 +enum {
62291 + GR_READ = 0x00000001,
62292 + GR_APPEND = 0x00000002,
62293 + GR_WRITE = 0x00000004,
62294 + GR_EXEC = 0x00000008,
62295 + GR_FIND = 0x00000010,
62296 + GR_INHERIT = 0x00000020,
62297 + GR_SETID = 0x00000040,
62298 + GR_CREATE = 0x00000080,
62299 + GR_DELETE = 0x00000100,
62300 + GR_LINK = 0x00000200,
62301 + GR_AUDIT_READ = 0x00000400,
62302 + GR_AUDIT_APPEND = 0x00000800,
62303 + GR_AUDIT_WRITE = 0x00001000,
62304 + GR_AUDIT_EXEC = 0x00002000,
62305 + GR_AUDIT_FIND = 0x00004000,
62306 + GR_AUDIT_INHERIT= 0x00008000,
62307 + GR_AUDIT_SETID = 0x00010000,
62308 + GR_AUDIT_CREATE = 0x00020000,
62309 + GR_AUDIT_DELETE = 0x00040000,
62310 + GR_AUDIT_LINK = 0x00080000,
62311 + GR_PTRACERD = 0x00100000,
62312 + GR_NOPTRACE = 0x00200000,
62313 + GR_SUPPRESS = 0x00400000,
62314 + GR_NOLEARN = 0x00800000,
62315 + GR_INIT_TRANSFER= 0x01000000
62316 +};
62317 +
62318 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62319 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62320 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62321 +
62322 +/* ACL subject-only mode flags */
62323 +enum {
62324 + GR_KILL = 0x00000001,
62325 + GR_VIEW = 0x00000002,
62326 + GR_PROTECTED = 0x00000004,
62327 + GR_LEARN = 0x00000008,
62328 + GR_OVERRIDE = 0x00000010,
62329 + /* just a placeholder, this mode is only used in userspace */
62330 + GR_DUMMY = 0x00000020,
62331 + GR_PROTSHM = 0x00000040,
62332 + GR_KILLPROC = 0x00000080,
62333 + GR_KILLIPPROC = 0x00000100,
62334 + /* just a placeholder, this mode is only used in userspace */
62335 + GR_NOTROJAN = 0x00000200,
62336 + GR_PROTPROCFD = 0x00000400,
62337 + GR_PROCACCT = 0x00000800,
62338 + GR_RELAXPTRACE = 0x00001000,
62339 + GR_NESTED = 0x00002000,
62340 + GR_INHERITLEARN = 0x00004000,
62341 + GR_PROCFIND = 0x00008000,
62342 + GR_POVERRIDE = 0x00010000,
62343 + GR_KERNELAUTH = 0x00020000,
62344 + GR_ATSECURE = 0x00040000,
62345 + GR_SHMEXEC = 0x00080000
62346 +};
62347 +
62348 +enum {
62349 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62350 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62351 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62352 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62353 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62354 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62355 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62356 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62357 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62358 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62359 +};
62360 +
62361 +enum {
62362 + GR_ID_USER = 0x01,
62363 + GR_ID_GROUP = 0x02,
62364 +};
62365 +
62366 +enum {
62367 + GR_ID_ALLOW = 0x01,
62368 + GR_ID_DENY = 0x02,
62369 +};
62370 +
62371 +#define GR_CRASH_RES 31
62372 +#define GR_UIDTABLE_MAX 500
62373 +
62374 +/* begin resource learning section */
62375 +enum {
62376 + GR_RLIM_CPU_BUMP = 60,
62377 + GR_RLIM_FSIZE_BUMP = 50000,
62378 + GR_RLIM_DATA_BUMP = 10000,
62379 + GR_RLIM_STACK_BUMP = 1000,
62380 + GR_RLIM_CORE_BUMP = 10000,
62381 + GR_RLIM_RSS_BUMP = 500000,
62382 + GR_RLIM_NPROC_BUMP = 1,
62383 + GR_RLIM_NOFILE_BUMP = 5,
62384 + GR_RLIM_MEMLOCK_BUMP = 50000,
62385 + GR_RLIM_AS_BUMP = 500000,
62386 + GR_RLIM_LOCKS_BUMP = 2,
62387 + GR_RLIM_SIGPENDING_BUMP = 5,
62388 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62389 + GR_RLIM_NICE_BUMP = 1,
62390 + GR_RLIM_RTPRIO_BUMP = 1,
62391 + GR_RLIM_RTTIME_BUMP = 1000000
62392 +};
62393 +
62394 +#endif
62395 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62396 new file mode 100644
62397 index 0000000..da390f1
62398 --- /dev/null
62399 +++ b/include/linux/grinternal.h
62400 @@ -0,0 +1,221 @@
62401 +#ifndef __GRINTERNAL_H
62402 +#define __GRINTERNAL_H
62403 +
62404 +#ifdef CONFIG_GRKERNSEC
62405 +
62406 +#include <linux/fs.h>
62407 +#include <linux/mnt_namespace.h>
62408 +#include <linux/nsproxy.h>
62409 +#include <linux/gracl.h>
62410 +#include <linux/grdefs.h>
62411 +#include <linux/grmsg.h>
62412 +
62413 +void gr_add_learn_entry(const char *fmt, ...)
62414 + __attribute__ ((format (printf, 1, 2)));
62415 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62416 + const struct vfsmount *mnt);
62417 +__u32 gr_check_create(const struct dentry *new_dentry,
62418 + const struct dentry *parent,
62419 + const struct vfsmount *mnt, const __u32 mode);
62420 +int gr_check_protected_task(const struct task_struct *task);
62421 +__u32 to_gr_audit(const __u32 reqmode);
62422 +int gr_set_acls(const int type);
62423 +int gr_apply_subject_to_task(struct task_struct *task);
62424 +int gr_acl_is_enabled(void);
62425 +char gr_roletype_to_char(void);
62426 +
62427 +void gr_handle_alertkill(struct task_struct *task);
62428 +char *gr_to_filename(const struct dentry *dentry,
62429 + const struct vfsmount *mnt);
62430 +char *gr_to_filename1(const struct dentry *dentry,
62431 + const struct vfsmount *mnt);
62432 +char *gr_to_filename2(const struct dentry *dentry,
62433 + const struct vfsmount *mnt);
62434 +char *gr_to_filename3(const struct dentry *dentry,
62435 + const struct vfsmount *mnt);
62436 +
62437 +extern int grsec_enable_ptrace_readexec;
62438 +extern int grsec_enable_harden_ptrace;
62439 +extern int grsec_enable_link;
62440 +extern int grsec_enable_fifo;
62441 +extern int grsec_enable_execve;
62442 +extern int grsec_enable_shm;
62443 +extern int grsec_enable_execlog;
62444 +extern int grsec_enable_signal;
62445 +extern int grsec_enable_audit_ptrace;
62446 +extern int grsec_enable_forkfail;
62447 +extern int grsec_enable_time;
62448 +extern int grsec_enable_rofs;
62449 +extern int grsec_enable_chroot_shmat;
62450 +extern int grsec_enable_chroot_mount;
62451 +extern int grsec_enable_chroot_double;
62452 +extern int grsec_enable_chroot_pivot;
62453 +extern int grsec_enable_chroot_chdir;
62454 +extern int grsec_enable_chroot_chmod;
62455 +extern int grsec_enable_chroot_mknod;
62456 +extern int grsec_enable_chroot_fchdir;
62457 +extern int grsec_enable_chroot_nice;
62458 +extern int grsec_enable_chroot_execlog;
62459 +extern int grsec_enable_chroot_caps;
62460 +extern int grsec_enable_chroot_sysctl;
62461 +extern int grsec_enable_chroot_unix;
62462 +extern int grsec_enable_tpe;
62463 +extern int grsec_tpe_gid;
62464 +extern int grsec_enable_tpe_all;
62465 +extern int grsec_enable_tpe_invert;
62466 +extern int grsec_enable_socket_all;
62467 +extern int grsec_socket_all_gid;
62468 +extern int grsec_enable_socket_client;
62469 +extern int grsec_socket_client_gid;
62470 +extern int grsec_enable_socket_server;
62471 +extern int grsec_socket_server_gid;
62472 +extern int grsec_audit_gid;
62473 +extern int grsec_enable_group;
62474 +extern int grsec_enable_audit_textrel;
62475 +extern int grsec_enable_log_rwxmaps;
62476 +extern int grsec_enable_mount;
62477 +extern int grsec_enable_chdir;
62478 +extern int grsec_resource_logging;
62479 +extern int grsec_enable_blackhole;
62480 +extern int grsec_lastack_retries;
62481 +extern int grsec_enable_brute;
62482 +extern int grsec_lock;
62483 +
62484 +extern spinlock_t grsec_alert_lock;
62485 +extern unsigned long grsec_alert_wtime;
62486 +extern unsigned long grsec_alert_fyet;
62487 +
62488 +extern spinlock_t grsec_audit_lock;
62489 +
62490 +extern rwlock_t grsec_exec_file_lock;
62491 +
62492 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62493 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62494 + (tsk)->exec_file->f_vfsmnt) : "/")
62495 +
62496 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62497 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62498 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62499 +
62500 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62501 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62502 + (tsk)->exec_file->f_vfsmnt) : "/")
62503 +
62504 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62505 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62506 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62507 +
62508 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62509 +
62510 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62511 +
62512 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62513 + (task)->pid, (cred)->uid, \
62514 + (cred)->euid, (cred)->gid, (cred)->egid, \
62515 + gr_parent_task_fullpath(task), \
62516 + (task)->real_parent->comm, (task)->real_parent->pid, \
62517 + (pcred)->uid, (pcred)->euid, \
62518 + (pcred)->gid, (pcred)->egid
62519 +
62520 +#define GR_CHROOT_CAPS {{ \
62521 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62522 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62523 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62524 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62525 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62526 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62527 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62528 +
62529 +#define security_learn(normal_msg,args...) \
62530 +({ \
62531 + read_lock(&grsec_exec_file_lock); \
62532 + gr_add_learn_entry(normal_msg "\n", ## args); \
62533 + read_unlock(&grsec_exec_file_lock); \
62534 +})
62535 +
62536 +enum {
62537 + GR_DO_AUDIT,
62538 + GR_DONT_AUDIT,
62539 + /* used for non-audit messages that we shouldn't kill the task on */
62540 + GR_DONT_AUDIT_GOOD
62541 +};
62542 +
62543 +enum {
62544 + GR_TTYSNIFF,
62545 + GR_RBAC,
62546 + GR_RBAC_STR,
62547 + GR_STR_RBAC,
62548 + GR_RBAC_MODE2,
62549 + GR_RBAC_MODE3,
62550 + GR_FILENAME,
62551 + GR_SYSCTL_HIDDEN,
62552 + GR_NOARGS,
62553 + GR_ONE_INT,
62554 + GR_ONE_INT_TWO_STR,
62555 + GR_ONE_STR,
62556 + GR_STR_INT,
62557 + GR_TWO_STR_INT,
62558 + GR_TWO_INT,
62559 + GR_TWO_U64,
62560 + GR_THREE_INT,
62561 + GR_FIVE_INT_TWO_STR,
62562 + GR_TWO_STR,
62563 + GR_THREE_STR,
62564 + GR_FOUR_STR,
62565 + GR_STR_FILENAME,
62566 + GR_FILENAME_STR,
62567 + GR_FILENAME_TWO_INT,
62568 + GR_FILENAME_TWO_INT_STR,
62569 + GR_TEXTREL,
62570 + GR_PTRACE,
62571 + GR_RESOURCE,
62572 + GR_CAP,
62573 + GR_SIG,
62574 + GR_SIG2,
62575 + GR_CRASH1,
62576 + GR_CRASH2,
62577 + GR_PSACCT,
62578 + GR_RWXMAP
62579 +};
62580 +
62581 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62582 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62583 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62584 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62585 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62586 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62587 +#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)
62588 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62589 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62590 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62591 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62592 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62593 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62594 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62595 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62596 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62597 +#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)
62598 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62599 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62600 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62601 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62602 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62603 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62604 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62605 +#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)
62606 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62607 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62608 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62609 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62610 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62611 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62612 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62613 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62614 +#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)
62615 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62616 +
62617 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62618 +
62619 +#endif
62620 +
62621 +#endif
62622 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62623 new file mode 100644
62624 index 0000000..ae576a1
62625 --- /dev/null
62626 +++ b/include/linux/grmsg.h
62627 @@ -0,0 +1,109 @@
62628 +#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"
62629 +#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"
62630 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62631 +#define GR_STOPMOD_MSG "denied modification of module state by "
62632 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62633 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62634 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62635 +#define GR_IOPL_MSG "denied use of iopl() by "
62636 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62637 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62638 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62639 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62640 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62641 +#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"
62642 +#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"
62643 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62644 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62645 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62646 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62647 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62648 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62649 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62650 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62651 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62652 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62653 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62654 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62655 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62656 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62657 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62658 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62659 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62660 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62661 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62662 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62663 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62664 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62665 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62666 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62667 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62668 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62669 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62670 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62671 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62672 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62673 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62674 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62675 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62676 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62677 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62678 +#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"
62679 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62680 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62681 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62682 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62683 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62684 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62685 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62686 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62687 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62688 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62689 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62690 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62691 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62692 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62693 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62694 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62695 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62696 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62697 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62698 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62699 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62700 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62701 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62702 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62703 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62704 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62705 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62706 +#define GR_TIME_MSG "time set by "
62707 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62708 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62709 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62710 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62711 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62712 +#define GR_BIND_MSG "denied bind() by "
62713 +#define GR_CONNECT_MSG "denied connect() by "
62714 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62715 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62716 +#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"
62717 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62718 +#define GR_CAP_ACL_MSG "use of %s denied for "
62719 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62720 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62721 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62722 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62723 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62724 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62725 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62726 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62727 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62728 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62729 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62730 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62731 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62732 +#define GR_VM86_MSG "denied use of vm86 by "
62733 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62734 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62735 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62736 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62737 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62738 new file mode 100644
62739 index 0000000..acd05db
62740 --- /dev/null
62741 +++ b/include/linux/grsecurity.h
62742 @@ -0,0 +1,232 @@
62743 +#ifndef GR_SECURITY_H
62744 +#define GR_SECURITY_H
62745 +#include <linux/fs.h>
62746 +#include <linux/fs_struct.h>
62747 +#include <linux/binfmts.h>
62748 +#include <linux/gracl.h>
62749 +
62750 +/* notify of brain-dead configs */
62751 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62752 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62753 +#endif
62754 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62755 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62756 +#endif
62757 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62758 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62759 +#endif
62760 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62761 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62762 +#endif
62763 +
62764 +#include <linux/compat.h>
62765 +
62766 +struct user_arg_ptr {
62767 +#ifdef CONFIG_COMPAT
62768 + bool is_compat;
62769 +#endif
62770 + union {
62771 + const char __user *const __user *native;
62772 +#ifdef CONFIG_COMPAT
62773 + compat_uptr_t __user *compat;
62774 +#endif
62775 + } ptr;
62776 +};
62777 +
62778 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62779 +void gr_handle_brute_check(void);
62780 +void gr_handle_kernel_exploit(void);
62781 +int gr_process_user_ban(void);
62782 +
62783 +char gr_roletype_to_char(void);
62784 +
62785 +int gr_acl_enable_at_secure(void);
62786 +
62787 +int gr_check_user_change(int real, int effective, int fs);
62788 +int gr_check_group_change(int real, int effective, int fs);
62789 +
62790 +void gr_del_task_from_ip_table(struct task_struct *p);
62791 +
62792 +int gr_pid_is_chrooted(struct task_struct *p);
62793 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62794 +int gr_handle_chroot_nice(void);
62795 +int gr_handle_chroot_sysctl(const int op);
62796 +int gr_handle_chroot_setpriority(struct task_struct *p,
62797 + const int niceval);
62798 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62799 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62800 + const struct vfsmount *mnt);
62801 +void gr_handle_chroot_chdir(struct path *path);
62802 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62803 + const struct vfsmount *mnt, const int mode);
62804 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62805 + const struct vfsmount *mnt, const int mode);
62806 +int gr_handle_chroot_mount(const struct dentry *dentry,
62807 + const struct vfsmount *mnt,
62808 + const char *dev_name);
62809 +int gr_handle_chroot_pivot(void);
62810 +int gr_handle_chroot_unix(const pid_t pid);
62811 +
62812 +int gr_handle_rawio(const struct inode *inode);
62813 +
62814 +void gr_handle_ioperm(void);
62815 +void gr_handle_iopl(void);
62816 +
62817 +umode_t gr_acl_umask(void);
62818 +
62819 +int gr_tpe_allow(const struct file *file);
62820 +
62821 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62822 +void gr_clear_chroot_entries(struct task_struct *task);
62823 +
62824 +void gr_log_forkfail(const int retval);
62825 +void gr_log_timechange(void);
62826 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62827 +void gr_log_chdir(const struct dentry *dentry,
62828 + const struct vfsmount *mnt);
62829 +void gr_log_chroot_exec(const struct dentry *dentry,
62830 + const struct vfsmount *mnt);
62831 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62832 +void gr_log_remount(const char *devname, const int retval);
62833 +void gr_log_unmount(const char *devname, const int retval);
62834 +void gr_log_mount(const char *from, const char *to, const int retval);
62835 +void gr_log_textrel(struct vm_area_struct *vma);
62836 +void gr_log_rwxmmap(struct file *file);
62837 +void gr_log_rwxmprotect(struct file *file);
62838 +
62839 +int gr_handle_follow_link(const struct inode *parent,
62840 + const struct inode *inode,
62841 + const struct dentry *dentry,
62842 + const struct vfsmount *mnt);
62843 +int gr_handle_fifo(const struct dentry *dentry,
62844 + const struct vfsmount *mnt,
62845 + const struct dentry *dir, const int flag,
62846 + const int acc_mode);
62847 +int gr_handle_hardlink(const struct dentry *dentry,
62848 + const struct vfsmount *mnt,
62849 + struct inode *inode,
62850 + const int mode, const char *to);
62851 +
62852 +int gr_is_capable(const int cap);
62853 +int gr_is_capable_nolog(const int cap);
62854 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62855 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62856 +
62857 +void gr_learn_resource(const struct task_struct *task, const int limit,
62858 + const unsigned long wanted, const int gt);
62859 +void gr_copy_label(struct task_struct *tsk);
62860 +void gr_handle_crash(struct task_struct *task, const int sig);
62861 +int gr_handle_signal(const struct task_struct *p, const int sig);
62862 +int gr_check_crash_uid(const uid_t uid);
62863 +int gr_check_protected_task(const struct task_struct *task);
62864 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62865 +int gr_acl_handle_mmap(const struct file *file,
62866 + const unsigned long prot);
62867 +int gr_acl_handle_mprotect(const struct file *file,
62868 + const unsigned long prot);
62869 +int gr_check_hidden_task(const struct task_struct *tsk);
62870 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62871 + const struct vfsmount *mnt);
62872 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62873 + const struct vfsmount *mnt);
62874 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62875 + const struct vfsmount *mnt, const int fmode);
62876 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62877 + const struct vfsmount *mnt, umode_t *mode);
62878 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62879 + const struct vfsmount *mnt);
62880 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62881 + const struct vfsmount *mnt);
62882 +int gr_handle_ptrace(struct task_struct *task, const long request);
62883 +int gr_handle_proc_ptrace(struct task_struct *task);
62884 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62885 + const struct vfsmount *mnt);
62886 +int gr_check_crash_exec(const struct file *filp);
62887 +int gr_acl_is_enabled(void);
62888 +void gr_set_kernel_label(struct task_struct *task);
62889 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62890 + const gid_t gid);
62891 +int gr_set_proc_label(const struct dentry *dentry,
62892 + const struct vfsmount *mnt,
62893 + const int unsafe_flags);
62894 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62895 + const struct vfsmount *mnt);
62896 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62897 + const struct vfsmount *mnt, int acc_mode);
62898 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62899 + const struct dentry *p_dentry,
62900 + const struct vfsmount *p_mnt,
62901 + int open_flags, int acc_mode, const int imode);
62902 +void gr_handle_create(const struct dentry *dentry,
62903 + const struct vfsmount *mnt);
62904 +void gr_handle_proc_create(const struct dentry *dentry,
62905 + const struct inode *inode);
62906 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62907 + const struct dentry *parent_dentry,
62908 + const struct vfsmount *parent_mnt,
62909 + const int mode);
62910 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62911 + const struct dentry *parent_dentry,
62912 + const struct vfsmount *parent_mnt);
62913 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62914 + const struct vfsmount *mnt);
62915 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62916 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62917 + const struct vfsmount *mnt);
62918 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62919 + const struct dentry *parent_dentry,
62920 + const struct vfsmount *parent_mnt,
62921 + const char *from);
62922 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62923 + const struct dentry *parent_dentry,
62924 + const struct vfsmount *parent_mnt,
62925 + const struct dentry *old_dentry,
62926 + const struct vfsmount *old_mnt, const char *to);
62927 +int gr_acl_handle_rename(struct dentry *new_dentry,
62928 + struct dentry *parent_dentry,
62929 + const struct vfsmount *parent_mnt,
62930 + struct dentry *old_dentry,
62931 + struct inode *old_parent_inode,
62932 + struct vfsmount *old_mnt, const char *newname);
62933 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62934 + struct dentry *old_dentry,
62935 + struct dentry *new_dentry,
62936 + struct vfsmount *mnt, const __u8 replace);
62937 +__u32 gr_check_link(const struct dentry *new_dentry,
62938 + const struct dentry *parent_dentry,
62939 + const struct vfsmount *parent_mnt,
62940 + const struct dentry *old_dentry,
62941 + const struct vfsmount *old_mnt);
62942 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62943 + const unsigned int namelen, const ino_t ino);
62944 +
62945 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62946 + const struct vfsmount *mnt);
62947 +void gr_acl_handle_exit(void);
62948 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62949 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62950 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62951 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62952 +void gr_audit_ptrace(struct task_struct *task);
62953 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62954 +
62955 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62956 +
62957 +#ifdef CONFIG_GRKERNSEC
62958 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62959 +void gr_handle_vm86(void);
62960 +void gr_handle_mem_readwrite(u64 from, u64 to);
62961 +
62962 +void gr_log_badprocpid(const char *entry);
62963 +
62964 +extern int grsec_enable_dmesg;
62965 +extern int grsec_disable_privio;
62966 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62967 +extern int grsec_enable_chroot_findtask;
62968 +#endif
62969 +#ifdef CONFIG_GRKERNSEC_SETXID
62970 +extern int grsec_enable_setxid;
62971 +#endif
62972 +#endif
62973 +
62974 +#endif
62975 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62976 new file mode 100644
62977 index 0000000..e7ffaaf
62978 --- /dev/null
62979 +++ b/include/linux/grsock.h
62980 @@ -0,0 +1,19 @@
62981 +#ifndef __GRSOCK_H
62982 +#define __GRSOCK_H
62983 +
62984 +extern void gr_attach_curr_ip(const struct sock *sk);
62985 +extern int gr_handle_sock_all(const int family, const int type,
62986 + const int protocol);
62987 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62988 +extern int gr_handle_sock_server_other(const struct sock *sck);
62989 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62990 +extern int gr_search_connect(struct socket * sock,
62991 + struct sockaddr_in * addr);
62992 +extern int gr_search_bind(struct socket * sock,
62993 + struct sockaddr_in * addr);
62994 +extern int gr_search_listen(struct socket * sock);
62995 +extern int gr_search_accept(struct socket * sock);
62996 +extern int gr_search_socket(const int domain, const int type,
62997 + const int protocol);
62998 +
62999 +#endif
63000 diff --git a/include/linux/hid.h b/include/linux/hid.h
63001 index 3a95da6..51986f1 100644
63002 --- a/include/linux/hid.h
63003 +++ b/include/linux/hid.h
63004 @@ -696,7 +696,7 @@ struct hid_ll_driver {
63005 unsigned int code, int value);
63006
63007 int (*parse)(struct hid_device *hdev);
63008 -};
63009 +} __no_const;
63010
63011 #define PM_HINT_FULLON 1<<5
63012 #define PM_HINT_NORMAL 1<<1
63013 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63014 index 3a93f73..b19d0b3 100644
63015 --- a/include/linux/highmem.h
63016 +++ b/include/linux/highmem.h
63017 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
63018 kunmap_atomic(kaddr, KM_USER0);
63019 }
63020
63021 +static inline void sanitize_highpage(struct page *page)
63022 +{
63023 + void *kaddr;
63024 + unsigned long flags;
63025 +
63026 + local_irq_save(flags);
63027 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
63028 + clear_page(kaddr);
63029 + kunmap_atomic(kaddr, KM_CLEARPAGE);
63030 + local_irq_restore(flags);
63031 +}
63032 +
63033 static inline void zero_user_segments(struct page *page,
63034 unsigned start1, unsigned end1,
63035 unsigned start2, unsigned end2)
63036 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63037 index 8e25a91..551b161 100644
63038 --- a/include/linux/i2c.h
63039 +++ b/include/linux/i2c.h
63040 @@ -364,6 +364,7 @@ struct i2c_algorithm {
63041 /* To determine what the adapter supports */
63042 u32 (*functionality) (struct i2c_adapter *);
63043 };
63044 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63045
63046 /*
63047 * i2c_adapter is the structure used to identify a physical i2c bus along
63048 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63049 index a6deef4..c56a7f2 100644
63050 --- a/include/linux/i2o.h
63051 +++ b/include/linux/i2o.h
63052 @@ -564,7 +564,7 @@ struct i2o_controller {
63053 struct i2o_device *exec; /* Executive */
63054 #if BITS_PER_LONG == 64
63055 spinlock_t context_list_lock; /* lock for context_list */
63056 - atomic_t context_list_counter; /* needed for unique contexts */
63057 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63058 struct list_head context_list; /* list of context id's
63059 and pointers */
63060 #endif
63061 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63062 index 58404b0..439ed95 100644
63063 --- a/include/linux/if_team.h
63064 +++ b/include/linux/if_team.h
63065 @@ -64,6 +64,7 @@ struct team_mode_ops {
63066 void (*port_leave)(struct team *team, struct team_port *port);
63067 void (*port_change_mac)(struct team *team, struct team_port *port);
63068 };
63069 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63070
63071 enum team_option_type {
63072 TEAM_OPTION_TYPE_U32,
63073 @@ -112,7 +113,7 @@ struct team {
63074 struct list_head option_list;
63075
63076 const struct team_mode *mode;
63077 - struct team_mode_ops ops;
63078 + team_mode_ops_no_const ops;
63079 long mode_priv[TEAM_MODE_PRIV_LONGS];
63080 };
63081
63082 diff --git a/include/linux/init.h b/include/linux/init.h
63083 index 6b95109..4aca62c 100644
63084 --- a/include/linux/init.h
63085 +++ b/include/linux/init.h
63086 @@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
63087
63088 /* Each module must use one module_init(). */
63089 #define module_init(initfn) \
63090 - static inline initcall_t __inittest(void) \
63091 + static inline __used initcall_t __inittest(void) \
63092 { return initfn; } \
63093 int init_module(void) __attribute__((alias(#initfn)));
63094
63095 /* This is only required if you want to be unloadable. */
63096 #define module_exit(exitfn) \
63097 - static inline exitcall_t __exittest(void) \
63098 + static inline __used exitcall_t __exittest(void) \
63099 { return exitfn; } \
63100 void cleanup_module(void) __attribute__((alias(#exitfn)));
63101
63102 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63103 index 9c66b1a..a3fdded 100644
63104 --- a/include/linux/init_task.h
63105 +++ b/include/linux/init_task.h
63106 @@ -127,6 +127,12 @@ extern struct cred init_cred;
63107
63108 #define INIT_TASK_COMM "swapper"
63109
63110 +#ifdef CONFIG_X86
63111 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63112 +#else
63113 +#define INIT_TASK_THREAD_INFO
63114 +#endif
63115 +
63116 /*
63117 * INIT_TASK is used to set up the first task table, touch at
63118 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63119 @@ -165,6 +171,7 @@ extern struct cred init_cred;
63120 RCU_INIT_POINTER(.cred, &init_cred), \
63121 .comm = INIT_TASK_COMM, \
63122 .thread = INIT_THREAD, \
63123 + INIT_TASK_THREAD_INFO \
63124 .fs = &init_fs, \
63125 .files = &init_files, \
63126 .signal = &init_signals, \
63127 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63128 index e6ca56d..8583707 100644
63129 --- a/include/linux/intel-iommu.h
63130 +++ b/include/linux/intel-iommu.h
63131 @@ -296,7 +296,7 @@ struct iommu_flush {
63132 u8 fm, u64 type);
63133 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63134 unsigned int size_order, u64 type);
63135 -};
63136 +} __no_const;
63137
63138 enum {
63139 SR_DMAR_FECTL_REG,
63140 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63141 index a64b00e..464d8bc 100644
63142 --- a/include/linux/interrupt.h
63143 +++ b/include/linux/interrupt.h
63144 @@ -441,7 +441,7 @@ enum
63145 /* map softirq index to softirq name. update 'softirq_to_name' in
63146 * kernel/softirq.c when adding a new softirq.
63147 */
63148 -extern char *softirq_to_name[NR_SOFTIRQS];
63149 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63150
63151 /* softirq mask and active fields moved to irq_cpustat_t in
63152 * asm/hardirq.h to get better cache usage. KAO
63153 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63154
63155 struct softirq_action
63156 {
63157 - void (*action)(struct softirq_action *);
63158 + void (*action)(void);
63159 };
63160
63161 asmlinkage void do_softirq(void);
63162 asmlinkage void __do_softirq(void);
63163 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63164 +extern void open_softirq(int nr, void (*action)(void));
63165 extern void softirq_init(void);
63166 static inline void __raise_softirq_irqoff(unsigned int nr)
63167 {
63168 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63169 index 3875719..4cd454c 100644
63170 --- a/include/linux/kallsyms.h
63171 +++ b/include/linux/kallsyms.h
63172 @@ -15,7 +15,8 @@
63173
63174 struct module;
63175
63176 -#ifdef CONFIG_KALLSYMS
63177 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63178 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63179 /* Lookup the address for a symbol. Returns 0 if not found. */
63180 unsigned long kallsyms_lookup_name(const char *name);
63181
63182 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63183 /* Stupid that this does nothing, but I didn't create this mess. */
63184 #define __print_symbol(fmt, addr)
63185 #endif /*CONFIG_KALLSYMS*/
63186 +#else /* when included by kallsyms.c, vsnprintf.c, or
63187 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63188 +extern void __print_symbol(const char *fmt, unsigned long address);
63189 +extern int sprint_backtrace(char *buffer, unsigned long address);
63190 +extern int sprint_symbol(char *buffer, unsigned long address);
63191 +const char *kallsyms_lookup(unsigned long addr,
63192 + unsigned long *symbolsize,
63193 + unsigned long *offset,
63194 + char **modname, char *namebuf);
63195 +#endif
63196
63197 /* This macro allows us to keep printk typechecking */
63198 static __printf(1, 2)
63199 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63200 index c4d2fc1..5df9c19 100644
63201 --- a/include/linux/kgdb.h
63202 +++ b/include/linux/kgdb.h
63203 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63204 extern int kgdb_io_module_registered;
63205
63206 extern atomic_t kgdb_setting_breakpoint;
63207 -extern atomic_t kgdb_cpu_doing_single_step;
63208 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63209
63210 extern struct task_struct *kgdb_usethread;
63211 extern struct task_struct *kgdb_contthread;
63212 @@ -252,7 +252,7 @@ struct kgdb_arch {
63213 void (*disable_hw_break)(struct pt_regs *regs);
63214 void (*remove_all_hw_break)(void);
63215 void (*correct_hw_break)(void);
63216 -};
63217 +} __do_const;
63218
63219 /**
63220 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63221 @@ -277,7 +277,7 @@ struct kgdb_io {
63222 void (*pre_exception) (void);
63223 void (*post_exception) (void);
63224 int is_console;
63225 -};
63226 +} __do_const;
63227
63228 extern struct kgdb_arch arch_kgdb_ops;
63229
63230 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63231 index 0fb48ef..1b680b2 100644
63232 --- a/include/linux/kmod.h
63233 +++ b/include/linux/kmod.h
63234 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63235 * usually useless though. */
63236 extern __printf(2, 3)
63237 int __request_module(bool wait, const char *name, ...);
63238 +extern __printf(3, 4)
63239 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63240 #define request_module(mod...) __request_module(true, mod)
63241 #define request_module_nowait(mod...) __request_module(false, mod)
63242 #define try_then_request_module(x, mod...) \
63243 diff --git a/include/linux/kref.h b/include/linux/kref.h
63244 index 9c07dce..a92fa71 100644
63245 --- a/include/linux/kref.h
63246 +++ b/include/linux/kref.h
63247 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
63248 static inline int kref_sub(struct kref *kref, unsigned int count,
63249 void (*release)(struct kref *kref))
63250 {
63251 - WARN_ON(release == NULL);
63252 + BUG_ON(release == NULL);
63253
63254 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63255 release(kref);
63256 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63257 index 4c4e83d..5f16617 100644
63258 --- a/include/linux/kvm_host.h
63259 +++ b/include/linux/kvm_host.h
63260 @@ -326,7 +326,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63261 void vcpu_load(struct kvm_vcpu *vcpu);
63262 void vcpu_put(struct kvm_vcpu *vcpu);
63263
63264 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63265 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63266 struct module *module);
63267 void kvm_exit(void);
63268
63269 @@ -416,20 +416,20 @@ void kvm_get_pfn(pfn_t pfn);
63270 int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset,
63271 int len);
63272 int kvm_read_guest_atomic(struct kvm *kvm, gpa_t gpa, void *data,
63273 - unsigned long len);
63274 -int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len);
63275 + unsigned long len) __size_overflow(4);
63276 +int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len) __size_overflow(2,4);
63277 int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
63278 - void *data, unsigned long len);
63279 + void *data, unsigned long len) __size_overflow(4);
63280 int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data,
63281 int offset, int len);
63282 int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data,
63283 - unsigned long len);
63284 + unsigned long len) __size_overflow(2,4);
63285 int kvm_write_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
63286 - void *data, unsigned long len);
63287 + void *data, unsigned long len) __size_overflow(4);
63288 int kvm_gfn_to_hva_cache_init(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
63289 gpa_t gpa);
63290 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len);
63291 -int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len);
63292 +int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len) __size_overflow(2,3);
63293 struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
63294 int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn);
63295 unsigned long kvm_host_page_size(struct kvm *kvm, gfn_t gfn);
63296 @@ -485,7 +485,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63297 struct kvm_guest_debug *dbg);
63298 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63299
63300 -int kvm_arch_init(void *opaque);
63301 +int kvm_arch_init(const void *opaque);
63302 void kvm_arch_exit(void);
63303
63304 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63305 @@ -727,7 +727,7 @@ int kvm_setup_default_irq_routing(struct kvm *kvm);
63306 int kvm_set_irq_routing(struct kvm *kvm,
63307 const struct kvm_irq_routing_entry *entries,
63308 unsigned nr,
63309 - unsigned flags);
63310 + unsigned flags) __size_overflow(3);
63311 void kvm_free_irq_routing(struct kvm *kvm);
63312
63313 #else
63314 diff --git a/include/linux/libata.h b/include/linux/libata.h
63315 index cafc09a..d7e7829 100644
63316 --- a/include/linux/libata.h
63317 +++ b/include/linux/libata.h
63318 @@ -909,7 +909,7 @@ struct ata_port_operations {
63319 * fields must be pointers.
63320 */
63321 const struct ata_port_operations *inherits;
63322 -};
63323 +} __do_const;
63324
63325 struct ata_port_info {
63326 unsigned long flags;
63327 diff --git a/include/linux/mca.h b/include/linux/mca.h
63328 index 3797270..7765ede 100644
63329 --- a/include/linux/mca.h
63330 +++ b/include/linux/mca.h
63331 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
63332 int region);
63333 void * (*mca_transform_memory)(struct mca_device *,
63334 void *memory);
63335 -};
63336 +} __no_const;
63337
63338 struct mca_bus {
63339 u64 default_dma_mask;
63340 diff --git a/include/linux/memory.h b/include/linux/memory.h
63341 index 1ac7f6e..a5794d0 100644
63342 --- a/include/linux/memory.h
63343 +++ b/include/linux/memory.h
63344 @@ -143,7 +143,7 @@ struct memory_accessor {
63345 size_t count);
63346 ssize_t (*write)(struct memory_accessor *, const char *buf,
63347 off_t offset, size_t count);
63348 -};
63349 +} __no_const;
63350
63351 /*
63352 * Kernel text modification mutex, used for code patching. Users of this lock
63353 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63354 index 9970337..9444122 100644
63355 --- a/include/linux/mfd/abx500.h
63356 +++ b/include/linux/mfd/abx500.h
63357 @@ -188,6 +188,7 @@ struct abx500_ops {
63358 int (*event_registers_startup_state_get) (struct device *, u8 *);
63359 int (*startup_irq_enabled) (struct device *, unsigned int);
63360 };
63361 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63362
63363 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63364 void abx500_remove_ops(struct device *dev);
63365 diff --git a/include/linux/mm.h b/include/linux/mm.h
63366 index 17b27cd..baea141 100644
63367 --- a/include/linux/mm.h
63368 +++ b/include/linux/mm.h
63369 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
63370
63371 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63372 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63373 +
63374 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63375 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63376 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63377 +#else
63378 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63379 +#endif
63380 +
63381 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63382 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63383
63384 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
63385 int set_page_dirty_lock(struct page *page);
63386 int clear_page_dirty_for_io(struct page *page);
63387
63388 -/* Is the vma a continuation of the stack vma above it? */
63389 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63390 -{
63391 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63392 -}
63393 -
63394 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63395 - unsigned long addr)
63396 -{
63397 - return (vma->vm_flags & VM_GROWSDOWN) &&
63398 - (vma->vm_start == addr) &&
63399 - !vma_growsdown(vma->vm_prev, addr);
63400 -}
63401 -
63402 -/* Is the vma a continuation of the stack vma below it? */
63403 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63404 -{
63405 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63406 -}
63407 -
63408 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63409 - unsigned long addr)
63410 -{
63411 - return (vma->vm_flags & VM_GROWSUP) &&
63412 - (vma->vm_end == addr) &&
63413 - !vma_growsup(vma->vm_next, addr);
63414 -}
63415 -
63416 extern unsigned long move_page_tables(struct vm_area_struct *vma,
63417 unsigned long old_addr, struct vm_area_struct *new_vma,
63418 unsigned long new_addr, unsigned long len);
63419 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
63420 }
63421 #endif
63422
63423 +#ifdef CONFIG_MMU
63424 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63425 +#else
63426 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63427 +{
63428 + return __pgprot(0);
63429 +}
63430 +#endif
63431 +
63432 int vma_wants_writenotify(struct vm_area_struct *vma);
63433
63434 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63435 @@ -1152,8 +1140,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63436 {
63437 return 0;
63438 }
63439 +
63440 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63441 + unsigned long address)
63442 +{
63443 + return 0;
63444 +}
63445 #else
63446 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63447 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63448 #endif
63449
63450 #ifdef __PAGETABLE_PMD_FOLDED
63451 @@ -1162,8 +1157,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63452 {
63453 return 0;
63454 }
63455 +
63456 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63457 + unsigned long address)
63458 +{
63459 + return 0;
63460 +}
63461 #else
63462 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63463 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63464 #endif
63465
63466 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63467 @@ -1181,11 +1183,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63468 NULL: pud_offset(pgd, address);
63469 }
63470
63471 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63472 +{
63473 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63474 + NULL: pud_offset(pgd, address);
63475 +}
63476 +
63477 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63478 {
63479 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63480 NULL: pmd_offset(pud, address);
63481 }
63482 +
63483 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63484 +{
63485 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63486 + NULL: pmd_offset(pud, address);
63487 +}
63488 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63489
63490 #if USE_SPLIT_PTLOCKS
63491 @@ -1409,6 +1423,7 @@ out:
63492 }
63493
63494 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63495 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63496
63497 extern unsigned long do_brk(unsigned long, unsigned long);
63498
63499 @@ -1466,6 +1481,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63500 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63501 struct vm_area_struct **pprev);
63502
63503 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63504 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63505 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63506 +
63507 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63508 NULL if none. Assume start_addr < end_addr. */
63509 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63510 @@ -1494,15 +1513,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63511 return vma;
63512 }
63513
63514 -#ifdef CONFIG_MMU
63515 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63516 -#else
63517 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63518 -{
63519 - return __pgprot(0);
63520 -}
63521 -#endif
63522 -
63523 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63524 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63525 unsigned long pfn, unsigned long size, pgprot_t);
63526 @@ -1606,7 +1616,7 @@ extern int unpoison_memory(unsigned long pfn);
63527 extern int sysctl_memory_failure_early_kill;
63528 extern int sysctl_memory_failure_recovery;
63529 extern void shake_page(struct page *p, int access);
63530 -extern atomic_long_t mce_bad_pages;
63531 +extern atomic_long_unchecked_t mce_bad_pages;
63532 extern int soft_offline_page(struct page *page, int flags);
63533
63534 extern void dump_page(struct page *page);
63535 @@ -1637,5 +1647,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63536 static inline bool page_is_guard(struct page *page) { return false; }
63537 #endif /* CONFIG_DEBUG_PAGEALLOC */
63538
63539 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63540 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63541 +#else
63542 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63543 +#endif
63544 +
63545 #endif /* __KERNEL__ */
63546 #endif /* _LINUX_MM_H */
63547 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63548 index 3cc3062..efeaeb7 100644
63549 --- a/include/linux/mm_types.h
63550 +++ b/include/linux/mm_types.h
63551 @@ -252,6 +252,8 @@ struct vm_area_struct {
63552 #ifdef CONFIG_NUMA
63553 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63554 #endif
63555 +
63556 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63557 };
63558
63559 struct core_thread {
63560 @@ -326,7 +328,7 @@ struct mm_struct {
63561 unsigned long def_flags;
63562 unsigned long nr_ptes; /* Page table pages */
63563 unsigned long start_code, end_code, start_data, end_data;
63564 - unsigned long start_brk, brk, start_stack;
63565 + unsigned long brk_gap, start_brk, brk, start_stack;
63566 unsigned long arg_start, arg_end, env_start, env_end;
63567
63568 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63569 @@ -388,6 +390,24 @@ struct mm_struct {
63570 #ifdef CONFIG_CPUMASK_OFFSTACK
63571 struct cpumask cpumask_allocation;
63572 #endif
63573 +
63574 +#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)
63575 + unsigned long pax_flags;
63576 +#endif
63577 +
63578 +#ifdef CONFIG_PAX_DLRESOLVE
63579 + unsigned long call_dl_resolve;
63580 +#endif
63581 +
63582 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63583 + unsigned long call_syscall;
63584 +#endif
63585 +
63586 +#ifdef CONFIG_PAX_ASLR
63587 + unsigned long delta_mmap; /* randomized offset */
63588 + unsigned long delta_stack; /* randomized offset */
63589 +#endif
63590 +
63591 };
63592
63593 static inline void mm_init_cpumask(struct mm_struct *mm)
63594 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63595 index 1d1b1e1..2a13c78 100644
63596 --- a/include/linux/mmu_notifier.h
63597 +++ b/include/linux/mmu_notifier.h
63598 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63599 */
63600 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63601 ({ \
63602 - pte_t __pte; \
63603 + pte_t ___pte; \
63604 struct vm_area_struct *___vma = __vma; \
63605 unsigned long ___address = __address; \
63606 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63607 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63608 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63609 - __pte; \
63610 + ___pte; \
63611 })
63612
63613 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63614 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63615 index 650ba2f..af0a58c 100644
63616 --- a/include/linux/mmzone.h
63617 +++ b/include/linux/mmzone.h
63618 @@ -379,7 +379,7 @@ struct zone {
63619 unsigned long flags; /* zone flags, see below */
63620
63621 /* Zone statistics */
63622 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63623 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63624
63625 /*
63626 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63627 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63628 index 83ac071..2656e0e 100644
63629 --- a/include/linux/mod_devicetable.h
63630 +++ b/include/linux/mod_devicetable.h
63631 @@ -12,7 +12,7 @@
63632 typedef unsigned long kernel_ulong_t;
63633 #endif
63634
63635 -#define PCI_ANY_ID (~0)
63636 +#define PCI_ANY_ID ((__u16)~0)
63637
63638 struct pci_device_id {
63639 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63640 @@ -131,7 +131,7 @@ struct usb_device_id {
63641 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
63642 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63643
63644 -#define HID_ANY_ID (~0)
63645 +#define HID_ANY_ID (~0U)
63646
63647 struct hid_device_id {
63648 __u16 bus;
63649 diff --git a/include/linux/module.h b/include/linux/module.h
63650 index 4598bf0..e069d7f 100644
63651 --- a/include/linux/module.h
63652 +++ b/include/linux/module.h
63653 @@ -17,6 +17,7 @@
63654 #include <linux/moduleparam.h>
63655 #include <linux/tracepoint.h>
63656 #include <linux/export.h>
63657 +#include <linux/fs.h>
63658
63659 #include <linux/percpu.h>
63660 #include <asm/module.h>
63661 @@ -275,19 +276,16 @@ struct module
63662 int (*init)(void);
63663
63664 /* If this is non-NULL, vfree after init() returns */
63665 - void *module_init;
63666 + void *module_init_rx, *module_init_rw;
63667
63668 /* Here is the actual code + data, vfree'd on unload. */
63669 - void *module_core;
63670 + void *module_core_rx, *module_core_rw;
63671
63672 /* Here are the sizes of the init and core sections */
63673 - unsigned int init_size, core_size;
63674 + unsigned int init_size_rw, core_size_rw;
63675
63676 /* The size of the executable code in each section. */
63677 - unsigned int init_text_size, core_text_size;
63678 -
63679 - /* Size of RO sections of the module (text+rodata) */
63680 - unsigned int init_ro_size, core_ro_size;
63681 + unsigned int init_size_rx, core_size_rx;
63682
63683 /* Arch-specific module values */
63684 struct mod_arch_specific arch;
63685 @@ -343,6 +341,10 @@ struct module
63686 #ifdef CONFIG_EVENT_TRACING
63687 struct ftrace_event_call **trace_events;
63688 unsigned int num_trace_events;
63689 + struct file_operations trace_id;
63690 + struct file_operations trace_enable;
63691 + struct file_operations trace_format;
63692 + struct file_operations trace_filter;
63693 #endif
63694 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63695 unsigned int num_ftrace_callsites;
63696 @@ -390,16 +392,46 @@ bool is_module_address(unsigned long addr);
63697 bool is_module_percpu_address(unsigned long addr);
63698 bool is_module_text_address(unsigned long addr);
63699
63700 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63701 +{
63702 +
63703 +#ifdef CONFIG_PAX_KERNEXEC
63704 + if (ktla_ktva(addr) >= (unsigned long)start &&
63705 + ktla_ktva(addr) < (unsigned long)start + size)
63706 + return 1;
63707 +#endif
63708 +
63709 + return ((void *)addr >= start && (void *)addr < start + size);
63710 +}
63711 +
63712 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63713 +{
63714 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63715 +}
63716 +
63717 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63718 +{
63719 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63720 +}
63721 +
63722 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63723 +{
63724 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63725 +}
63726 +
63727 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63728 +{
63729 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63730 +}
63731 +
63732 static inline int within_module_core(unsigned long addr, struct module *mod)
63733 {
63734 - return (unsigned long)mod->module_core <= addr &&
63735 - addr < (unsigned long)mod->module_core + mod->core_size;
63736 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63737 }
63738
63739 static inline int within_module_init(unsigned long addr, struct module *mod)
63740 {
63741 - return (unsigned long)mod->module_init <= addr &&
63742 - addr < (unsigned long)mod->module_init + mod->init_size;
63743 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63744 }
63745
63746 /* Search for module by name: must hold module_mutex. */
63747 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63748 index b2be02e..72d2f78 100644
63749 --- a/include/linux/moduleloader.h
63750 +++ b/include/linux/moduleloader.h
63751 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63752
63753 /* Allocator used for allocating struct module, core sections and init
63754 sections. Returns NULL on failure. */
63755 -void *module_alloc(unsigned long size);
63756 +void *module_alloc(unsigned long size) __size_overflow(1);
63757 +
63758 +#ifdef CONFIG_PAX_KERNEXEC
63759 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63760 +#else
63761 +#define module_alloc_exec(x) module_alloc(x)
63762 +#endif
63763
63764 /* Free memory returned from module_alloc. */
63765 void module_free(struct module *mod, void *module_region);
63766
63767 +#ifdef CONFIG_PAX_KERNEXEC
63768 +void module_free_exec(struct module *mod, void *module_region);
63769 +#else
63770 +#define module_free_exec(x, y) module_free((x), (y))
63771 +#endif
63772 +
63773 /* Apply the given relocation to the (simplified) ELF. Return -error
63774 or 0. */
63775 int apply_relocate(Elf_Shdr *sechdrs,
63776 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63777 index c47f4d6..23f9bdb 100644
63778 --- a/include/linux/moduleparam.h
63779 +++ b/include/linux/moduleparam.h
63780 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
63781 * @len is usually just sizeof(string).
63782 */
63783 #define module_param_string(name, string, len, perm) \
63784 - static const struct kparam_string __param_string_##name \
63785 + static const struct kparam_string __param_string_##name __used \
63786 = { len, string }; \
63787 __module_param_call(MODULE_PARAM_PREFIX, name, \
63788 &param_ops_string, \
63789 @@ -396,7 +396,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63790 */
63791 #define module_param_array_named(name, array, type, nump, perm) \
63792 param_check_##type(name, &(array)[0]); \
63793 - static const struct kparam_array __param_arr_##name \
63794 + static const struct kparam_array __param_arr_##name __used \
63795 = { .max = ARRAY_SIZE(array), .num = nump, \
63796 .ops = &param_ops_##type, \
63797 .elemsize = sizeof(array[0]), .elem = array }; \
63798 diff --git a/include/linux/namei.h b/include/linux/namei.h
63799 index ffc0213..2c1f2cb 100644
63800 --- a/include/linux/namei.h
63801 +++ b/include/linux/namei.h
63802 @@ -24,7 +24,7 @@ struct nameidata {
63803 unsigned seq;
63804 int last_type;
63805 unsigned depth;
63806 - char *saved_names[MAX_NESTED_LINKS + 1];
63807 + const char *saved_names[MAX_NESTED_LINKS + 1];
63808
63809 /* Intent data */
63810 union {
63811 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63812 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63813 extern void unlock_rename(struct dentry *, struct dentry *);
63814
63815 -static inline void nd_set_link(struct nameidata *nd, char *path)
63816 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63817 {
63818 nd->saved_names[nd->depth] = path;
63819 }
63820
63821 -static inline char *nd_get_link(struct nameidata *nd)
63822 +static inline const char *nd_get_link(const struct nameidata *nd)
63823 {
63824 return nd->saved_names[nd->depth];
63825 }
63826 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63827 index 7e472b7..212d381 100644
63828 --- a/include/linux/netdevice.h
63829 +++ b/include/linux/netdevice.h
63830 @@ -1002,6 +1002,7 @@ struct net_device_ops {
63831 int (*ndo_neigh_construct)(struct neighbour *n);
63832 void (*ndo_neigh_destroy)(struct neighbour *n);
63833 };
63834 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63835
63836 /*
63837 * The DEVICE structure.
63838 @@ -1063,7 +1064,7 @@ struct net_device {
63839 int iflink;
63840
63841 struct net_device_stats stats;
63842 - atomic_long_t rx_dropped; /* dropped packets by core network
63843 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63844 * Do not use this in drivers.
63845 */
63846
63847 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63848 new file mode 100644
63849 index 0000000..33f4af8
63850 --- /dev/null
63851 +++ b/include/linux/netfilter/xt_gradm.h
63852 @@ -0,0 +1,9 @@
63853 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63854 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63855 +
63856 +struct xt_gradm_mtinfo {
63857 + __u16 flags;
63858 + __u16 invflags;
63859 +};
63860 +
63861 +#endif
63862 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63863 index c65a18a..0c05f3a 100644
63864 --- a/include/linux/of_pdt.h
63865 +++ b/include/linux/of_pdt.h
63866 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63867
63868 /* return 0 on success; fill in 'len' with number of bytes in path */
63869 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63870 -};
63871 +} __no_const;
63872
63873 extern void *prom_early_alloc(unsigned long size);
63874
63875 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63876 index a4c5624..2dabfb7 100644
63877 --- a/include/linux/oprofile.h
63878 +++ b/include/linux/oprofile.h
63879 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63880 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63881 char const * name, ulong * val);
63882
63883 -/** Create a file for read-only access to an atomic_t. */
63884 +/** Create a file for read-only access to an atomic_unchecked_t. */
63885 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63886 - char const * name, atomic_t * val);
63887 + char const * name, atomic_unchecked_t * val);
63888
63889 /** create a directory */
63890 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63891 @@ -163,7 +163,7 @@ ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t co
63892 * Read an ASCII string for a number from a userspace buffer and fill *val on success.
63893 * Returns 0 on success, < 0 on error.
63894 */
63895 -int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count);
63896 +int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count) __size_overflow(3);
63897
63898 /** lock for read/write safety */
63899 extern raw_spinlock_t oprofilefs_lock;
63900 diff --git a/include/linux/padata.h b/include/linux/padata.h
63901 index 4633b2f..988bc08 100644
63902 --- a/include/linux/padata.h
63903 +++ b/include/linux/padata.h
63904 @@ -129,7 +129,7 @@ struct parallel_data {
63905 struct padata_instance *pinst;
63906 struct padata_parallel_queue __percpu *pqueue;
63907 struct padata_serial_queue __percpu *squeue;
63908 - atomic_t seq_nr;
63909 + atomic_unchecked_t seq_nr;
63910 atomic_t reorder_objects;
63911 atomic_t refcnt;
63912 unsigned int max_seq_nr;
63913 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63914 index abb2776..d8b8e15 100644
63915 --- a/include/linux/perf_event.h
63916 +++ b/include/linux/perf_event.h
63917 @@ -750,8 +750,8 @@ struct perf_event {
63918
63919 enum perf_event_active_state state;
63920 unsigned int attach_state;
63921 - local64_t count;
63922 - atomic64_t child_count;
63923 + local64_t count; /* PaX: fix it one day */
63924 + atomic64_unchecked_t child_count;
63925
63926 /*
63927 * These are the total time in nanoseconds that the event
63928 @@ -802,8 +802,8 @@ struct perf_event {
63929 * These accumulate total time (in nanoseconds) that children
63930 * events have been enabled and running, respectively.
63931 */
63932 - atomic64_t child_total_time_enabled;
63933 - atomic64_t child_total_time_running;
63934 + atomic64_unchecked_t child_total_time_enabled;
63935 + atomic64_unchecked_t child_total_time_running;
63936
63937 /*
63938 * Protect attach/detach and child_list:
63939 diff --git a/include/linux/personality.h b/include/linux/personality.h
63940 index 8fc7dd1a..c19d89e 100644
63941 --- a/include/linux/personality.h
63942 +++ b/include/linux/personality.h
63943 @@ -44,6 +44,7 @@ enum {
63944 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63945 ADDR_NO_RANDOMIZE | \
63946 ADDR_COMPAT_LAYOUT | \
63947 + ADDR_LIMIT_3GB | \
63948 MMAP_PAGE_ZERO)
63949
63950 /*
63951 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63952 index 0072a53..c5dcca5 100644
63953 --- a/include/linux/pipe_fs_i.h
63954 +++ b/include/linux/pipe_fs_i.h
63955 @@ -47,9 +47,9 @@ struct pipe_buffer {
63956 struct pipe_inode_info {
63957 wait_queue_head_t wait;
63958 unsigned int nrbufs, curbuf, buffers;
63959 - unsigned int readers;
63960 - unsigned int writers;
63961 - unsigned int waiting_writers;
63962 + atomic_t readers;
63963 + atomic_t writers;
63964 + atomic_t waiting_writers;
63965 unsigned int r_counter;
63966 unsigned int w_counter;
63967 struct page *tmp_page;
63968 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63969 index 609daae..5392427 100644
63970 --- a/include/linux/pm_runtime.h
63971 +++ b/include/linux/pm_runtime.h
63972 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63973
63974 static inline void pm_runtime_mark_last_busy(struct device *dev)
63975 {
63976 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63977 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63978 }
63979
63980 #else /* !CONFIG_PM_RUNTIME */
63981 diff --git a/include/linux/poison.h b/include/linux/poison.h
63982 index 2110a81..13a11bb 100644
63983 --- a/include/linux/poison.h
63984 +++ b/include/linux/poison.h
63985 @@ -19,8 +19,8 @@
63986 * under normal circumstances, used to verify that nobody uses
63987 * non-initialized list entries.
63988 */
63989 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63990 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63991 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63992 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63993
63994 /********** include/linux/timer.h **********/
63995 /*
63996 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63997 index 58969b2..ead129b 100644
63998 --- a/include/linux/preempt.h
63999 +++ b/include/linux/preempt.h
64000 @@ -123,7 +123,7 @@ struct preempt_ops {
64001 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
64002 void (*sched_out)(struct preempt_notifier *notifier,
64003 struct task_struct *next);
64004 -};
64005 +} __no_const;
64006
64007 /**
64008 * preempt_notifier - key for installing preemption notifiers
64009 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
64010 index 85c5073..51fac8b 100644
64011 --- a/include/linux/proc_fs.h
64012 +++ b/include/linux/proc_fs.h
64013 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
64014 return proc_create_data(name, mode, parent, proc_fops, NULL);
64015 }
64016
64017 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64018 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64019 +{
64020 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64021 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64022 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64023 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64024 +#else
64025 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64026 +#endif
64027 +}
64028 +
64029 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64030 umode_t mode, struct proc_dir_entry *base,
64031 read_proc_t *read_proc, void * data)
64032 @@ -258,7 +270,7 @@ union proc_op {
64033 int (*proc_show)(struct seq_file *m,
64034 struct pid_namespace *ns, struct pid *pid,
64035 struct task_struct *task);
64036 -};
64037 +} __no_const;
64038
64039 struct ctl_table_header;
64040 struct ctl_table;
64041 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
64042 index c2f1f6a..6fdb196 100644
64043 --- a/include/linux/ptrace.h
64044 +++ b/include/linux/ptrace.h
64045 @@ -199,9 +199,10 @@ static inline void ptrace_event(int event, unsigned long message)
64046 if (unlikely(ptrace_event_enabled(current, event))) {
64047 current->ptrace_message = message;
64048 ptrace_notify((event << 8) | SIGTRAP);
64049 - } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
64050 + } else if (event == PTRACE_EVENT_EXEC) {
64051 /* legacy EXEC report via SIGTRAP */
64052 - send_sig(SIGTRAP, current, 0);
64053 + if ((current->ptrace & (PT_PTRACED|PT_SEIZED)) == PT_PTRACED)
64054 + send_sig(SIGTRAP, current, 0);
64055 }
64056 }
64057
64058 diff --git a/include/linux/random.h b/include/linux/random.h
64059 index 8f74538..02a1012 100644
64060 --- a/include/linux/random.h
64061 +++ b/include/linux/random.h
64062 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
64063
64064 u32 prandom32(struct rnd_state *);
64065
64066 +static inline unsigned long pax_get_random_long(void)
64067 +{
64068 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64069 +}
64070 +
64071 /*
64072 * Handle minimum values for seeds
64073 */
64074 static inline u32 __seed(u32 x, u32 m)
64075 {
64076 - return (x < m) ? x + m : x;
64077 + return (x <= m) ? x + m + 1 : x;
64078 }
64079
64080 /**
64081 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64082 index e0879a7..a12f962 100644
64083 --- a/include/linux/reboot.h
64084 +++ b/include/linux/reboot.h
64085 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64086 * Architecture-specific implementations of sys_reboot commands.
64087 */
64088
64089 -extern void machine_restart(char *cmd);
64090 -extern void machine_halt(void);
64091 -extern void machine_power_off(void);
64092 +extern void machine_restart(char *cmd) __noreturn;
64093 +extern void machine_halt(void) __noreturn;
64094 +extern void machine_power_off(void) __noreturn;
64095
64096 extern void machine_shutdown(void);
64097 struct pt_regs;
64098 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64099 */
64100
64101 extern void kernel_restart_prepare(char *cmd);
64102 -extern void kernel_restart(char *cmd);
64103 -extern void kernel_halt(void);
64104 -extern void kernel_power_off(void);
64105 +extern void kernel_restart(char *cmd) __noreturn;
64106 +extern void kernel_halt(void) __noreturn;
64107 +extern void kernel_power_off(void) __noreturn;
64108
64109 extern int C_A_D; /* for sysctl */
64110 void ctrl_alt_del(void);
64111 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64112 * Emergency restart, callable from an interrupt handler.
64113 */
64114
64115 -extern void emergency_restart(void);
64116 +extern void emergency_restart(void) __noreturn;
64117 #include <asm/emergency-restart.h>
64118
64119 #endif
64120 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
64121 index 2213ddc..650212a 100644
64122 --- a/include/linux/reiserfs_fs.h
64123 +++ b/include/linux/reiserfs_fs.h
64124 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64125 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64126
64127 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64128 -#define get_generation(s) atomic_read (&fs_generation(s))
64129 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64130 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64131 #define __fs_changed(gen,s) (gen != get_generation (s))
64132 #define fs_changed(gen,s) \
64133 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
64134 index 8c9e85c..1698e9a 100644
64135 --- a/include/linux/reiserfs_fs_sb.h
64136 +++ b/include/linux/reiserfs_fs_sb.h
64137 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
64138 /* Comment? -Hans */
64139 wait_queue_head_t s_wait;
64140 /* To be obsoleted soon by per buffer seals.. -Hans */
64141 - atomic_t s_generation_counter; // increased by one every time the
64142 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64143 // tree gets re-balanced
64144 unsigned long s_properties; /* File system properties. Currently holds
64145 on-disk FS format */
64146 diff --git a/include/linux/relay.h b/include/linux/relay.h
64147 index a822fd7..62b70f6 100644
64148 --- a/include/linux/relay.h
64149 +++ b/include/linux/relay.h
64150 @@ -159,7 +159,7 @@ struct rchan_callbacks
64151 * The callback should return 0 if successful, negative if not.
64152 */
64153 int (*remove_buf_file)(struct dentry *dentry);
64154 -};
64155 +} __no_const;
64156
64157 /*
64158 * CONFIG_RELAY kernel API, kernel/relay.c
64159 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64160 index c6c6084..5bf1212 100644
64161 --- a/include/linux/rfkill.h
64162 +++ b/include/linux/rfkill.h
64163 @@ -147,6 +147,7 @@ struct rfkill_ops {
64164 void (*query)(struct rfkill *rfkill, void *data);
64165 int (*set_block)(void *data, bool blocked);
64166 };
64167 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64168
64169 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64170 /**
64171 diff --git a/include/linux/rio.h b/include/linux/rio.h
64172 index 4d50611..c6858a2 100644
64173 --- a/include/linux/rio.h
64174 +++ b/include/linux/rio.h
64175 @@ -315,7 +315,7 @@ struct rio_ops {
64176 int mbox, void *buffer, size_t len);
64177 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64178 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64179 -};
64180 +} __no_const;
64181
64182 #define RIO_RESOURCE_MEM 0x00000100
64183 #define RIO_RESOURCE_DOORBELL 0x00000200
64184 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64185 index 1cdd62a..e399f0d 100644
64186 --- a/include/linux/rmap.h
64187 +++ b/include/linux/rmap.h
64188 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64189 void anon_vma_init(void); /* create anon_vma_cachep */
64190 int anon_vma_prepare(struct vm_area_struct *);
64191 void unlink_anon_vmas(struct vm_area_struct *);
64192 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64193 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64194 void anon_vma_moveto_tail(struct vm_area_struct *);
64195 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64196 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64197 void __anon_vma_link(struct vm_area_struct *);
64198
64199 static inline void anon_vma_merge(struct vm_area_struct *vma,
64200 diff --git a/include/linux/sched.h b/include/linux/sched.h
64201 index 0657368..765f70f 100644
64202 --- a/include/linux/sched.h
64203 +++ b/include/linux/sched.h
64204 @@ -101,6 +101,7 @@ struct bio_list;
64205 struct fs_struct;
64206 struct perf_event_context;
64207 struct blk_plug;
64208 +struct linux_binprm;
64209
64210 /*
64211 * List of flags we want to share for kernel threads,
64212 @@ -382,10 +383,13 @@ struct user_namespace;
64213 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64214
64215 extern int sysctl_max_map_count;
64216 +extern unsigned long sysctl_heap_stack_gap;
64217
64218 #include <linux/aio.h>
64219
64220 #ifdef CONFIG_MMU
64221 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64222 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64223 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64224 extern unsigned long
64225 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64226 @@ -631,6 +635,17 @@ struct signal_struct {
64227 #ifdef CONFIG_TASKSTATS
64228 struct taskstats *stats;
64229 #endif
64230 +
64231 +#ifdef CONFIG_GRKERNSEC
64232 + u32 curr_ip;
64233 + u32 saved_ip;
64234 + u32 gr_saddr;
64235 + u32 gr_daddr;
64236 + u16 gr_sport;
64237 + u16 gr_dport;
64238 + u8 used_accept:1;
64239 +#endif
64240 +
64241 #ifdef CONFIG_AUDIT
64242 unsigned audit_tty;
64243 struct tty_audit_buf *tty_audit_buf;
64244 @@ -714,6 +729,11 @@ struct user_struct {
64245 struct key *session_keyring; /* UID's default session keyring */
64246 #endif
64247
64248 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64249 + unsigned int banned;
64250 + unsigned long ban_expires;
64251 +#endif
64252 +
64253 /* Hash table maintenance information */
64254 struct hlist_node uidhash_node;
64255 uid_t uid;
64256 @@ -1354,8 +1374,8 @@ struct task_struct {
64257 struct list_head thread_group;
64258
64259 struct completion *vfork_done; /* for vfork() */
64260 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64261 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64262 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64263 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64264
64265 cputime_t utime, stime, utimescaled, stimescaled;
64266 cputime_t gtime;
64267 @@ -1371,13 +1391,6 @@ struct task_struct {
64268 struct task_cputime cputime_expires;
64269 struct list_head cpu_timers[3];
64270
64271 -/* process credentials */
64272 - const struct cred __rcu *real_cred; /* objective and real subjective task
64273 - * credentials (COW) */
64274 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64275 - * credentials (COW) */
64276 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64277 -
64278 char comm[TASK_COMM_LEN]; /* executable name excluding path
64279 - access with [gs]et_task_comm (which lock
64280 it with task_lock())
64281 @@ -1394,8 +1407,16 @@ struct task_struct {
64282 #endif
64283 /* CPU-specific state of this task */
64284 struct thread_struct thread;
64285 +/* thread_info moved to task_struct */
64286 +#ifdef CONFIG_X86
64287 + struct thread_info tinfo;
64288 +#endif
64289 /* filesystem information */
64290 struct fs_struct *fs;
64291 +
64292 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64293 + * credentials (COW) */
64294 +
64295 /* open file information */
64296 struct files_struct *files;
64297 /* namespaces */
64298 @@ -1442,6 +1463,11 @@ struct task_struct {
64299 struct rt_mutex_waiter *pi_blocked_on;
64300 #endif
64301
64302 +/* process credentials */
64303 + const struct cred __rcu *real_cred; /* objective and real subjective task
64304 + * credentials (COW) */
64305 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64306 +
64307 #ifdef CONFIG_DEBUG_MUTEXES
64308 /* mutex deadlock detection */
64309 struct mutex_waiter *blocked_on;
64310 @@ -1558,6 +1584,27 @@ struct task_struct {
64311 unsigned long default_timer_slack_ns;
64312
64313 struct list_head *scm_work_list;
64314 +
64315 +#ifdef CONFIG_GRKERNSEC
64316 + /* grsecurity */
64317 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64318 + u64 exec_id;
64319 +#endif
64320 +#ifdef CONFIG_GRKERNSEC_SETXID
64321 + const struct cred *delayed_cred;
64322 +#endif
64323 + struct dentry *gr_chroot_dentry;
64324 + struct acl_subject_label *acl;
64325 + struct acl_role_label *role;
64326 + struct file *exec_file;
64327 + u16 acl_role_id;
64328 + /* is this the task that authenticated to the special role */
64329 + u8 acl_sp_role;
64330 + u8 is_writable;
64331 + u8 brute;
64332 + u8 gr_is_chrooted;
64333 +#endif
64334 +
64335 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
64336 /* Index of current stored address in ret_stack */
64337 int curr_ret_stack;
64338 @@ -1592,6 +1639,51 @@ struct task_struct {
64339 #endif
64340 };
64341
64342 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64343 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64344 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64345 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64346 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64347 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64348 +
64349 +#ifdef CONFIG_PAX_SOFTMODE
64350 +extern int pax_softmode;
64351 +#endif
64352 +
64353 +extern int pax_check_flags(unsigned long *);
64354 +
64355 +/* if tsk != current then task_lock must be held on it */
64356 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64357 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64358 +{
64359 + if (likely(tsk->mm))
64360 + return tsk->mm->pax_flags;
64361 + else
64362 + return 0UL;
64363 +}
64364 +
64365 +/* if tsk != current then task_lock must be held on it */
64366 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64367 +{
64368 + if (likely(tsk->mm)) {
64369 + tsk->mm->pax_flags = flags;
64370 + return 0;
64371 + }
64372 + return -EINVAL;
64373 +}
64374 +#endif
64375 +
64376 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64377 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64378 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64379 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64380 +#endif
64381 +
64382 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64383 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64384 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64385 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
64386 +
64387 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64388 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64389
64390 @@ -2104,7 +2196,9 @@ void yield(void);
64391 extern struct exec_domain default_exec_domain;
64392
64393 union thread_union {
64394 +#ifndef CONFIG_X86
64395 struct thread_info thread_info;
64396 +#endif
64397 unsigned long stack[THREAD_SIZE/sizeof(long)];
64398 };
64399
64400 @@ -2137,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
64401 */
64402
64403 extern struct task_struct *find_task_by_vpid(pid_t nr);
64404 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64405 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64406 struct pid_namespace *ns);
64407
64408 @@ -2280,7 +2375,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64409 extern void exit_itimers(struct signal_struct *);
64410 extern void flush_itimer_signals(void);
64411
64412 -extern void do_group_exit(int);
64413 +extern __noreturn void do_group_exit(int);
64414
64415 extern void daemonize(const char *, ...);
64416 extern int allow_signal(int);
64417 @@ -2478,13 +2573,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64418
64419 #endif
64420
64421 -static inline int object_is_on_stack(void *obj)
64422 +static inline int object_starts_on_stack(void *obj)
64423 {
64424 - void *stack = task_stack_page(current);
64425 + const void *stack = task_stack_page(current);
64426
64427 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64428 }
64429
64430 +#ifdef CONFIG_PAX_USERCOPY
64431 +extern int object_is_on_stack(const void *obj, unsigned long len);
64432 +#endif
64433 +
64434 extern void thread_info_cache_init(void);
64435
64436 #ifdef CONFIG_DEBUG_STACK_USAGE
64437 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64438 index 899fbb4..1cb4138 100644
64439 --- a/include/linux/screen_info.h
64440 +++ b/include/linux/screen_info.h
64441 @@ -43,7 +43,8 @@ struct screen_info {
64442 __u16 pages; /* 0x32 */
64443 __u16 vesa_attributes; /* 0x34 */
64444 __u32 capabilities; /* 0x36 */
64445 - __u8 _reserved[6]; /* 0x3a */
64446 + __u16 vesapm_size; /* 0x3a */
64447 + __u8 _reserved[4]; /* 0x3c */
64448 } __attribute__((packed));
64449
64450 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64451 diff --git a/include/linux/security.h b/include/linux/security.h
64452 index 83c18e8..2d98860 100644
64453 --- a/include/linux/security.h
64454 +++ b/include/linux/security.h
64455 @@ -37,6 +37,7 @@
64456 #include <linux/xfrm.h>
64457 #include <linux/slab.h>
64458 #include <linux/xattr.h>
64459 +#include <linux/grsecurity.h>
64460 #include <net/flow.h>
64461
64462 /* Maximum number of letters for an LSM name string */
64463 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64464 index 44f1514..2bbf6c1 100644
64465 --- a/include/linux/seq_file.h
64466 +++ b/include/linux/seq_file.h
64467 @@ -24,6 +24,9 @@ struct seq_file {
64468 struct mutex lock;
64469 const struct seq_operations *op;
64470 int poll_event;
64471 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64472 + u64 exec_id;
64473 +#endif
64474 void *private;
64475 };
64476
64477 @@ -33,6 +36,7 @@ struct seq_operations {
64478 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64479 int (*show) (struct seq_file *m, void *v);
64480 };
64481 +typedef struct seq_operations __no_const seq_operations_no_const;
64482
64483 #define SEQ_SKIP 1
64484
64485 diff --git a/include/linux/shm.h b/include/linux/shm.h
64486 index 92808b8..c28cac4 100644
64487 --- a/include/linux/shm.h
64488 +++ b/include/linux/shm.h
64489 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64490
64491 /* The task created the shm object. NULL if the task is dead. */
64492 struct task_struct *shm_creator;
64493 +#ifdef CONFIG_GRKERNSEC
64494 + time_t shm_createtime;
64495 + pid_t shm_lapid;
64496 +#endif
64497 };
64498
64499 /* shm_mode upper byte flags */
64500 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64501 index 42854ce..3b7d3c8 100644
64502 --- a/include/linux/skbuff.h
64503 +++ b/include/linux/skbuff.h
64504 @@ -655,7 +655,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64505 */
64506 static inline int skb_queue_empty(const struct sk_buff_head *list)
64507 {
64508 - return list->next == (struct sk_buff *)list;
64509 + return list->next == (const struct sk_buff *)list;
64510 }
64511
64512 /**
64513 @@ -668,7 +668,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64514 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64515 const struct sk_buff *skb)
64516 {
64517 - return skb->next == (struct sk_buff *)list;
64518 + return skb->next == (const struct sk_buff *)list;
64519 }
64520
64521 /**
64522 @@ -681,7 +681,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64523 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64524 const struct sk_buff *skb)
64525 {
64526 - return skb->prev == (struct sk_buff *)list;
64527 + return skb->prev == (const struct sk_buff *)list;
64528 }
64529
64530 /**
64531 @@ -1558,7 +1558,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64532 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64533 */
64534 #ifndef NET_SKB_PAD
64535 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64536 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64537 #endif
64538
64539 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64540 diff --git a/include/linux/slab.h b/include/linux/slab.h
64541 index 573c809..07e1f43 100644
64542 --- a/include/linux/slab.h
64543 +++ b/include/linux/slab.h
64544 @@ -11,12 +11,20 @@
64545
64546 #include <linux/gfp.h>
64547 #include <linux/types.h>
64548 +#include <linux/err.h>
64549
64550 /*
64551 * Flags to pass to kmem_cache_create().
64552 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64553 */
64554 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64555 +
64556 +#ifdef CONFIG_PAX_USERCOPY
64557 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64558 +#else
64559 +#define SLAB_USERCOPY 0x00000000UL
64560 +#endif
64561 +
64562 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64563 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64564 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64565 @@ -87,10 +95,13 @@
64566 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64567 * Both make kfree a no-op.
64568 */
64569 -#define ZERO_SIZE_PTR ((void *)16)
64570 +#define ZERO_SIZE_PTR \
64571 +({ \
64572 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64573 + (void *)(-MAX_ERRNO-1L); \
64574 +})
64575
64576 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64577 - (unsigned long)ZERO_SIZE_PTR)
64578 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64579
64580 /*
64581 * struct kmem_cache related prototypes
64582 @@ -156,11 +167,12 @@ unsigned int kmem_cache_size(struct kmem_cache *);
64583 /*
64584 * Common kmalloc functions provided by all allocators
64585 */
64586 -void * __must_check __krealloc(const void *, size_t, gfp_t);
64587 -void * __must_check krealloc(const void *, size_t, gfp_t);
64588 +void * __must_check __krealloc(const void *, size_t, gfp_t) __size_overflow(2);
64589 +void * __must_check krealloc(const void *, size_t, gfp_t) __size_overflow(2);
64590 void kfree(const void *);
64591 void kzfree(const void *);
64592 size_t ksize(const void *);
64593 +void check_object_size(const void *ptr, unsigned long n, bool to);
64594
64595 /*
64596 * Allocator specific definitions. These are mainly used to establish optimized
64597 @@ -287,7 +299,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64598 */
64599 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64600 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64601 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64602 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64603 #define kmalloc_track_caller(size, flags) \
64604 __kmalloc_track_caller(size, flags, _RET_IP_)
64605 #else
64606 @@ -306,7 +318,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64607 */
64608 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64609 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64610 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64611 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64612 #define kmalloc_node_track_caller(size, flags, node) \
64613 __kmalloc_node_track_caller(size, flags, node, \
64614 _RET_IP_)
64615 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64616 index fbd1117..c0bd874 100644
64617 --- a/include/linux/slab_def.h
64618 +++ b/include/linux/slab_def.h
64619 @@ -66,10 +66,10 @@ struct kmem_cache {
64620 unsigned long node_allocs;
64621 unsigned long node_frees;
64622 unsigned long node_overflow;
64623 - atomic_t allochit;
64624 - atomic_t allocmiss;
64625 - atomic_t freehit;
64626 - atomic_t freemiss;
64627 + atomic_unchecked_t allochit;
64628 + atomic_unchecked_t allocmiss;
64629 + atomic_unchecked_t freehit;
64630 + atomic_unchecked_t freemiss;
64631
64632 /*
64633 * If debugging is enabled, then the allocator can add additional
64634 @@ -107,7 +107,7 @@ struct cache_sizes {
64635 extern struct cache_sizes malloc_sizes[];
64636
64637 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64638 -void *__kmalloc(size_t size, gfp_t flags);
64639 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64640
64641 #ifdef CONFIG_TRACING
64642 extern void *kmem_cache_alloc_trace(size_t size,
64643 @@ -125,6 +125,7 @@ static inline size_t slab_buffer_size(struct kmem_cache *cachep)
64644 }
64645 #endif
64646
64647 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64648 static __always_inline void *kmalloc(size_t size, gfp_t flags)
64649 {
64650 struct kmem_cache *cachep;
64651 @@ -160,7 +161,7 @@ found:
64652 }
64653
64654 #ifdef CONFIG_NUMA
64655 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64656 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64657 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64658
64659 #ifdef CONFIG_TRACING
64660 @@ -179,6 +180,7 @@ kmem_cache_alloc_node_trace(size_t size,
64661 }
64662 #endif
64663
64664 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64665 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64666 {
64667 struct kmem_cache *cachep;
64668 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64669 index 0ec00b3..65e7e0e 100644
64670 --- a/include/linux/slob_def.h
64671 +++ b/include/linux/slob_def.h
64672 @@ -9,8 +9,9 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64673 return kmem_cache_alloc_node(cachep, flags, -1);
64674 }
64675
64676 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64677 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64678
64679 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64680 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64681 {
64682 return __kmalloc_node(size, flags, node);
64683 @@ -24,11 +25,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64684 * kmalloc is the normal method of allocating memory
64685 * in the kernel.
64686 */
64687 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64688 static __always_inline void *kmalloc(size_t size, gfp_t flags)
64689 {
64690 return __kmalloc_node(size, flags, -1);
64691 }
64692
64693 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64694 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64695 {
64696 return kmalloc(size, flags);
64697 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64698 index a32bcfd..d26bd6e 100644
64699 --- a/include/linux/slub_def.h
64700 +++ b/include/linux/slub_def.h
64701 @@ -89,7 +89,7 @@ struct kmem_cache {
64702 struct kmem_cache_order_objects max;
64703 struct kmem_cache_order_objects min;
64704 gfp_t allocflags; /* gfp flags to use on each alloc */
64705 - int refcount; /* Refcount for slab cache destroy */
64706 + atomic_t refcount; /* Refcount for slab cache destroy */
64707 void (*ctor)(void *);
64708 int inuse; /* Offset to metadata */
64709 int align; /* Alignment */
64710 @@ -204,6 +204,7 @@ static __always_inline int kmalloc_index(size_t size)
64711 * This ought to end up with a global pointer to the right cache
64712 * in kmalloc_caches.
64713 */
64714 +static __always_inline struct kmem_cache *kmalloc_slab(size_t size) __size_overflow(1);
64715 static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64716 {
64717 int index = kmalloc_index(size);
64718 @@ -215,9 +216,11 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64719 }
64720
64721 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64722 -void *__kmalloc(size_t size, gfp_t flags);
64723 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64724
64725 static __always_inline void *
64726 +kmalloc_order(size_t size, gfp_t flags, unsigned int order) __size_overflow(1);
64727 +static __always_inline void *
64728 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64729 {
64730 void *ret = (void *) __get_free_pages(flags | __GFP_COMP, order);
64731 @@ -256,12 +259,14 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64732 }
64733 #endif
64734
64735 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
64736 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64737 {
64738 unsigned int order = get_order(size);
64739 return kmalloc_order_trace(size, flags, order);
64740 }
64741
64742 +static __always_inline void *kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64743 static __always_inline void *kmalloc(size_t size, gfp_t flags)
64744 {
64745 if (__builtin_constant_p(size)) {
64746 @@ -281,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64747 }
64748
64749 #ifdef CONFIG_NUMA
64750 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64751 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64752 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64753
64754 #ifdef CONFIG_TRACING
64755 @@ -298,6 +303,7 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s,
64756 }
64757 #endif
64758
64759 +static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64760 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64761 {
64762 if (__builtin_constant_p(size) &&
64763 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64764 index de8832d..0147b46 100644
64765 --- a/include/linux/sonet.h
64766 +++ b/include/linux/sonet.h
64767 @@ -61,7 +61,7 @@ struct sonet_stats {
64768 #include <linux/atomic.h>
64769
64770 struct k_sonet_stats {
64771 -#define __HANDLE_ITEM(i) atomic_t i
64772 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64773 __SONET_ITEMS
64774 #undef __HANDLE_ITEM
64775 };
64776 diff --git a/include/linux/stddef.h b/include/linux/stddef.h
64777 index 6a40c76..1747b67 100644
64778 --- a/include/linux/stddef.h
64779 +++ b/include/linux/stddef.h
64780 @@ -3,14 +3,10 @@
64781
64782 #include <linux/compiler.h>
64783
64784 +#ifdef __KERNEL__
64785 +
64786 #undef NULL
64787 -#if defined(__cplusplus)
64788 -#define NULL 0
64789 -#else
64790 #define NULL ((void *)0)
64791 -#endif
64792 -
64793 -#ifdef __KERNEL__
64794
64795 enum {
64796 false = 0,
64797 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64798 index 2c5993a..b0e79f0 100644
64799 --- a/include/linux/sunrpc/clnt.h
64800 +++ b/include/linux/sunrpc/clnt.h
64801 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64802 {
64803 switch (sap->sa_family) {
64804 case AF_INET:
64805 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64806 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64807 case AF_INET6:
64808 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64809 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64810 }
64811 return 0;
64812 }
64813 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64814 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64815 const struct sockaddr *src)
64816 {
64817 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64818 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64819 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64820
64821 dsin->sin_family = ssin->sin_family;
64822 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64823 if (sa->sa_family != AF_INET6)
64824 return 0;
64825
64826 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64827 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64828 }
64829
64830 #endif /* __KERNEL__ */
64831 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64832 index e775689..9e206d9 100644
64833 --- a/include/linux/sunrpc/sched.h
64834 +++ b/include/linux/sunrpc/sched.h
64835 @@ -105,6 +105,7 @@ struct rpc_call_ops {
64836 void (*rpc_call_done)(struct rpc_task *, void *);
64837 void (*rpc_release)(void *);
64838 };
64839 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64840
64841 struct rpc_task_setup {
64842 struct rpc_task *task;
64843 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64844 index c14fe86..393245e 100644
64845 --- a/include/linux/sunrpc/svc_rdma.h
64846 +++ b/include/linux/sunrpc/svc_rdma.h
64847 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64848 extern unsigned int svcrdma_max_requests;
64849 extern unsigned int svcrdma_max_req_size;
64850
64851 -extern atomic_t rdma_stat_recv;
64852 -extern atomic_t rdma_stat_read;
64853 -extern atomic_t rdma_stat_write;
64854 -extern atomic_t rdma_stat_sq_starve;
64855 -extern atomic_t rdma_stat_rq_starve;
64856 -extern atomic_t rdma_stat_rq_poll;
64857 -extern atomic_t rdma_stat_rq_prod;
64858 -extern atomic_t rdma_stat_sq_poll;
64859 -extern atomic_t rdma_stat_sq_prod;
64860 +extern atomic_unchecked_t rdma_stat_recv;
64861 +extern atomic_unchecked_t rdma_stat_read;
64862 +extern atomic_unchecked_t rdma_stat_write;
64863 +extern atomic_unchecked_t rdma_stat_sq_starve;
64864 +extern atomic_unchecked_t rdma_stat_rq_starve;
64865 +extern atomic_unchecked_t rdma_stat_rq_poll;
64866 +extern atomic_unchecked_t rdma_stat_rq_prod;
64867 +extern atomic_unchecked_t rdma_stat_sq_poll;
64868 +extern atomic_unchecked_t rdma_stat_sq_prod;
64869
64870 #define RPCRDMA_VERSION 1
64871
64872 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64873 index bb9127d..34ab358 100644
64874 --- a/include/linux/sysctl.h
64875 +++ b/include/linux/sysctl.h
64876 @@ -155,7 +155,11 @@ enum
64877 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64878 };
64879
64880 -
64881 +#ifdef CONFIG_PAX_SOFTMODE
64882 +enum {
64883 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64884 +};
64885 +#endif
64886
64887 /* CTL_VM names: */
64888 enum
64889 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64890
64891 extern int proc_dostring(struct ctl_table *, int,
64892 void __user *, size_t *, loff_t *);
64893 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64894 + void __user *, size_t *, loff_t *);
64895 extern int proc_dointvec(struct ctl_table *, int,
64896 void __user *, size_t *, loff_t *);
64897 extern int proc_dointvec_minmax(struct ctl_table *, int,
64898 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
64899 index a71a292..51bd91d 100644
64900 --- a/include/linux/tracehook.h
64901 +++ b/include/linux/tracehook.h
64902 @@ -54,12 +54,12 @@ struct linux_binprm;
64903 /*
64904 * ptrace report for syscall entry and exit looks identical.
64905 */
64906 -static inline void ptrace_report_syscall(struct pt_regs *regs)
64907 +static inline int ptrace_report_syscall(struct pt_regs *regs)
64908 {
64909 int ptrace = current->ptrace;
64910
64911 if (!(ptrace & PT_PTRACED))
64912 - return;
64913 + return 0;
64914
64915 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
64916
64917 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
64918 send_sig(current->exit_code, current, 1);
64919 current->exit_code = 0;
64920 }
64921 +
64922 + return fatal_signal_pending(current);
64923 }
64924
64925 /**
64926 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
64927 static inline __must_check int tracehook_report_syscall_entry(
64928 struct pt_regs *regs)
64929 {
64930 - ptrace_report_syscall(regs);
64931 - return 0;
64932 + return ptrace_report_syscall(regs);
64933 }
64934
64935 /**
64936 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64937 index ff7dc08..893e1bd 100644
64938 --- a/include/linux/tty_ldisc.h
64939 +++ b/include/linux/tty_ldisc.h
64940 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
64941
64942 struct module *owner;
64943
64944 - int refcount;
64945 + atomic_t refcount;
64946 };
64947
64948 struct tty_ldisc {
64949 diff --git a/include/linux/types.h b/include/linux/types.h
64950 index e5fa503..df6e8a4 100644
64951 --- a/include/linux/types.h
64952 +++ b/include/linux/types.h
64953 @@ -214,10 +214,26 @@ typedef struct {
64954 int counter;
64955 } atomic_t;
64956
64957 +#ifdef CONFIG_PAX_REFCOUNT
64958 +typedef struct {
64959 + int counter;
64960 +} atomic_unchecked_t;
64961 +#else
64962 +typedef atomic_t atomic_unchecked_t;
64963 +#endif
64964 +
64965 #ifdef CONFIG_64BIT
64966 typedef struct {
64967 long counter;
64968 } atomic64_t;
64969 +
64970 +#ifdef CONFIG_PAX_REFCOUNT
64971 +typedef struct {
64972 + long counter;
64973 +} atomic64_unchecked_t;
64974 +#else
64975 +typedef atomic64_t atomic64_unchecked_t;
64976 +#endif
64977 #endif
64978
64979 struct list_head {
64980 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64981 index 5ca0951..53a2fff 100644
64982 --- a/include/linux/uaccess.h
64983 +++ b/include/linux/uaccess.h
64984 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64985 long ret; \
64986 mm_segment_t old_fs = get_fs(); \
64987 \
64988 - set_fs(KERNEL_DS); \
64989 pagefault_disable(); \
64990 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64991 - pagefault_enable(); \
64992 + set_fs(KERNEL_DS); \
64993 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64994 set_fs(old_fs); \
64995 + pagefault_enable(); \
64996 ret; \
64997 })
64998
64999 @@ -105,7 +105,7 @@ extern long __probe_kernel_read(void *dst, const void *src, size_t size);
65000 * Safely write to address @dst from the buffer at @src. If a kernel fault
65001 * happens, handle that and return -EFAULT.
65002 */
65003 -extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
65004 +extern long notrace probe_kernel_write(void *dst, const void *src, size_t size) __size_overflow(3);
65005 extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
65006
65007 #endif /* __LINUX_UACCESS_H__ */
65008 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
65009 index 99c1b4d..bb94261 100644
65010 --- a/include/linux/unaligned/access_ok.h
65011 +++ b/include/linux/unaligned/access_ok.h
65012 @@ -6,32 +6,32 @@
65013
65014 static inline u16 get_unaligned_le16(const void *p)
65015 {
65016 - return le16_to_cpup((__le16 *)p);
65017 + return le16_to_cpup((const __le16 *)p);
65018 }
65019
65020 static inline u32 get_unaligned_le32(const void *p)
65021 {
65022 - return le32_to_cpup((__le32 *)p);
65023 + return le32_to_cpup((const __le32 *)p);
65024 }
65025
65026 static inline u64 get_unaligned_le64(const void *p)
65027 {
65028 - return le64_to_cpup((__le64 *)p);
65029 + return le64_to_cpup((const __le64 *)p);
65030 }
65031
65032 static inline u16 get_unaligned_be16(const void *p)
65033 {
65034 - return be16_to_cpup((__be16 *)p);
65035 + return be16_to_cpup((const __be16 *)p);
65036 }
65037
65038 static inline u32 get_unaligned_be32(const void *p)
65039 {
65040 - return be32_to_cpup((__be32 *)p);
65041 + return be32_to_cpup((const __be32 *)p);
65042 }
65043
65044 static inline u64 get_unaligned_be64(const void *p)
65045 {
65046 - return be64_to_cpup((__be64 *)p);
65047 + return be64_to_cpup((const __be64 *)p);
65048 }
65049
65050 static inline void put_unaligned_le16(u16 val, void *p)
65051 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
65052 index 0d3f988..000f101 100644
65053 --- a/include/linux/usb/renesas_usbhs.h
65054 +++ b/include/linux/usb/renesas_usbhs.h
65055 @@ -39,7 +39,7 @@ enum {
65056 */
65057 struct renesas_usbhs_driver_callback {
65058 int (*notify_hotplug)(struct platform_device *pdev);
65059 -};
65060 +} __no_const;
65061
65062 /*
65063 * callback functions for platform
65064 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
65065 * VBUS control is needed for Host
65066 */
65067 int (*set_vbus)(struct platform_device *pdev, int enable);
65068 -};
65069 +} __no_const;
65070
65071 /*
65072 * parameters for renesas usbhs
65073 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
65074 index 6f8fbcf..8259001 100644
65075 --- a/include/linux/vermagic.h
65076 +++ b/include/linux/vermagic.h
65077 @@ -25,9 +25,35 @@
65078 #define MODULE_ARCH_VERMAGIC ""
65079 #endif
65080
65081 +#ifdef CONFIG_PAX_REFCOUNT
65082 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
65083 +#else
65084 +#define MODULE_PAX_REFCOUNT ""
65085 +#endif
65086 +
65087 +#ifdef CONSTIFY_PLUGIN
65088 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65089 +#else
65090 +#define MODULE_CONSTIFY_PLUGIN ""
65091 +#endif
65092 +
65093 +#ifdef STACKLEAK_PLUGIN
65094 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
65095 +#else
65096 +#define MODULE_STACKLEAK_PLUGIN ""
65097 +#endif
65098 +
65099 +#ifdef CONFIG_GRKERNSEC
65100 +#define MODULE_GRSEC "GRSEC "
65101 +#else
65102 +#define MODULE_GRSEC ""
65103 +#endif
65104 +
65105 #define VERMAGIC_STRING \
65106 UTS_RELEASE " " \
65107 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65108 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65109 - MODULE_ARCH_VERMAGIC
65110 + MODULE_ARCH_VERMAGIC \
65111 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65112 + MODULE_GRSEC
65113
65114 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65115 index dcdfc2b..cce598d 100644
65116 --- a/include/linux/vmalloc.h
65117 +++ b/include/linux/vmalloc.h
65118 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65119 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65120 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65121 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65122 +
65123 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65124 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65125 +#endif
65126 +
65127 /* bits [20..32] reserved for arch specific ioremap internals */
65128
65129 /*
65130 @@ -51,18 +56,18 @@ static inline void vmalloc_init(void)
65131 }
65132 #endif
65133
65134 -extern void *vmalloc(unsigned long size);
65135 -extern void *vzalloc(unsigned long size);
65136 -extern void *vmalloc_user(unsigned long size);
65137 -extern void *vmalloc_node(unsigned long size, int node);
65138 -extern void *vzalloc_node(unsigned long size, int node);
65139 -extern void *vmalloc_exec(unsigned long size);
65140 -extern void *vmalloc_32(unsigned long size);
65141 -extern void *vmalloc_32_user(unsigned long size);
65142 -extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65143 +extern void *vmalloc(unsigned long size) __size_overflow(1);
65144 +extern void *vzalloc(unsigned long size) __size_overflow(1);
65145 +extern void *vmalloc_user(unsigned long size) __size_overflow(1);
65146 +extern void *vmalloc_node(unsigned long size, int node) __size_overflow(1);
65147 +extern void *vzalloc_node(unsigned long size, int node) __size_overflow(1);
65148 +extern void *vmalloc_exec(unsigned long size) __size_overflow(1);
65149 +extern void *vmalloc_32(unsigned long size) __size_overflow(1);
65150 +extern void *vmalloc_32_user(unsigned long size) __size_overflow(1);
65151 +extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) __size_overflow(1);
65152 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65153 unsigned long start, unsigned long end, gfp_t gfp_mask,
65154 - pgprot_t prot, int node, void *caller);
65155 + pgprot_t prot, int node, void *caller) __size_overflow(1);
65156 extern void vfree(const void *addr);
65157
65158 extern void *vmap(struct page **pages, unsigned int count,
65159 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65160 extern void free_vm_area(struct vm_struct *area);
65161
65162 /* for /dev/kmem */
65163 -extern long vread(char *buf, char *addr, unsigned long count);
65164 -extern long vwrite(char *buf, char *addr, unsigned long count);
65165 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65166 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65167
65168 /*
65169 * Internals. Dont't use..
65170 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65171 index 65efb92..137adbb 100644
65172 --- a/include/linux/vmstat.h
65173 +++ b/include/linux/vmstat.h
65174 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65175 /*
65176 * Zone based page accounting with per cpu differentials.
65177 */
65178 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65179 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65180
65181 static inline void zone_page_state_add(long x, struct zone *zone,
65182 enum zone_stat_item item)
65183 {
65184 - atomic_long_add(x, &zone->vm_stat[item]);
65185 - atomic_long_add(x, &vm_stat[item]);
65186 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65187 + atomic_long_add_unchecked(x, &vm_stat[item]);
65188 }
65189
65190 static inline unsigned long global_page_state(enum zone_stat_item item)
65191 {
65192 - long x = atomic_long_read(&vm_stat[item]);
65193 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65194 #ifdef CONFIG_SMP
65195 if (x < 0)
65196 x = 0;
65197 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65198 static inline unsigned long zone_page_state(struct zone *zone,
65199 enum zone_stat_item item)
65200 {
65201 - long x = atomic_long_read(&zone->vm_stat[item]);
65202 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65203 #ifdef CONFIG_SMP
65204 if (x < 0)
65205 x = 0;
65206 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65207 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65208 enum zone_stat_item item)
65209 {
65210 - long x = atomic_long_read(&zone->vm_stat[item]);
65211 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65212
65213 #ifdef CONFIG_SMP
65214 int cpu;
65215 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65216
65217 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65218 {
65219 - atomic_long_inc(&zone->vm_stat[item]);
65220 - atomic_long_inc(&vm_stat[item]);
65221 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65222 + atomic_long_inc_unchecked(&vm_stat[item]);
65223 }
65224
65225 static inline void __inc_zone_page_state(struct page *page,
65226 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
65227
65228 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65229 {
65230 - atomic_long_dec(&zone->vm_stat[item]);
65231 - atomic_long_dec(&vm_stat[item]);
65232 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65233 + atomic_long_dec_unchecked(&vm_stat[item]);
65234 }
65235
65236 static inline void __dec_zone_page_state(struct page *page,
65237 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65238 index e5d1220..ef6e406 100644
65239 --- a/include/linux/xattr.h
65240 +++ b/include/linux/xattr.h
65241 @@ -57,6 +57,11 @@
65242 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65243 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65244
65245 +/* User namespace */
65246 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65247 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65248 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65249 +
65250 #ifdef __KERNEL__
65251
65252 #include <linux/types.h>
65253 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65254 index 4aeff96..b378cdc 100644
65255 --- a/include/media/saa7146_vv.h
65256 +++ b/include/media/saa7146_vv.h
65257 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
65258 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65259
65260 /* the extension can override this */
65261 - struct v4l2_ioctl_ops ops;
65262 + v4l2_ioctl_ops_no_const ops;
65263 /* pointer to the saa7146 core ops */
65264 const struct v4l2_ioctl_ops *core_ops;
65265
65266 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65267 index c7c40f1..4f01585 100644
65268 --- a/include/media/v4l2-dev.h
65269 +++ b/include/media/v4l2-dev.h
65270 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
65271
65272
65273 struct v4l2_file_operations {
65274 - struct module *owner;
65275 + struct module * const owner;
65276 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
65277 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
65278 unsigned int (*poll) (struct file *, struct poll_table_struct *);
65279 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
65280 int (*open) (struct file *);
65281 int (*release) (struct file *);
65282 };
65283 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65284
65285 /*
65286 * Newer version of video_device, handled by videodev2.c
65287 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65288 index 3f5d60f..44210ed 100644
65289 --- a/include/media/v4l2-ioctl.h
65290 +++ b/include/media/v4l2-ioctl.h
65291 @@ -278,7 +278,7 @@ struct v4l2_ioctl_ops {
65292 long (*vidioc_default) (struct file *file, void *fh,
65293 bool valid_prio, int cmd, void *arg);
65294 };
65295 -
65296 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65297
65298 /* v4l debugging and diagnostics */
65299
65300 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65301 index 8d55251..dfe5b0a 100644
65302 --- a/include/net/caif/caif_hsi.h
65303 +++ b/include/net/caif/caif_hsi.h
65304 @@ -98,7 +98,7 @@ struct cfhsi_drv {
65305 void (*rx_done_cb) (struct cfhsi_drv *drv);
65306 void (*wake_up_cb) (struct cfhsi_drv *drv);
65307 void (*wake_down_cb) (struct cfhsi_drv *drv);
65308 -};
65309 +} __no_const;
65310
65311 /* Structure implemented by HSI device. */
65312 struct cfhsi_dev {
65313 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65314 index 9e5425b..8136ffc 100644
65315 --- a/include/net/caif/cfctrl.h
65316 +++ b/include/net/caif/cfctrl.h
65317 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65318 void (*radioset_rsp)(void);
65319 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65320 struct cflayer *client_layer);
65321 -};
65322 +} __no_const;
65323
65324 /* Link Setup Parameters for CAIF-Links. */
65325 struct cfctrl_link_param {
65326 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65327 struct cfctrl {
65328 struct cfsrvl serv;
65329 struct cfctrl_rsp res;
65330 - atomic_t req_seq_no;
65331 - atomic_t rsp_seq_no;
65332 + atomic_unchecked_t req_seq_no;
65333 + atomic_unchecked_t rsp_seq_no;
65334 struct list_head list;
65335 /* Protects from simultaneous access to first_req list */
65336 spinlock_t info_list_lock;
65337 diff --git a/include/net/flow.h b/include/net/flow.h
65338 index 6c469db..7743b8e 100644
65339 --- a/include/net/flow.h
65340 +++ b/include/net/flow.h
65341 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65342
65343 extern void flow_cache_flush(void);
65344 extern void flow_cache_flush_deferred(void);
65345 -extern atomic_t flow_cache_genid;
65346 +extern atomic_unchecked_t flow_cache_genid;
65347
65348 #endif
65349 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65350 index b94765e..053f68b 100644
65351 --- a/include/net/inetpeer.h
65352 +++ b/include/net/inetpeer.h
65353 @@ -48,8 +48,8 @@ struct inet_peer {
65354 */
65355 union {
65356 struct {
65357 - atomic_t rid; /* Frag reception counter */
65358 - atomic_t ip_id_count; /* IP ID for the next packet */
65359 + atomic_unchecked_t rid; /* Frag reception counter */
65360 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65361 __u32 tcp_ts;
65362 __u32 tcp_ts_stamp;
65363 };
65364 @@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65365 more++;
65366 inet_peer_refcheck(p);
65367 do {
65368 - old = atomic_read(&p->ip_id_count);
65369 + old = atomic_read_unchecked(&p->ip_id_count);
65370 new = old + more;
65371 if (!new)
65372 new = 1;
65373 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65374 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65375 return new;
65376 }
65377
65378 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65379 index 10422ef..662570f 100644
65380 --- a/include/net/ip_fib.h
65381 +++ b/include/net/ip_fib.h
65382 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65383
65384 #define FIB_RES_SADDR(net, res) \
65385 ((FIB_RES_NH(res).nh_saddr_genid == \
65386 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65387 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65388 FIB_RES_NH(res).nh_saddr : \
65389 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65390 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65391 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65392 index ebe517f..1bd286b 100644
65393 --- a/include/net/ip_vs.h
65394 +++ b/include/net/ip_vs.h
65395 @@ -509,7 +509,7 @@ struct ip_vs_conn {
65396 struct ip_vs_conn *control; /* Master control connection */
65397 atomic_t n_control; /* Number of controlled ones */
65398 struct ip_vs_dest *dest; /* real server */
65399 - atomic_t in_pkts; /* incoming packet counter */
65400 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65401
65402 /* packet transmitter for different forwarding methods. If it
65403 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65404 @@ -647,7 +647,7 @@ struct ip_vs_dest {
65405 __be16 port; /* port number of the server */
65406 union nf_inet_addr addr; /* IP address of the server */
65407 volatile unsigned flags; /* dest status flags */
65408 - atomic_t conn_flags; /* flags to copy to conn */
65409 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65410 atomic_t weight; /* server weight */
65411
65412 atomic_t refcnt; /* reference counter */
65413 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65414 index 69b610a..fe3962c 100644
65415 --- a/include/net/irda/ircomm_core.h
65416 +++ b/include/net/irda/ircomm_core.h
65417 @@ -51,7 +51,7 @@ typedef struct {
65418 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65419 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65420 struct ircomm_info *);
65421 -} call_t;
65422 +} __no_const call_t;
65423
65424 struct ircomm_cb {
65425 irda_queue_t queue;
65426 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65427 index 59ba38bc..d515662 100644
65428 --- a/include/net/irda/ircomm_tty.h
65429 +++ b/include/net/irda/ircomm_tty.h
65430 @@ -35,6 +35,7 @@
65431 #include <linux/termios.h>
65432 #include <linux/timer.h>
65433 #include <linux/tty.h> /* struct tty_struct */
65434 +#include <asm/local.h>
65435
65436 #include <net/irda/irias_object.h>
65437 #include <net/irda/ircomm_core.h>
65438 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65439 unsigned short close_delay;
65440 unsigned short closing_wait; /* time to wait before closing */
65441
65442 - int open_count;
65443 - int blocked_open; /* # of blocked opens */
65444 + local_t open_count;
65445 + local_t blocked_open; /* # of blocked opens */
65446
65447 /* Protect concurent access to :
65448 * o self->open_count
65449 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65450 index 0954ec9..7413562 100644
65451 --- a/include/net/iucv/af_iucv.h
65452 +++ b/include/net/iucv/af_iucv.h
65453 @@ -138,7 +138,7 @@ struct iucv_sock {
65454 struct iucv_sock_list {
65455 struct hlist_head head;
65456 rwlock_t lock;
65457 - atomic_t autobind_name;
65458 + atomic_unchecked_t autobind_name;
65459 };
65460
65461 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65462 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65463 index 34c996f..bb3b4d4 100644
65464 --- a/include/net/neighbour.h
65465 +++ b/include/net/neighbour.h
65466 @@ -123,7 +123,7 @@ struct neigh_ops {
65467 void (*error_report)(struct neighbour *, struct sk_buff *);
65468 int (*output)(struct neighbour *, struct sk_buff *);
65469 int (*connected_output)(struct neighbour *, struct sk_buff *);
65470 -};
65471 +} __do_const;
65472
65473 struct pneigh_entry {
65474 struct pneigh_entry *next;
65475 diff --git a/include/net/netlink.h b/include/net/netlink.h
65476 index cb1f350..3279d2c 100644
65477 --- a/include/net/netlink.h
65478 +++ b/include/net/netlink.h
65479 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65480 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65481 {
65482 if (mark)
65483 - skb_trim(skb, (unsigned char *) mark - skb->data);
65484 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65485 }
65486
65487 /**
65488 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65489 index bbd023a..97c6d0d 100644
65490 --- a/include/net/netns/ipv4.h
65491 +++ b/include/net/netns/ipv4.h
65492 @@ -57,8 +57,8 @@ struct netns_ipv4 {
65493 unsigned int sysctl_ping_group_range[2];
65494 long sysctl_tcp_mem[3];
65495
65496 - atomic_t rt_genid;
65497 - atomic_t dev_addr_genid;
65498 + atomic_unchecked_t rt_genid;
65499 + atomic_unchecked_t dev_addr_genid;
65500
65501 #ifdef CONFIG_IP_MROUTE
65502 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65503 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65504 index d368561..96aaa17 100644
65505 --- a/include/net/sctp/sctp.h
65506 +++ b/include/net/sctp/sctp.h
65507 @@ -318,9 +318,9 @@ do { \
65508
65509 #else /* SCTP_DEBUG */
65510
65511 -#define SCTP_DEBUG_PRINTK(whatever...)
65512 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65513 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65514 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65515 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65516 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65517 #define SCTP_ENABLE_DEBUG
65518 #define SCTP_DISABLE_DEBUG
65519 #define SCTP_ASSERT(expr, str, func)
65520 diff --git a/include/net/sock.h b/include/net/sock.h
65521 index 91c1c8b..15ae923 100644
65522 --- a/include/net/sock.h
65523 +++ b/include/net/sock.h
65524 @@ -299,7 +299,7 @@ struct sock {
65525 #ifdef CONFIG_RPS
65526 __u32 sk_rxhash;
65527 #endif
65528 - atomic_t sk_drops;
65529 + atomic_unchecked_t sk_drops;
65530 int sk_rcvbuf;
65531
65532 struct sk_filter __rcu *sk_filter;
65533 @@ -1660,7 +1660,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65534 }
65535
65536 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65537 - char __user *from, char *to,
65538 + char __user *from, unsigned char *to,
65539 int copy, int offset)
65540 {
65541 if (skb->ip_summed == CHECKSUM_NONE) {
65542 diff --git a/include/net/tcp.h b/include/net/tcp.h
65543 index 2d80c29..aa07caf 100644
65544 --- a/include/net/tcp.h
65545 +++ b/include/net/tcp.h
65546 @@ -1426,7 +1426,7 @@ struct tcp_seq_afinfo {
65547 char *name;
65548 sa_family_t family;
65549 const struct file_operations *seq_fops;
65550 - struct seq_operations seq_ops;
65551 + seq_operations_no_const seq_ops;
65552 };
65553
65554 struct tcp_iter_state {
65555 diff --git a/include/net/udp.h b/include/net/udp.h
65556 index e39592f..fef9680 100644
65557 --- a/include/net/udp.h
65558 +++ b/include/net/udp.h
65559 @@ -243,7 +243,7 @@ struct udp_seq_afinfo {
65560 sa_family_t family;
65561 struct udp_table *udp_table;
65562 const struct file_operations *seq_fops;
65563 - struct seq_operations seq_ops;
65564 + seq_operations_no_const seq_ops;
65565 };
65566
65567 struct udp_iter_state {
65568 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65569 index 89174e2..1f82598 100644
65570 --- a/include/net/xfrm.h
65571 +++ b/include/net/xfrm.h
65572 @@ -505,7 +505,7 @@ struct xfrm_policy {
65573 struct timer_list timer;
65574
65575 struct flow_cache_object flo;
65576 - atomic_t genid;
65577 + atomic_unchecked_t genid;
65578 u32 priority;
65579 u32 index;
65580 struct xfrm_mark mark;
65581 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65582 index 1a046b1..ee0bef0 100644
65583 --- a/include/rdma/iw_cm.h
65584 +++ b/include/rdma/iw_cm.h
65585 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65586 int backlog);
65587
65588 int (*destroy_listen)(struct iw_cm_id *cm_id);
65589 -};
65590 +} __no_const;
65591
65592 /**
65593 * iw_create_cm_id - Create an IW CM identifier.
65594 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65595 index 6a3922f..0b73022 100644
65596 --- a/include/scsi/libfc.h
65597 +++ b/include/scsi/libfc.h
65598 @@ -748,6 +748,7 @@ struct libfc_function_template {
65599 */
65600 void (*disc_stop_final) (struct fc_lport *);
65601 };
65602 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65603
65604 /**
65605 * struct fc_disc - Discovery context
65606 @@ -851,7 +852,7 @@ struct fc_lport {
65607 struct fc_vport *vport;
65608
65609 /* Operational Information */
65610 - struct libfc_function_template tt;
65611 + libfc_function_template_no_const tt;
65612 u8 link_up;
65613 u8 qfull;
65614 enum fc_lport_state state;
65615 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65616 index 77273f2..dd4031f 100644
65617 --- a/include/scsi/scsi_device.h
65618 +++ b/include/scsi/scsi_device.h
65619 @@ -161,9 +161,9 @@ struct scsi_device {
65620 unsigned int max_device_blocked; /* what device_blocked counts down from */
65621 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65622
65623 - atomic_t iorequest_cnt;
65624 - atomic_t iodone_cnt;
65625 - atomic_t ioerr_cnt;
65626 + atomic_unchecked_t iorequest_cnt;
65627 + atomic_unchecked_t iodone_cnt;
65628 + atomic_unchecked_t ioerr_cnt;
65629
65630 struct device sdev_gendev,
65631 sdev_dev;
65632 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65633 index 2a65167..91e01f8 100644
65634 --- a/include/scsi/scsi_transport_fc.h
65635 +++ b/include/scsi/scsi_transport_fc.h
65636 @@ -711,7 +711,7 @@ struct fc_function_template {
65637 unsigned long show_host_system_hostname:1;
65638
65639 unsigned long disable_target_scan:1;
65640 -};
65641 +} __do_const;
65642
65643
65644 /**
65645 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65646 index 030b87c..98a6954 100644
65647 --- a/include/sound/ak4xxx-adda.h
65648 +++ b/include/sound/ak4xxx-adda.h
65649 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65650 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65651 unsigned char val);
65652 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65653 -};
65654 +} __no_const;
65655
65656 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65657
65658 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65659 index 8c05e47..2b5df97 100644
65660 --- a/include/sound/hwdep.h
65661 +++ b/include/sound/hwdep.h
65662 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65663 struct snd_hwdep_dsp_status *status);
65664 int (*dsp_load)(struct snd_hwdep *hw,
65665 struct snd_hwdep_dsp_image *image);
65666 -};
65667 +} __no_const;
65668
65669 struct snd_hwdep {
65670 struct snd_card *card;
65671 diff --git a/include/sound/info.h b/include/sound/info.h
65672 index 9ca1a49..aba1728 100644
65673 --- a/include/sound/info.h
65674 +++ b/include/sound/info.h
65675 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65676 struct snd_info_buffer *buffer);
65677 void (*write)(struct snd_info_entry *entry,
65678 struct snd_info_buffer *buffer);
65679 -};
65680 +} __no_const;
65681
65682 struct snd_info_entry_ops {
65683 int (*open)(struct snd_info_entry *entry,
65684 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65685 index 0cf91b2..b70cae4 100644
65686 --- a/include/sound/pcm.h
65687 +++ b/include/sound/pcm.h
65688 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65689 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65690 int (*ack)(struct snd_pcm_substream *substream);
65691 };
65692 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65693
65694 /*
65695 *
65696 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65697 index af1b49e..a5d55a5 100644
65698 --- a/include/sound/sb16_csp.h
65699 +++ b/include/sound/sb16_csp.h
65700 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65701 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65702 int (*csp_stop) (struct snd_sb_csp * p);
65703 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65704 -};
65705 +} __no_const;
65706
65707 /*
65708 * CSP private data
65709 diff --git a/include/sound/soc.h b/include/sound/soc.h
65710 index 0992dff..bb366fe 100644
65711 --- a/include/sound/soc.h
65712 +++ b/include/sound/soc.h
65713 @@ -682,7 +682,7 @@ struct snd_soc_platform_driver {
65714 /* platform IO - used for platform DAPM */
65715 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65716 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65717 -};
65718 +} __do_const;
65719
65720 struct snd_soc_platform {
65721 const char *name;
65722 @@ -852,7 +852,7 @@ struct snd_soc_pcm_runtime {
65723 struct snd_soc_dai_link *dai_link;
65724 struct mutex pcm_mutex;
65725 enum snd_soc_pcm_subclass pcm_subclass;
65726 - struct snd_pcm_ops ops;
65727 + snd_pcm_ops_no_const ops;
65728
65729 unsigned int complete:1;
65730 unsigned int dev_registered:1;
65731 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
65732 index 444cd6b..3327cc5 100644
65733 --- a/include/sound/ymfpci.h
65734 +++ b/include/sound/ymfpci.h
65735 @@ -358,7 +358,7 @@ struct snd_ymfpci {
65736 spinlock_t reg_lock;
65737 spinlock_t voice_lock;
65738 wait_queue_head_t interrupt_sleep;
65739 - atomic_t interrupt_sleep_count;
65740 + atomic_unchecked_t interrupt_sleep_count;
65741 struct snd_info_entry *proc_entry;
65742 const struct firmware *dsp_microcode;
65743 const struct firmware *controller_microcode;
65744 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65745 index fe73eb8..56388b1 100644
65746 --- a/include/target/target_core_base.h
65747 +++ b/include/target/target_core_base.h
65748 @@ -443,7 +443,7 @@ struct t10_reservation_ops {
65749 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65750 int (*t10_pr_register)(struct se_cmd *);
65751 int (*t10_pr_clear)(struct se_cmd *);
65752 -};
65753 +} __no_const;
65754
65755 struct t10_reservation {
65756 /* Reservation effects all target ports */
65757 @@ -561,8 +561,8 @@ struct se_cmd {
65758 atomic_t t_se_count;
65759 atomic_t t_task_cdbs_left;
65760 atomic_t t_task_cdbs_ex_left;
65761 - atomic_t t_task_cdbs_sent;
65762 - atomic_t t_transport_aborted;
65763 + atomic_unchecked_t t_task_cdbs_sent;
65764 + atomic_unchecked_t t_transport_aborted;
65765 atomic_t t_transport_active;
65766 atomic_t t_transport_complete;
65767 atomic_t t_transport_queue_active;
65768 @@ -799,7 +799,7 @@ struct se_device {
65769 spinlock_t stats_lock;
65770 /* Active commands on this virtual SE device */
65771 atomic_t simple_cmds;
65772 - atomic_t dev_ordered_id;
65773 + atomic_unchecked_t dev_ordered_id;
65774 atomic_t execute_tasks;
65775 atomic_t dev_ordered_sync;
65776 atomic_t dev_qf_count;
65777 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65778 index 1c09820..7f5ec79 100644
65779 --- a/include/trace/events/irq.h
65780 +++ b/include/trace/events/irq.h
65781 @@ -36,7 +36,7 @@ struct softirq_action;
65782 */
65783 TRACE_EVENT(irq_handler_entry,
65784
65785 - TP_PROTO(int irq, struct irqaction *action),
65786 + TP_PROTO(int irq, const struct irqaction *action),
65787
65788 TP_ARGS(irq, action),
65789
65790 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65791 */
65792 TRACE_EVENT(irq_handler_exit,
65793
65794 - TP_PROTO(int irq, struct irqaction *action, int ret),
65795 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65796
65797 TP_ARGS(irq, action, ret),
65798
65799 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65800 index c41f308..6918de3 100644
65801 --- a/include/video/udlfb.h
65802 +++ b/include/video/udlfb.h
65803 @@ -52,10 +52,10 @@ struct dlfb_data {
65804 u32 pseudo_palette[256];
65805 int blank_mode; /*one of FB_BLANK_ */
65806 /* blit-only rendering path metrics, exposed through sysfs */
65807 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65808 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65809 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65810 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65811 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65812 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65813 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65814 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65815 };
65816
65817 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65818 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65819 index 0993a22..32ba2fe 100644
65820 --- a/include/video/uvesafb.h
65821 +++ b/include/video/uvesafb.h
65822 @@ -177,6 +177,7 @@ struct uvesafb_par {
65823 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65824 u8 pmi_setpal; /* PMI for palette changes */
65825 u16 *pmi_base; /* protected mode interface location */
65826 + u8 *pmi_code; /* protected mode code location */
65827 void *pmi_start;
65828 void *pmi_pal;
65829 u8 *vbe_state_orig; /*
65830 diff --git a/init/Kconfig b/init/Kconfig
65831 index 3f42cd6..613f41d 100644
65832 --- a/init/Kconfig
65833 +++ b/init/Kconfig
65834 @@ -799,6 +799,7 @@ endif # CGROUPS
65835
65836 config CHECKPOINT_RESTORE
65837 bool "Checkpoint/restore support" if EXPERT
65838 + depends on !GRKERNSEC
65839 default n
65840 help
65841 Enables additional kernel features in a sake of checkpoint/restore.
65842 @@ -1249,7 +1250,7 @@ config SLUB_DEBUG
65843
65844 config COMPAT_BRK
65845 bool "Disable heap randomization"
65846 - default y
65847 + default n
65848 help
65849 Randomizing heap placement makes heap exploits harder, but it
65850 also breaks ancient binaries (including anything libc5 based).
65851 diff --git a/init/do_mounts.c b/init/do_mounts.c
65852 index 2974c8b..0b863ae 100644
65853 --- a/init/do_mounts.c
65854 +++ b/init/do_mounts.c
65855 @@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
65856 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65857 {
65858 struct super_block *s;
65859 - int err = sys_mount(name, "/root", fs, flags, data);
65860 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65861 if (err)
65862 return err;
65863
65864 - sys_chdir((const char __user __force *)"/root");
65865 + sys_chdir((const char __force_user *)"/root");
65866 s = current->fs->pwd.dentry->d_sb;
65867 ROOT_DEV = s->s_dev;
65868 printk(KERN_INFO
65869 @@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
65870 va_start(args, fmt);
65871 vsprintf(buf, fmt, args);
65872 va_end(args);
65873 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65874 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65875 if (fd >= 0) {
65876 sys_ioctl(fd, FDEJECT, 0);
65877 sys_close(fd);
65878 }
65879 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65880 - fd = sys_open("/dev/console", O_RDWR, 0);
65881 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65882 if (fd >= 0) {
65883 sys_ioctl(fd, TCGETS, (long)&termios);
65884 termios.c_lflag &= ~ICANON;
65885 sys_ioctl(fd, TCSETSF, (long)&termios);
65886 - sys_read(fd, &c, 1);
65887 + sys_read(fd, (char __user *)&c, 1);
65888 termios.c_lflag |= ICANON;
65889 sys_ioctl(fd, TCSETSF, (long)&termios);
65890 sys_close(fd);
65891 @@ -555,6 +555,6 @@ void __init prepare_namespace(void)
65892 mount_root();
65893 out:
65894 devtmpfs_mount("dev");
65895 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65896 - sys_chroot((const char __user __force *)".");
65897 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65898 + sys_chroot((const char __force_user *)".");
65899 }
65900 diff --git a/init/do_mounts.h b/init/do_mounts.h
65901 index f5b978a..69dbfe8 100644
65902 --- a/init/do_mounts.h
65903 +++ b/init/do_mounts.h
65904 @@ -15,15 +15,15 @@ extern int root_mountflags;
65905
65906 static inline int create_dev(char *name, dev_t dev)
65907 {
65908 - sys_unlink(name);
65909 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65910 + sys_unlink((char __force_user *)name);
65911 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65912 }
65913
65914 #if BITS_PER_LONG == 32
65915 static inline u32 bstat(char *name)
65916 {
65917 struct stat64 stat;
65918 - if (sys_stat64(name, &stat) != 0)
65919 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65920 return 0;
65921 if (!S_ISBLK(stat.st_mode))
65922 return 0;
65923 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65924 static inline u32 bstat(char *name)
65925 {
65926 struct stat stat;
65927 - if (sys_newstat(name, &stat) != 0)
65928 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65929 return 0;
65930 if (!S_ISBLK(stat.st_mode))
65931 return 0;
65932 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65933 index 3098a38..253064e 100644
65934 --- a/init/do_mounts_initrd.c
65935 +++ b/init/do_mounts_initrd.c
65936 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
65937 create_dev("/dev/root.old", Root_RAM0);
65938 /* mount initrd on rootfs' /root */
65939 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65940 - sys_mkdir("/old", 0700);
65941 - root_fd = sys_open("/", 0, 0);
65942 - old_fd = sys_open("/old", 0, 0);
65943 + sys_mkdir((const char __force_user *)"/old", 0700);
65944 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65945 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65946 /* move initrd over / and chdir/chroot in initrd root */
65947 - sys_chdir("/root");
65948 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65949 - sys_chroot(".");
65950 + sys_chdir((const char __force_user *)"/root");
65951 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65952 + sys_chroot((const char __force_user *)".");
65953
65954 /*
65955 * In case that a resume from disk is carried out by linuxrc or one of
65956 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
65957
65958 /* move initrd to rootfs' /old */
65959 sys_fchdir(old_fd);
65960 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65961 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65962 /* switch root and cwd back to / of rootfs */
65963 sys_fchdir(root_fd);
65964 - sys_chroot(".");
65965 + sys_chroot((const char __force_user *)".");
65966 sys_close(old_fd);
65967 sys_close(root_fd);
65968
65969 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65970 - sys_chdir("/old");
65971 + sys_chdir((const char __force_user *)"/old");
65972 return;
65973 }
65974
65975 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
65976 mount_root();
65977
65978 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65979 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65980 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65981 if (!error)
65982 printk("okay\n");
65983 else {
65984 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65985 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65986 if (error == -ENOENT)
65987 printk("/initrd does not exist. Ignored.\n");
65988 else
65989 printk("failed\n");
65990 printk(KERN_NOTICE "Unmounting old root\n");
65991 - sys_umount("/old", MNT_DETACH);
65992 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65993 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65994 if (fd < 0) {
65995 error = fd;
65996 @@ -116,11 +116,11 @@ int __init initrd_load(void)
65997 * mounted in the normal path.
65998 */
65999 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66000 - sys_unlink("/initrd.image");
66001 + sys_unlink((const char __force_user *)"/initrd.image");
66002 handle_initrd();
66003 return 1;
66004 }
66005 }
66006 - sys_unlink("/initrd.image");
66007 + sys_unlink((const char __force_user *)"/initrd.image");
66008 return 0;
66009 }
66010 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66011 index 32c4799..c27ee74 100644
66012 --- a/init/do_mounts_md.c
66013 +++ b/init/do_mounts_md.c
66014 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
66015 partitioned ? "_d" : "", minor,
66016 md_setup_args[ent].device_names);
66017
66018 - fd = sys_open(name, 0, 0);
66019 + fd = sys_open((char __force_user *)name, 0, 0);
66020 if (fd < 0) {
66021 printk(KERN_ERR "md: open failed - cannot start "
66022 "array %s\n", name);
66023 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
66024 * array without it
66025 */
66026 sys_close(fd);
66027 - fd = sys_open(name, 0, 0);
66028 + fd = sys_open((char __force_user *)name, 0, 0);
66029 sys_ioctl(fd, BLKRRPART, 0);
66030 }
66031 sys_close(fd);
66032 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
66033
66034 wait_for_device_probe();
66035
66036 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
66037 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66038 if (fd >= 0) {
66039 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66040 sys_close(fd);
66041 diff --git a/init/initramfs.c b/init/initramfs.c
66042 index 8216c30..25e8e32 100644
66043 --- a/init/initramfs.c
66044 +++ b/init/initramfs.c
66045 @@ -74,7 +74,7 @@ static void __init free_hash(void)
66046 }
66047 }
66048
66049 -static long __init do_utime(char __user *filename, time_t mtime)
66050 +static long __init do_utime(__force char __user *filename, time_t mtime)
66051 {
66052 struct timespec t[2];
66053
66054 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
66055 struct dir_entry *de, *tmp;
66056 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66057 list_del(&de->list);
66058 - do_utime(de->name, de->mtime);
66059 + do_utime((char __force_user *)de->name, de->mtime);
66060 kfree(de->name);
66061 kfree(de);
66062 }
66063 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
66064 if (nlink >= 2) {
66065 char *old = find_link(major, minor, ino, mode, collected);
66066 if (old)
66067 - return (sys_link(old, collected) < 0) ? -1 : 1;
66068 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66069 }
66070 return 0;
66071 }
66072 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
66073 {
66074 struct stat st;
66075
66076 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66077 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66078 if (S_ISDIR(st.st_mode))
66079 - sys_rmdir(path);
66080 + sys_rmdir((char __force_user *)path);
66081 else
66082 - sys_unlink(path);
66083 + sys_unlink((char __force_user *)path);
66084 }
66085 }
66086
66087 @@ -305,7 +305,7 @@ static int __init do_name(void)
66088 int openflags = O_WRONLY|O_CREAT;
66089 if (ml != 1)
66090 openflags |= O_TRUNC;
66091 - wfd = sys_open(collected, openflags, mode);
66092 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66093
66094 if (wfd >= 0) {
66095 sys_fchown(wfd, uid, gid);
66096 @@ -317,17 +317,17 @@ static int __init do_name(void)
66097 }
66098 }
66099 } else if (S_ISDIR(mode)) {
66100 - sys_mkdir(collected, mode);
66101 - sys_chown(collected, uid, gid);
66102 - sys_chmod(collected, mode);
66103 + sys_mkdir((char __force_user *)collected, mode);
66104 + sys_chown((char __force_user *)collected, uid, gid);
66105 + sys_chmod((char __force_user *)collected, mode);
66106 dir_add(collected, mtime);
66107 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66108 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66109 if (maybe_link() == 0) {
66110 - sys_mknod(collected, mode, rdev);
66111 - sys_chown(collected, uid, gid);
66112 - sys_chmod(collected, mode);
66113 - do_utime(collected, mtime);
66114 + sys_mknod((char __force_user *)collected, mode, rdev);
66115 + sys_chown((char __force_user *)collected, uid, gid);
66116 + sys_chmod((char __force_user *)collected, mode);
66117 + do_utime((char __force_user *)collected, mtime);
66118 }
66119 }
66120 return 0;
66121 @@ -336,15 +336,15 @@ static int __init do_name(void)
66122 static int __init do_copy(void)
66123 {
66124 if (count >= body_len) {
66125 - sys_write(wfd, victim, body_len);
66126 + sys_write(wfd, (char __force_user *)victim, body_len);
66127 sys_close(wfd);
66128 - do_utime(vcollected, mtime);
66129 + do_utime((char __force_user *)vcollected, mtime);
66130 kfree(vcollected);
66131 eat(body_len);
66132 state = SkipIt;
66133 return 0;
66134 } else {
66135 - sys_write(wfd, victim, count);
66136 + sys_write(wfd, (char __force_user *)victim, count);
66137 body_len -= count;
66138 eat(count);
66139 return 1;
66140 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
66141 {
66142 collected[N_ALIGN(name_len) + body_len] = '\0';
66143 clean_path(collected, 0);
66144 - sys_symlink(collected + N_ALIGN(name_len), collected);
66145 - sys_lchown(collected, uid, gid);
66146 - do_utime(collected, mtime);
66147 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66148 + sys_lchown((char __force_user *)collected, uid, gid);
66149 + do_utime((char __force_user *)collected, mtime);
66150 state = SkipIt;
66151 next_state = Reset;
66152 return 0;
66153 diff --git a/init/main.c b/init/main.c
66154 index ff49a6d..5fa0429 100644
66155 --- a/init/main.c
66156 +++ b/init/main.c
66157 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66158 extern void tc_init(void);
66159 #endif
66160
66161 +extern void grsecurity_init(void);
66162 +
66163 /*
66164 * Debug helper: via this flag we know that we are in 'early bootup code'
66165 * where only the boot processor is running with IRQ disabled. This means
66166 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
66167
66168 __setup("reset_devices", set_reset_devices);
66169
66170 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66171 +extern char pax_enter_kernel_user[];
66172 +extern char pax_exit_kernel_user[];
66173 +extern pgdval_t clone_pgd_mask;
66174 +#endif
66175 +
66176 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66177 +static int __init setup_pax_nouderef(char *str)
66178 +{
66179 +#ifdef CONFIG_X86_32
66180 + unsigned int cpu;
66181 + struct desc_struct *gdt;
66182 +
66183 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66184 + gdt = get_cpu_gdt_table(cpu);
66185 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66186 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66187 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66188 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66189 + }
66190 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
66191 +#else
66192 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66193 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66194 + clone_pgd_mask = ~(pgdval_t)0UL;
66195 +#endif
66196 +
66197 + return 0;
66198 +}
66199 +early_param("pax_nouderef", setup_pax_nouderef);
66200 +#endif
66201 +
66202 +#ifdef CONFIG_PAX_SOFTMODE
66203 +int pax_softmode;
66204 +
66205 +static int __init setup_pax_softmode(char *str)
66206 +{
66207 + get_option(&str, &pax_softmode);
66208 + return 1;
66209 +}
66210 +__setup("pax_softmode=", setup_pax_softmode);
66211 +#endif
66212 +
66213 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66214 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66215 static const char *panic_later, *panic_param;
66216 @@ -675,6 +720,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66217 {
66218 int count = preempt_count();
66219 int ret;
66220 + const char *msg1 = "", *msg2 = "";
66221
66222 if (initcall_debug)
66223 ret = do_one_initcall_debug(fn);
66224 @@ -687,15 +733,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66225 sprintf(msgbuf, "error code %d ", ret);
66226
66227 if (preempt_count() != count) {
66228 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66229 + msg1 = " preemption imbalance";
66230 preempt_count() = count;
66231 }
66232 if (irqs_disabled()) {
66233 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66234 + msg2 = " disabled interrupts";
66235 local_irq_enable();
66236 }
66237 - if (msgbuf[0]) {
66238 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66239 + if (msgbuf[0] || *msg1 || *msg2) {
66240 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66241 }
66242
66243 return ret;
66244 @@ -814,7 +860,7 @@ static int __init kernel_init(void * unused)
66245 do_basic_setup();
66246
66247 /* Open the /dev/console on the rootfs, this should never fail */
66248 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66249 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66250 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66251
66252 (void) sys_dup(0);
66253 @@ -827,11 +873,13 @@ static int __init kernel_init(void * unused)
66254 if (!ramdisk_execute_command)
66255 ramdisk_execute_command = "/init";
66256
66257 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66258 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66259 ramdisk_execute_command = NULL;
66260 prepare_namespace();
66261 }
66262
66263 + grsecurity_init();
66264 +
66265 /*
66266 * Ok, we have completed the initial bootup, and
66267 * we're essentially up and running. Get rid of the
66268 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66269 index 86ee272..773d937 100644
66270 --- a/ipc/mqueue.c
66271 +++ b/ipc/mqueue.c
66272 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66273 mq_bytes = (mq_msg_tblsz +
66274 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
66275
66276 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66277 spin_lock(&mq_lock);
66278 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66279 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66280 diff --git a/ipc/msg.c b/ipc/msg.c
66281 index 7385de2..a8180e08 100644
66282 --- a/ipc/msg.c
66283 +++ b/ipc/msg.c
66284 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66285 return security_msg_queue_associate(msq, msgflg);
66286 }
66287
66288 +static struct ipc_ops msg_ops = {
66289 + .getnew = newque,
66290 + .associate = msg_security,
66291 + .more_checks = NULL
66292 +};
66293 +
66294 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66295 {
66296 struct ipc_namespace *ns;
66297 - struct ipc_ops msg_ops;
66298 struct ipc_params msg_params;
66299
66300 ns = current->nsproxy->ipc_ns;
66301
66302 - msg_ops.getnew = newque;
66303 - msg_ops.associate = msg_security;
66304 - msg_ops.more_checks = NULL;
66305 -
66306 msg_params.key = key;
66307 msg_params.flg = msgflg;
66308
66309 diff --git a/ipc/sem.c b/ipc/sem.c
66310 index 5215a81..cfc0cac 100644
66311 --- a/ipc/sem.c
66312 +++ b/ipc/sem.c
66313 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66314 return 0;
66315 }
66316
66317 +static struct ipc_ops sem_ops = {
66318 + .getnew = newary,
66319 + .associate = sem_security,
66320 + .more_checks = sem_more_checks
66321 +};
66322 +
66323 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66324 {
66325 struct ipc_namespace *ns;
66326 - struct ipc_ops sem_ops;
66327 struct ipc_params sem_params;
66328
66329 ns = current->nsproxy->ipc_ns;
66330 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66331 if (nsems < 0 || nsems > ns->sc_semmsl)
66332 return -EINVAL;
66333
66334 - sem_ops.getnew = newary;
66335 - sem_ops.associate = sem_security;
66336 - sem_ops.more_checks = sem_more_checks;
66337 -
66338 sem_params.key = key;
66339 sem_params.flg = semflg;
66340 sem_params.u.nsems = nsems;
66341 diff --git a/ipc/shm.c b/ipc/shm.c
66342 index b76be5b..859e750 100644
66343 --- a/ipc/shm.c
66344 +++ b/ipc/shm.c
66345 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66346 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66347 #endif
66348
66349 +#ifdef CONFIG_GRKERNSEC
66350 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66351 + const time_t shm_createtime, const uid_t cuid,
66352 + const int shmid);
66353 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66354 + const time_t shm_createtime);
66355 +#endif
66356 +
66357 void shm_init_ns(struct ipc_namespace *ns)
66358 {
66359 ns->shm_ctlmax = SHMMAX;
66360 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66361 shp->shm_lprid = 0;
66362 shp->shm_atim = shp->shm_dtim = 0;
66363 shp->shm_ctim = get_seconds();
66364 +#ifdef CONFIG_GRKERNSEC
66365 + {
66366 + struct timespec timeval;
66367 + do_posix_clock_monotonic_gettime(&timeval);
66368 +
66369 + shp->shm_createtime = timeval.tv_sec;
66370 + }
66371 +#endif
66372 shp->shm_segsz = size;
66373 shp->shm_nattch = 0;
66374 shp->shm_file = file;
66375 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66376 return 0;
66377 }
66378
66379 +static struct ipc_ops shm_ops = {
66380 + .getnew = newseg,
66381 + .associate = shm_security,
66382 + .more_checks = shm_more_checks
66383 +};
66384 +
66385 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66386 {
66387 struct ipc_namespace *ns;
66388 - struct ipc_ops shm_ops;
66389 struct ipc_params shm_params;
66390
66391 ns = current->nsproxy->ipc_ns;
66392
66393 - shm_ops.getnew = newseg;
66394 - shm_ops.associate = shm_security;
66395 - shm_ops.more_checks = shm_more_checks;
66396 -
66397 shm_params.key = key;
66398 shm_params.flg = shmflg;
66399 shm_params.u.size = size;
66400 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
66401 f_mode = FMODE_READ | FMODE_WRITE;
66402 }
66403 if (shmflg & SHM_EXEC) {
66404 +
66405 +#ifdef CONFIG_PAX_MPROTECT
66406 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66407 + goto out;
66408 +#endif
66409 +
66410 prot |= PROT_EXEC;
66411 acc_mode |= S_IXUGO;
66412 }
66413 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
66414 if (err)
66415 goto out_unlock;
66416
66417 +#ifdef CONFIG_GRKERNSEC
66418 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66419 + shp->shm_perm.cuid, shmid) ||
66420 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66421 + err = -EACCES;
66422 + goto out_unlock;
66423 + }
66424 +#endif
66425 +
66426 path = shp->shm_file->f_path;
66427 path_get(&path);
66428 shp->shm_nattch++;
66429 +#ifdef CONFIG_GRKERNSEC
66430 + shp->shm_lapid = current->pid;
66431 +#endif
66432 size = i_size_read(path.dentry->d_inode);
66433 shm_unlock(shp);
66434
66435 diff --git a/kernel/acct.c b/kernel/acct.c
66436 index 02e6167..54824f7 100644
66437 --- a/kernel/acct.c
66438 +++ b/kernel/acct.c
66439 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66440 */
66441 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66442 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66443 - file->f_op->write(file, (char *)&ac,
66444 + file->f_op->write(file, (char __force_user *)&ac,
66445 sizeof(acct_t), &file->f_pos);
66446 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66447 set_fs(fs);
66448 diff --git a/kernel/audit.c b/kernel/audit.c
66449 index bb0eb5b..cf2a03a 100644
66450 --- a/kernel/audit.c
66451 +++ b/kernel/audit.c
66452 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66453 3) suppressed due to audit_rate_limit
66454 4) suppressed due to audit_backlog_limit
66455 */
66456 -static atomic_t audit_lost = ATOMIC_INIT(0);
66457 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66458
66459 /* The netlink socket. */
66460 static struct sock *audit_sock;
66461 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66462 unsigned long now;
66463 int print;
66464
66465 - atomic_inc(&audit_lost);
66466 + atomic_inc_unchecked(&audit_lost);
66467
66468 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66469
66470 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66471 printk(KERN_WARNING
66472 "audit: audit_lost=%d audit_rate_limit=%d "
66473 "audit_backlog_limit=%d\n",
66474 - atomic_read(&audit_lost),
66475 + atomic_read_unchecked(&audit_lost),
66476 audit_rate_limit,
66477 audit_backlog_limit);
66478 audit_panic(message);
66479 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66480 status_set.pid = audit_pid;
66481 status_set.rate_limit = audit_rate_limit;
66482 status_set.backlog_limit = audit_backlog_limit;
66483 - status_set.lost = atomic_read(&audit_lost);
66484 + status_set.lost = atomic_read_unchecked(&audit_lost);
66485 status_set.backlog = skb_queue_len(&audit_skb_queue);
66486 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66487 &status_set, sizeof(status_set));
66488 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66489 index af1de0f..06dfe57 100644
66490 --- a/kernel/auditsc.c
66491 +++ b/kernel/auditsc.c
66492 @@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66493 }
66494
66495 /* global counter which is incremented every time something logs in */
66496 -static atomic_t session_id = ATOMIC_INIT(0);
66497 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66498
66499 /**
66500 * audit_set_loginuid - set current task's audit_context loginuid
66501 @@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
66502 return -EPERM;
66503 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66504
66505 - sessionid = atomic_inc_return(&session_id);
66506 + sessionid = atomic_inc_return_unchecked(&session_id);
66507 if (context && context->in_syscall) {
66508 struct audit_buffer *ab;
66509
66510 diff --git a/kernel/capability.c b/kernel/capability.c
66511 index 3f1adb6..c564db0 100644
66512 --- a/kernel/capability.c
66513 +++ b/kernel/capability.c
66514 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66515 * before modification is attempted and the application
66516 * fails.
66517 */
66518 + if (tocopy > ARRAY_SIZE(kdata))
66519 + return -EFAULT;
66520 +
66521 if (copy_to_user(dataptr, kdata, tocopy
66522 * sizeof(struct __user_cap_data_struct))) {
66523 return -EFAULT;
66524 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66525 int ret;
66526
66527 rcu_read_lock();
66528 - ret = security_capable(__task_cred(t), ns, cap);
66529 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66530 + gr_task_is_capable(t, __task_cred(t), cap);
66531 rcu_read_unlock();
66532
66533 - return (ret == 0);
66534 + return ret;
66535 }
66536
66537 /**
66538 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66539 int ret;
66540
66541 rcu_read_lock();
66542 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66543 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66544 rcu_read_unlock();
66545
66546 - return (ret == 0);
66547 + return ret;
66548 }
66549
66550 /**
66551 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66552 BUG();
66553 }
66554
66555 - if (security_capable(current_cred(), ns, cap) == 0) {
66556 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66557 current->flags |= PF_SUPERPRIV;
66558 return true;
66559 }
66560 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66561 }
66562 EXPORT_SYMBOL(ns_capable);
66563
66564 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66565 +{
66566 + if (unlikely(!cap_valid(cap))) {
66567 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66568 + BUG();
66569 + }
66570 +
66571 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66572 + current->flags |= PF_SUPERPRIV;
66573 + return true;
66574 + }
66575 + return false;
66576 +}
66577 +EXPORT_SYMBOL(ns_capable_nolog);
66578 +
66579 /**
66580 * capable - Determine if the current task has a superior capability in effect
66581 * @cap: The capability to be tested for
66582 @@ -408,6 +427,12 @@ bool capable(int cap)
66583 }
66584 EXPORT_SYMBOL(capable);
66585
66586 +bool capable_nolog(int cap)
66587 +{
66588 + return ns_capable_nolog(&init_user_ns, cap);
66589 +}
66590 +EXPORT_SYMBOL(capable_nolog);
66591 +
66592 /**
66593 * nsown_capable - Check superior capability to one's own user_ns
66594 * @cap: The capability in question
66595 diff --git a/kernel/compat.c b/kernel/compat.c
66596 index f346ced..aa2b1f4 100644
66597 --- a/kernel/compat.c
66598 +++ b/kernel/compat.c
66599 @@ -13,6 +13,7 @@
66600
66601 #include <linux/linkage.h>
66602 #include <linux/compat.h>
66603 +#include <linux/module.h>
66604 #include <linux/errno.h>
66605 #include <linux/time.h>
66606 #include <linux/signal.h>
66607 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66608 mm_segment_t oldfs;
66609 long ret;
66610
66611 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66612 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66613 oldfs = get_fs();
66614 set_fs(KERNEL_DS);
66615 ret = hrtimer_nanosleep_restart(restart);
66616 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66617 oldfs = get_fs();
66618 set_fs(KERNEL_DS);
66619 ret = hrtimer_nanosleep(&tu,
66620 - rmtp ? (struct timespec __user *)&rmt : NULL,
66621 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66622 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66623 set_fs(oldfs);
66624
66625 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66626 mm_segment_t old_fs = get_fs();
66627
66628 set_fs(KERNEL_DS);
66629 - ret = sys_sigpending((old_sigset_t __user *) &s);
66630 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66631 set_fs(old_fs);
66632 if (ret == 0)
66633 ret = put_user(s, set);
66634 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
66635 old_fs = get_fs();
66636 set_fs(KERNEL_DS);
66637 ret = sys_sigprocmask(how,
66638 - set ? (old_sigset_t __user *) &s : NULL,
66639 - oset ? (old_sigset_t __user *) &s : NULL);
66640 + set ? (old_sigset_t __force_user *) &s : NULL,
66641 + oset ? (old_sigset_t __force_user *) &s : NULL);
66642 set_fs(old_fs);
66643 if (ret == 0)
66644 if (oset)
66645 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66646 mm_segment_t old_fs = get_fs();
66647
66648 set_fs(KERNEL_DS);
66649 - ret = sys_old_getrlimit(resource, &r);
66650 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66651 set_fs(old_fs);
66652
66653 if (!ret) {
66654 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66655 mm_segment_t old_fs = get_fs();
66656
66657 set_fs(KERNEL_DS);
66658 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66659 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66660 set_fs(old_fs);
66661
66662 if (ret)
66663 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66664 set_fs (KERNEL_DS);
66665 ret = sys_wait4(pid,
66666 (stat_addr ?
66667 - (unsigned int __user *) &status : NULL),
66668 - options, (struct rusage __user *) &r);
66669 + (unsigned int __force_user *) &status : NULL),
66670 + options, (struct rusage __force_user *) &r);
66671 set_fs (old_fs);
66672
66673 if (ret > 0) {
66674 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66675 memset(&info, 0, sizeof(info));
66676
66677 set_fs(KERNEL_DS);
66678 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66679 - uru ? (struct rusage __user *)&ru : NULL);
66680 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66681 + uru ? (struct rusage __force_user *)&ru : NULL);
66682 set_fs(old_fs);
66683
66684 if ((ret < 0) || (info.si_signo == 0))
66685 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66686 oldfs = get_fs();
66687 set_fs(KERNEL_DS);
66688 err = sys_timer_settime(timer_id, flags,
66689 - (struct itimerspec __user *) &newts,
66690 - (struct itimerspec __user *) &oldts);
66691 + (struct itimerspec __force_user *) &newts,
66692 + (struct itimerspec __force_user *) &oldts);
66693 set_fs(oldfs);
66694 if (!err && old && put_compat_itimerspec(old, &oldts))
66695 return -EFAULT;
66696 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66697 oldfs = get_fs();
66698 set_fs(KERNEL_DS);
66699 err = sys_timer_gettime(timer_id,
66700 - (struct itimerspec __user *) &ts);
66701 + (struct itimerspec __force_user *) &ts);
66702 set_fs(oldfs);
66703 if (!err && put_compat_itimerspec(setting, &ts))
66704 return -EFAULT;
66705 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66706 oldfs = get_fs();
66707 set_fs(KERNEL_DS);
66708 err = sys_clock_settime(which_clock,
66709 - (struct timespec __user *) &ts);
66710 + (struct timespec __force_user *) &ts);
66711 set_fs(oldfs);
66712 return err;
66713 }
66714 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66715 oldfs = get_fs();
66716 set_fs(KERNEL_DS);
66717 err = sys_clock_gettime(which_clock,
66718 - (struct timespec __user *) &ts);
66719 + (struct timespec __force_user *) &ts);
66720 set_fs(oldfs);
66721 if (!err && put_compat_timespec(&ts, tp))
66722 return -EFAULT;
66723 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66724
66725 oldfs = get_fs();
66726 set_fs(KERNEL_DS);
66727 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66728 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66729 set_fs(oldfs);
66730
66731 err = compat_put_timex(utp, &txc);
66732 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66733 oldfs = get_fs();
66734 set_fs(KERNEL_DS);
66735 err = sys_clock_getres(which_clock,
66736 - (struct timespec __user *) &ts);
66737 + (struct timespec __force_user *) &ts);
66738 set_fs(oldfs);
66739 if (!err && tp && put_compat_timespec(&ts, tp))
66740 return -EFAULT;
66741 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66742 long err;
66743 mm_segment_t oldfs;
66744 struct timespec tu;
66745 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66746 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66747
66748 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66749 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66750 oldfs = get_fs();
66751 set_fs(KERNEL_DS);
66752 err = clock_nanosleep_restart(restart);
66753 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66754 oldfs = get_fs();
66755 set_fs(KERNEL_DS);
66756 err = sys_clock_nanosleep(which_clock, flags,
66757 - (struct timespec __user *) &in,
66758 - (struct timespec __user *) &out);
66759 + (struct timespec __force_user *) &in,
66760 + (struct timespec __force_user *) &out);
66761 set_fs(oldfs);
66762
66763 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66764 diff --git a/kernel/configs.c b/kernel/configs.c
66765 index 42e8fa0..9e7406b 100644
66766 --- a/kernel/configs.c
66767 +++ b/kernel/configs.c
66768 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66769 struct proc_dir_entry *entry;
66770
66771 /* create the current config file */
66772 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66773 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66774 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66775 + &ikconfig_file_ops);
66776 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66777 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66778 + &ikconfig_file_ops);
66779 +#endif
66780 +#else
66781 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66782 &ikconfig_file_ops);
66783 +#endif
66784 +
66785 if (!entry)
66786 return -ENOMEM;
66787
66788 diff --git a/kernel/cred.c b/kernel/cred.c
66789 index 48c6fd3..8398912 100644
66790 --- a/kernel/cred.c
66791 +++ b/kernel/cred.c
66792 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
66793 validate_creds(cred);
66794 put_cred(cred);
66795 }
66796 +
66797 +#ifdef CONFIG_GRKERNSEC_SETXID
66798 + cred = (struct cred *) tsk->delayed_cred;
66799 + if (cred) {
66800 + tsk->delayed_cred = NULL;
66801 + validate_creds(cred);
66802 + put_cred(cred);
66803 + }
66804 +#endif
66805 }
66806
66807 /**
66808 @@ -472,7 +481,7 @@ error_put:
66809 * Always returns 0 thus allowing this function to be tail-called at the end
66810 * of, say, sys_setgid().
66811 */
66812 -int commit_creds(struct cred *new)
66813 +static int __commit_creds(struct cred *new)
66814 {
66815 struct task_struct *task = current;
66816 const struct cred *old = task->real_cred;
66817 @@ -491,6 +500,8 @@ int commit_creds(struct cred *new)
66818
66819 get_cred(new); /* we will require a ref for the subj creds too */
66820
66821 + gr_set_role_label(task, new->uid, new->gid);
66822 +
66823 /* dumpability changes */
66824 if (old->euid != new->euid ||
66825 old->egid != new->egid ||
66826 @@ -540,6 +551,101 @@ int commit_creds(struct cred *new)
66827 put_cred(old);
66828 return 0;
66829 }
66830 +#ifdef CONFIG_GRKERNSEC_SETXID
66831 +extern int set_user(struct cred *new);
66832 +
66833 +void gr_delayed_cred_worker(void)
66834 +{
66835 + const struct cred *new = current->delayed_cred;
66836 + struct cred *ncred;
66837 +
66838 + current->delayed_cred = NULL;
66839 +
66840 + if (current_uid() && new != NULL) {
66841 + // from doing get_cred on it when queueing this
66842 + put_cred(new);
66843 + return;
66844 + } else if (new == NULL)
66845 + return;
66846 +
66847 + ncred = prepare_creds();
66848 + if (!ncred)
66849 + goto die;
66850 + // uids
66851 + ncred->uid = new->uid;
66852 + ncred->euid = new->euid;
66853 + ncred->suid = new->suid;
66854 + ncred->fsuid = new->fsuid;
66855 + // gids
66856 + ncred->gid = new->gid;
66857 + ncred->egid = new->egid;
66858 + ncred->sgid = new->sgid;
66859 + ncred->fsgid = new->fsgid;
66860 + // groups
66861 + if (set_groups(ncred, new->group_info) < 0) {
66862 + abort_creds(ncred);
66863 + goto die;
66864 + }
66865 + // caps
66866 + ncred->securebits = new->securebits;
66867 + ncred->cap_inheritable = new->cap_inheritable;
66868 + ncred->cap_permitted = new->cap_permitted;
66869 + ncred->cap_effective = new->cap_effective;
66870 + ncred->cap_bset = new->cap_bset;
66871 +
66872 + if (set_user(ncred)) {
66873 + abort_creds(ncred);
66874 + goto die;
66875 + }
66876 +
66877 + // from doing get_cred on it when queueing this
66878 + put_cred(new);
66879 +
66880 + __commit_creds(ncred);
66881 + return;
66882 +die:
66883 + // from doing get_cred on it when queueing this
66884 + put_cred(new);
66885 + do_group_exit(SIGKILL);
66886 +}
66887 +#endif
66888 +
66889 +int commit_creds(struct cred *new)
66890 +{
66891 +#ifdef CONFIG_GRKERNSEC_SETXID
66892 + int ret;
66893 + int schedule_it = 0;
66894 + struct task_struct *t;
66895 +
66896 + /* we won't get called with tasklist_lock held for writing
66897 + and interrupts disabled as the cred struct in that case is
66898 + init_cred
66899 + */
66900 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66901 + !current_uid() && new->uid) {
66902 + schedule_it = 1;
66903 + }
66904 + ret = __commit_creds(new);
66905 + if (schedule_it) {
66906 + rcu_read_lock();
66907 + read_lock(&tasklist_lock);
66908 + for (t = next_thread(current); t != current;
66909 + t = next_thread(t)) {
66910 + if (t->delayed_cred == NULL) {
66911 + t->delayed_cred = get_cred(new);
66912 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66913 + set_tsk_need_resched(t);
66914 + }
66915 + }
66916 + read_unlock(&tasklist_lock);
66917 + rcu_read_unlock();
66918 + }
66919 + return ret;
66920 +#else
66921 + return __commit_creds(new);
66922 +#endif
66923 +}
66924 +
66925 EXPORT_SYMBOL(commit_creds);
66926
66927 /**
66928 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66929 index 7fda904..59f620c 100644
66930 --- a/kernel/debug/debug_core.c
66931 +++ b/kernel/debug/debug_core.c
66932 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66933 */
66934 static atomic_t masters_in_kgdb;
66935 static atomic_t slaves_in_kgdb;
66936 -static atomic_t kgdb_break_tasklet_var;
66937 +static atomic_unchecked_t kgdb_break_tasklet_var;
66938 atomic_t kgdb_setting_breakpoint;
66939
66940 struct task_struct *kgdb_usethread;
66941 @@ -129,7 +129,7 @@ int kgdb_single_step;
66942 static pid_t kgdb_sstep_pid;
66943
66944 /* to keep track of the CPU which is doing the single stepping*/
66945 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66946 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66947
66948 /*
66949 * If you are debugging a problem where roundup (the collection of
66950 @@ -537,7 +537,7 @@ return_normal:
66951 * kernel will only try for the value of sstep_tries before
66952 * giving up and continuing on.
66953 */
66954 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66955 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66956 (kgdb_info[cpu].task &&
66957 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66958 atomic_set(&kgdb_active, -1);
66959 @@ -631,8 +631,8 @@ cpu_master_loop:
66960 }
66961
66962 kgdb_restore:
66963 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66964 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66965 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66966 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66967 if (kgdb_info[sstep_cpu].task)
66968 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66969 else
66970 @@ -829,18 +829,18 @@ static void kgdb_unregister_callbacks(void)
66971 static void kgdb_tasklet_bpt(unsigned long ing)
66972 {
66973 kgdb_breakpoint();
66974 - atomic_set(&kgdb_break_tasklet_var, 0);
66975 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66976 }
66977
66978 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66979
66980 void kgdb_schedule_breakpoint(void)
66981 {
66982 - if (atomic_read(&kgdb_break_tasklet_var) ||
66983 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66984 atomic_read(&kgdb_active) != -1 ||
66985 atomic_read(&kgdb_setting_breakpoint))
66986 return;
66987 - atomic_inc(&kgdb_break_tasklet_var);
66988 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66989 tasklet_schedule(&kgdb_tasklet_breakpoint);
66990 }
66991 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66992 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66993 index e2ae734..08a4c5c 100644
66994 --- a/kernel/debug/kdb/kdb_main.c
66995 +++ b/kernel/debug/kdb/kdb_main.c
66996 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
66997 list_for_each_entry(mod, kdb_modules, list) {
66998
66999 kdb_printf("%-20s%8u 0x%p ", mod->name,
67000 - mod->core_size, (void *)mod);
67001 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67002 #ifdef CONFIG_MODULE_UNLOAD
67003 kdb_printf("%4ld ", module_refcount(mod));
67004 #endif
67005 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
67006 kdb_printf(" (Loading)");
67007 else
67008 kdb_printf(" (Live)");
67009 - kdb_printf(" 0x%p", mod->module_core);
67010 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67011
67012 #ifdef CONFIG_MODULE_UNLOAD
67013 {
67014 diff --git a/kernel/events/core.c b/kernel/events/core.c
67015 index 1b5c081..c375f83 100644
67016 --- a/kernel/events/core.c
67017 +++ b/kernel/events/core.c
67018 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67019 return 0;
67020 }
67021
67022 -static atomic64_t perf_event_id;
67023 +static atomic64_unchecked_t perf_event_id;
67024
67025 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67026 enum event_type_t event_type);
67027 @@ -2581,7 +2581,7 @@ static void __perf_event_read(void *info)
67028
67029 static inline u64 perf_event_count(struct perf_event *event)
67030 {
67031 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67032 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67033 }
67034
67035 static u64 perf_event_read(struct perf_event *event)
67036 @@ -2897,9 +2897,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67037 mutex_lock(&event->child_mutex);
67038 total += perf_event_read(event);
67039 *enabled += event->total_time_enabled +
67040 - atomic64_read(&event->child_total_time_enabled);
67041 + atomic64_read_unchecked(&event->child_total_time_enabled);
67042 *running += event->total_time_running +
67043 - atomic64_read(&event->child_total_time_running);
67044 + atomic64_read_unchecked(&event->child_total_time_running);
67045
67046 list_for_each_entry(child, &event->child_list, child_list) {
67047 total += perf_event_read(child);
67048 @@ -3306,10 +3306,10 @@ void perf_event_update_userpage(struct perf_event *event)
67049 userpg->offset -= local64_read(&event->hw.prev_count);
67050
67051 userpg->time_enabled = enabled +
67052 - atomic64_read(&event->child_total_time_enabled);
67053 + atomic64_read_unchecked(&event->child_total_time_enabled);
67054
67055 userpg->time_running = running +
67056 - atomic64_read(&event->child_total_time_running);
67057 + atomic64_read_unchecked(&event->child_total_time_running);
67058
67059 barrier();
67060 ++userpg->lock;
67061 @@ -3738,11 +3738,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67062 values[n++] = perf_event_count(event);
67063 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67064 values[n++] = enabled +
67065 - atomic64_read(&event->child_total_time_enabled);
67066 + atomic64_read_unchecked(&event->child_total_time_enabled);
67067 }
67068 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67069 values[n++] = running +
67070 - atomic64_read(&event->child_total_time_running);
67071 + atomic64_read_unchecked(&event->child_total_time_running);
67072 }
67073 if (read_format & PERF_FORMAT_ID)
67074 values[n++] = primary_event_id(event);
67075 @@ -4393,12 +4393,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67076 * need to add enough zero bytes after the string to handle
67077 * the 64bit alignment we do later.
67078 */
67079 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67080 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67081 if (!buf) {
67082 name = strncpy(tmp, "//enomem", sizeof(tmp));
67083 goto got_name;
67084 }
67085 - name = d_path(&file->f_path, buf, PATH_MAX);
67086 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67087 if (IS_ERR(name)) {
67088 name = strncpy(tmp, "//toolong", sizeof(tmp));
67089 goto got_name;
67090 @@ -5765,7 +5765,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67091 event->parent = parent_event;
67092
67093 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67094 - event->id = atomic64_inc_return(&perf_event_id);
67095 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67096
67097 event->state = PERF_EVENT_STATE_INACTIVE;
67098
67099 @@ -6287,10 +6287,10 @@ static void sync_child_event(struct perf_event *child_event,
67100 /*
67101 * Add back the child's count to the parent's count:
67102 */
67103 - atomic64_add(child_val, &parent_event->child_count);
67104 - atomic64_add(child_event->total_time_enabled,
67105 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67106 + atomic64_add_unchecked(child_event->total_time_enabled,
67107 &parent_event->child_total_time_enabled);
67108 - atomic64_add(child_event->total_time_running,
67109 + atomic64_add_unchecked(child_event->total_time_running,
67110 &parent_event->child_total_time_running);
67111
67112 /*
67113 diff --git a/kernel/exit.c b/kernel/exit.c
67114 index 46c8b14..d868958 100644
67115 --- a/kernel/exit.c
67116 +++ b/kernel/exit.c
67117 @@ -58,6 +58,10 @@
67118 #include <asm/pgtable.h>
67119 #include <asm/mmu_context.h>
67120
67121 +#ifdef CONFIG_GRKERNSEC
67122 +extern rwlock_t grsec_exec_file_lock;
67123 +#endif
67124 +
67125 static void exit_mm(struct task_struct * tsk);
67126
67127 static void __unhash_process(struct task_struct *p, bool group_dead)
67128 @@ -169,6 +173,10 @@ void release_task(struct task_struct * p)
67129 struct task_struct *leader;
67130 int zap_leader;
67131 repeat:
67132 +#ifdef CONFIG_NET
67133 + gr_del_task_from_ip_table(p);
67134 +#endif
67135 +
67136 /* don't need to get the RCU readlock here - the process is dead and
67137 * can't be modifying its own credentials. But shut RCU-lockdep up */
67138 rcu_read_lock();
67139 @@ -381,7 +389,7 @@ int allow_signal(int sig)
67140 * know it'll be handled, so that they don't get converted to
67141 * SIGKILL or just silently dropped.
67142 */
67143 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67144 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67145 recalc_sigpending();
67146 spin_unlock_irq(&current->sighand->siglock);
67147 return 0;
67148 @@ -417,6 +425,17 @@ void daemonize(const char *name, ...)
67149 vsnprintf(current->comm, sizeof(current->comm), name, args);
67150 va_end(args);
67151
67152 +#ifdef CONFIG_GRKERNSEC
67153 + write_lock(&grsec_exec_file_lock);
67154 + if (current->exec_file) {
67155 + fput(current->exec_file);
67156 + current->exec_file = NULL;
67157 + }
67158 + write_unlock(&grsec_exec_file_lock);
67159 +#endif
67160 +
67161 + gr_set_kernel_label(current);
67162 +
67163 /*
67164 * If we were started as result of loading a module, close all of the
67165 * user space pages. We don't need them, and if we didn't close them
67166 @@ -873,6 +892,8 @@ void do_exit(long code)
67167 struct task_struct *tsk = current;
67168 int group_dead;
67169
67170 + set_fs(USER_DS);
67171 +
67172 profile_task_exit(tsk);
67173
67174 WARN_ON(blk_needs_flush_plug(tsk));
67175 @@ -889,7 +910,6 @@ void do_exit(long code)
67176 * mm_release()->clear_child_tid() from writing to a user-controlled
67177 * kernel address.
67178 */
67179 - set_fs(USER_DS);
67180
67181 ptrace_event(PTRACE_EVENT_EXIT, code);
67182
67183 @@ -950,6 +970,9 @@ void do_exit(long code)
67184 tsk->exit_code = code;
67185 taskstats_exit(tsk, group_dead);
67186
67187 + gr_acl_handle_psacct(tsk, code);
67188 + gr_acl_handle_exit();
67189 +
67190 exit_mm(tsk);
67191
67192 if (group_dead)
67193 @@ -1066,7 +1089,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67194 * Take down every thread in the group. This is called by fatal signals
67195 * as well as by sys_exit_group (below).
67196 */
67197 -void
67198 +__noreturn void
67199 do_group_exit(int exit_code)
67200 {
67201 struct signal_struct *sig = current->signal;
67202 diff --git a/kernel/fork.c b/kernel/fork.c
67203 index 26a7a67..a1053f9 100644
67204 --- a/kernel/fork.c
67205 +++ b/kernel/fork.c
67206 @@ -284,7 +284,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67207 *stackend = STACK_END_MAGIC; /* for overflow detection */
67208
67209 #ifdef CONFIG_CC_STACKPROTECTOR
67210 - tsk->stack_canary = get_random_int();
67211 + tsk->stack_canary = pax_get_random_long();
67212 #endif
67213
67214 /*
67215 @@ -308,13 +308,77 @@ out:
67216 }
67217
67218 #ifdef CONFIG_MMU
67219 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
67220 +{
67221 + struct vm_area_struct *tmp;
67222 + unsigned long charge;
67223 + struct mempolicy *pol;
67224 + struct file *file;
67225 +
67226 + charge = 0;
67227 + if (mpnt->vm_flags & VM_ACCOUNT) {
67228 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67229 + if (security_vm_enough_memory(len))
67230 + goto fail_nomem;
67231 + charge = len;
67232 + }
67233 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67234 + if (!tmp)
67235 + goto fail_nomem;
67236 + *tmp = *mpnt;
67237 + tmp->vm_mm = mm;
67238 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67239 + pol = mpol_dup(vma_policy(mpnt));
67240 + if (IS_ERR(pol))
67241 + goto fail_nomem_policy;
67242 + vma_set_policy(tmp, pol);
67243 + if (anon_vma_fork(tmp, mpnt))
67244 + goto fail_nomem_anon_vma_fork;
67245 + tmp->vm_flags &= ~VM_LOCKED;
67246 + tmp->vm_next = tmp->vm_prev = NULL;
67247 + tmp->vm_mirror = NULL;
67248 + file = tmp->vm_file;
67249 + if (file) {
67250 + struct inode *inode = file->f_path.dentry->d_inode;
67251 + struct address_space *mapping = file->f_mapping;
67252 +
67253 + get_file(file);
67254 + if (tmp->vm_flags & VM_DENYWRITE)
67255 + atomic_dec(&inode->i_writecount);
67256 + mutex_lock(&mapping->i_mmap_mutex);
67257 + if (tmp->vm_flags & VM_SHARED)
67258 + mapping->i_mmap_writable++;
67259 + flush_dcache_mmap_lock(mapping);
67260 + /* insert tmp into the share list, just after mpnt */
67261 + vma_prio_tree_add(tmp, mpnt);
67262 + flush_dcache_mmap_unlock(mapping);
67263 + mutex_unlock(&mapping->i_mmap_mutex);
67264 + }
67265 +
67266 + /*
67267 + * Clear hugetlb-related page reserves for children. This only
67268 + * affects MAP_PRIVATE mappings. Faults generated by the child
67269 + * are not guaranteed to succeed, even if read-only
67270 + */
67271 + if (is_vm_hugetlb_page(tmp))
67272 + reset_vma_resv_huge_pages(tmp);
67273 +
67274 + return tmp;
67275 +
67276 +fail_nomem_anon_vma_fork:
67277 + mpol_put(pol);
67278 +fail_nomem_policy:
67279 + kmem_cache_free(vm_area_cachep, tmp);
67280 +fail_nomem:
67281 + vm_unacct_memory(charge);
67282 + return NULL;
67283 +}
67284 +
67285 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67286 {
67287 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67288 struct rb_node **rb_link, *rb_parent;
67289 int retval;
67290 - unsigned long charge;
67291 - struct mempolicy *pol;
67292
67293 down_write(&oldmm->mmap_sem);
67294 flush_cache_dup_mm(oldmm);
67295 @@ -326,8 +390,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67296 mm->locked_vm = 0;
67297 mm->mmap = NULL;
67298 mm->mmap_cache = NULL;
67299 - mm->free_area_cache = oldmm->mmap_base;
67300 - mm->cached_hole_size = ~0UL;
67301 + mm->free_area_cache = oldmm->free_area_cache;
67302 + mm->cached_hole_size = oldmm->cached_hole_size;
67303 mm->map_count = 0;
67304 cpumask_clear(mm_cpumask(mm));
67305 mm->mm_rb = RB_ROOT;
67306 @@ -343,8 +407,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67307
67308 prev = NULL;
67309 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67310 - struct file *file;
67311 -
67312 if (mpnt->vm_flags & VM_DONTCOPY) {
67313 long pages = vma_pages(mpnt);
67314 mm->total_vm -= pages;
67315 @@ -352,53 +414,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67316 -pages);
67317 continue;
67318 }
67319 - charge = 0;
67320 - if (mpnt->vm_flags & VM_ACCOUNT) {
67321 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67322 - if (security_vm_enough_memory(len))
67323 - goto fail_nomem;
67324 - charge = len;
67325 + tmp = dup_vma(mm, mpnt);
67326 + if (!tmp) {
67327 + retval = -ENOMEM;
67328 + goto out;
67329 }
67330 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67331 - if (!tmp)
67332 - goto fail_nomem;
67333 - *tmp = *mpnt;
67334 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67335 - pol = mpol_dup(vma_policy(mpnt));
67336 - retval = PTR_ERR(pol);
67337 - if (IS_ERR(pol))
67338 - goto fail_nomem_policy;
67339 - vma_set_policy(tmp, pol);
67340 - tmp->vm_mm = mm;
67341 - if (anon_vma_fork(tmp, mpnt))
67342 - goto fail_nomem_anon_vma_fork;
67343 - tmp->vm_flags &= ~VM_LOCKED;
67344 - tmp->vm_next = tmp->vm_prev = NULL;
67345 - file = tmp->vm_file;
67346 - if (file) {
67347 - struct inode *inode = file->f_path.dentry->d_inode;
67348 - struct address_space *mapping = file->f_mapping;
67349 -
67350 - get_file(file);
67351 - if (tmp->vm_flags & VM_DENYWRITE)
67352 - atomic_dec(&inode->i_writecount);
67353 - mutex_lock(&mapping->i_mmap_mutex);
67354 - if (tmp->vm_flags & VM_SHARED)
67355 - mapping->i_mmap_writable++;
67356 - flush_dcache_mmap_lock(mapping);
67357 - /* insert tmp into the share list, just after mpnt */
67358 - vma_prio_tree_add(tmp, mpnt);
67359 - flush_dcache_mmap_unlock(mapping);
67360 - mutex_unlock(&mapping->i_mmap_mutex);
67361 - }
67362 -
67363 - /*
67364 - * Clear hugetlb-related page reserves for children. This only
67365 - * affects MAP_PRIVATE mappings. Faults generated by the child
67366 - * are not guaranteed to succeed, even if read-only
67367 - */
67368 - if (is_vm_hugetlb_page(tmp))
67369 - reset_vma_resv_huge_pages(tmp);
67370
67371 /*
67372 * Link in the new vma and copy the page table entries.
67373 @@ -421,6 +441,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67374 if (retval)
67375 goto out;
67376 }
67377 +
67378 +#ifdef CONFIG_PAX_SEGMEXEC
67379 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67380 + struct vm_area_struct *mpnt_m;
67381 +
67382 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67383 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67384 +
67385 + if (!mpnt->vm_mirror)
67386 + continue;
67387 +
67388 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67389 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67390 + mpnt->vm_mirror = mpnt_m;
67391 + } else {
67392 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67393 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67394 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67395 + mpnt->vm_mirror->vm_mirror = mpnt;
67396 + }
67397 + }
67398 + BUG_ON(mpnt_m);
67399 + }
67400 +#endif
67401 +
67402 /* a new mm has just been created */
67403 arch_dup_mmap(oldmm, mm);
67404 retval = 0;
67405 @@ -429,14 +474,6 @@ out:
67406 flush_tlb_mm(oldmm);
67407 up_write(&oldmm->mmap_sem);
67408 return retval;
67409 -fail_nomem_anon_vma_fork:
67410 - mpol_put(pol);
67411 -fail_nomem_policy:
67412 - kmem_cache_free(vm_area_cachep, tmp);
67413 -fail_nomem:
67414 - retval = -ENOMEM;
67415 - vm_unacct_memory(charge);
67416 - goto out;
67417 }
67418
67419 static inline int mm_alloc_pgd(struct mm_struct *mm)
67420 @@ -658,8 +695,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67421 return ERR_PTR(err);
67422
67423 mm = get_task_mm(task);
67424 - if (mm && mm != current->mm &&
67425 - !ptrace_may_access(task, mode)) {
67426 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67427 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67428 mmput(mm);
67429 mm = ERR_PTR(-EACCES);
67430 }
67431 @@ -881,13 +918,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67432 spin_unlock(&fs->lock);
67433 return -EAGAIN;
67434 }
67435 - fs->users++;
67436 + atomic_inc(&fs->users);
67437 spin_unlock(&fs->lock);
67438 return 0;
67439 }
67440 tsk->fs = copy_fs_struct(fs);
67441 if (!tsk->fs)
67442 return -ENOMEM;
67443 + gr_set_chroot_entries(tsk, &tsk->fs->root);
67444 return 0;
67445 }
67446
67447 @@ -1151,6 +1189,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67448 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67449 #endif
67450 retval = -EAGAIN;
67451 +
67452 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67453 +
67454 if (atomic_read(&p->real_cred->user->processes) >=
67455 task_rlimit(p, RLIMIT_NPROC)) {
67456 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67457 @@ -1306,6 +1347,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67458 if (clone_flags & CLONE_THREAD)
67459 p->tgid = current->tgid;
67460
67461 + gr_copy_label(p);
67462 +
67463 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
67464 /*
67465 * Clear TID on mm_release()?
67466 @@ -1472,6 +1515,8 @@ bad_fork_cleanup_count:
67467 bad_fork_free:
67468 free_task(p);
67469 fork_out:
67470 + gr_log_forkfail(retval);
67471 +
67472 return ERR_PTR(retval);
67473 }
67474
67475 @@ -1572,6 +1617,8 @@ long do_fork(unsigned long clone_flags,
67476 if (clone_flags & CLONE_PARENT_SETTID)
67477 put_user(nr, parent_tidptr);
67478
67479 + gr_handle_brute_check();
67480 +
67481 if (clone_flags & CLONE_VFORK) {
67482 p->vfork_done = &vfork;
67483 init_completion(&vfork);
67484 @@ -1670,7 +1717,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67485 return 0;
67486
67487 /* don't need lock here; in the worst case we'll do useless copy */
67488 - if (fs->users == 1)
67489 + if (atomic_read(&fs->users) == 1)
67490 return 0;
67491
67492 *new_fsp = copy_fs_struct(fs);
67493 @@ -1759,7 +1806,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67494 fs = current->fs;
67495 spin_lock(&fs->lock);
67496 current->fs = new_fs;
67497 - if (--fs->users)
67498 + gr_set_chroot_entries(current, &current->fs->root);
67499 + if (atomic_dec_return(&fs->users))
67500 new_fs = NULL;
67501 else
67502 new_fs = fs;
67503 diff --git a/kernel/futex.c b/kernel/futex.c
67504 index 866c9d5..5c5f828 100644
67505 --- a/kernel/futex.c
67506 +++ b/kernel/futex.c
67507 @@ -54,6 +54,7 @@
67508 #include <linux/mount.h>
67509 #include <linux/pagemap.h>
67510 #include <linux/syscalls.h>
67511 +#include <linux/ptrace.h>
67512 #include <linux/signal.h>
67513 #include <linux/export.h>
67514 #include <linux/magic.h>
67515 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67516 struct page *page, *page_head;
67517 int err, ro = 0;
67518
67519 +#ifdef CONFIG_PAX_SEGMEXEC
67520 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67521 + return -EFAULT;
67522 +#endif
67523 +
67524 /*
67525 * The futex address must be "naturally" aligned.
67526 */
67527 @@ -2721,6 +2727,7 @@ static int __init futex_init(void)
67528 {
67529 u32 curval;
67530 int i;
67531 + mm_segment_t oldfs;
67532
67533 /*
67534 * This will fail and we want it. Some arch implementations do
67535 @@ -2732,8 +2739,11 @@ static int __init futex_init(void)
67536 * implementation, the non-functional ones will return
67537 * -ENOSYS.
67538 */
67539 + oldfs = get_fs();
67540 + set_fs(USER_DS);
67541 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67542 futex_cmpxchg_enabled = 1;
67543 + set_fs(oldfs);
67544
67545 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67546 plist_head_init(&futex_queues[i].chain);
67547 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67548 index 9b22d03..6295b62 100644
67549 --- a/kernel/gcov/base.c
67550 +++ b/kernel/gcov/base.c
67551 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67552 }
67553
67554 #ifdef CONFIG_MODULES
67555 -static inline int within(void *addr, void *start, unsigned long size)
67556 -{
67557 - return ((addr >= start) && (addr < start + size));
67558 -}
67559 -
67560 /* Update list and generate events when modules are unloaded. */
67561 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67562 void *data)
67563 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67564 prev = NULL;
67565 /* Remove entries located in module from linked list. */
67566 for (info = gcov_info_head; info; info = info->next) {
67567 - if (within(info, mod->module_core, mod->core_size)) {
67568 + if (within_module_core_rw((unsigned long)info, mod)) {
67569 if (prev)
67570 prev->next = info->next;
67571 else
67572 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67573 index ae34bf5..4e2f3d0 100644
67574 --- a/kernel/hrtimer.c
67575 +++ b/kernel/hrtimer.c
67576 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
67577 local_irq_restore(flags);
67578 }
67579
67580 -static void run_hrtimer_softirq(struct softirq_action *h)
67581 +static void run_hrtimer_softirq(void)
67582 {
67583 hrtimer_peek_ahead_timers();
67584 }
67585 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67586 index 01d3b70..9e4d098 100644
67587 --- a/kernel/jump_label.c
67588 +++ b/kernel/jump_label.c
67589 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67590
67591 size = (((unsigned long)stop - (unsigned long)start)
67592 / sizeof(struct jump_entry));
67593 + pax_open_kernel();
67594 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67595 + pax_close_kernel();
67596 }
67597
67598 static void jump_label_update(struct jump_label_key *key, int enable);
67599 @@ -340,10 +342,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67600 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67601 struct jump_entry *iter;
67602
67603 + pax_open_kernel();
67604 for (iter = iter_start; iter < iter_stop; iter++) {
67605 if (within_module_init(iter->code, mod))
67606 iter->code = 0;
67607 }
67608 + pax_close_kernel();
67609 }
67610
67611 static int
67612 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67613 index 079f1d3..a407562 100644
67614 --- a/kernel/kallsyms.c
67615 +++ b/kernel/kallsyms.c
67616 @@ -11,6 +11,9 @@
67617 * Changed the compression method from stem compression to "table lookup"
67618 * compression (see scripts/kallsyms.c for a more complete description)
67619 */
67620 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67621 +#define __INCLUDED_BY_HIDESYM 1
67622 +#endif
67623 #include <linux/kallsyms.h>
67624 #include <linux/module.h>
67625 #include <linux/init.h>
67626 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67627
67628 static inline int is_kernel_inittext(unsigned long addr)
67629 {
67630 + if (system_state != SYSTEM_BOOTING)
67631 + return 0;
67632 +
67633 if (addr >= (unsigned long)_sinittext
67634 && addr <= (unsigned long)_einittext)
67635 return 1;
67636 return 0;
67637 }
67638
67639 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67640 +#ifdef CONFIG_MODULES
67641 +static inline int is_module_text(unsigned long addr)
67642 +{
67643 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67644 + return 1;
67645 +
67646 + addr = ktla_ktva(addr);
67647 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67648 +}
67649 +#else
67650 +static inline int is_module_text(unsigned long addr)
67651 +{
67652 + return 0;
67653 +}
67654 +#endif
67655 +#endif
67656 +
67657 static inline int is_kernel_text(unsigned long addr)
67658 {
67659 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67660 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67661
67662 static inline int is_kernel(unsigned long addr)
67663 {
67664 +
67665 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67666 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67667 + return 1;
67668 +
67669 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67670 +#else
67671 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67672 +#endif
67673 +
67674 return 1;
67675 return in_gate_area_no_mm(addr);
67676 }
67677
67678 static int is_ksym_addr(unsigned long addr)
67679 {
67680 +
67681 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67682 + if (is_module_text(addr))
67683 + return 0;
67684 +#endif
67685 +
67686 if (all_var)
67687 return is_kernel(addr);
67688
67689 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67690
67691 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67692 {
67693 - iter->name[0] = '\0';
67694 iter->nameoff = get_symbol_offset(new_pos);
67695 iter->pos = new_pos;
67696 }
67697 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
67698 {
67699 struct kallsym_iter *iter = m->private;
67700
67701 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67702 + if (current_uid())
67703 + return 0;
67704 +#endif
67705 +
67706 /* Some debugging symbols have no name. Ignore them. */
67707 if (!iter->name[0])
67708 return 0;
67709 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67710 struct kallsym_iter *iter;
67711 int ret;
67712
67713 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67714 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67715 if (!iter)
67716 return -ENOMEM;
67717 reset_iter(iter, 0);
67718 diff --git a/kernel/kexec.c b/kernel/kexec.c
67719 index 7b08867..3bac516 100644
67720 --- a/kernel/kexec.c
67721 +++ b/kernel/kexec.c
67722 @@ -1047,7 +1047,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67723 unsigned long flags)
67724 {
67725 struct compat_kexec_segment in;
67726 - struct kexec_segment out, __user *ksegments;
67727 + struct kexec_segment out;
67728 + struct kexec_segment __user *ksegments;
67729 unsigned long i, result;
67730
67731 /* Don't allow clients that don't understand the native
67732 diff --git a/kernel/kmod.c b/kernel/kmod.c
67733 index a3a46cb..f2e42f8 100644
67734 --- a/kernel/kmod.c
67735 +++ b/kernel/kmod.c
67736 @@ -75,13 +75,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
67737 * If module auto-loading support is disabled then this function
67738 * becomes a no-operation.
67739 */
67740 -int __request_module(bool wait, const char *fmt, ...)
67741 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67742 {
67743 - va_list args;
67744 char module_name[MODULE_NAME_LEN];
67745 unsigned int max_modprobes;
67746 int ret;
67747 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
67748 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
67749 static char *envp[] = { "HOME=/",
67750 "TERM=linux",
67751 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
67752 @@ -90,9 +89,7 @@ int __request_module(bool wait, const char *fmt, ...)
67753 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67754 static int kmod_loop_msg;
67755
67756 - va_start(args, fmt);
67757 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67758 - va_end(args);
67759 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67760 if (ret >= MODULE_NAME_LEN)
67761 return -ENAMETOOLONG;
67762
67763 @@ -100,6 +97,20 @@ int __request_module(bool wait, const char *fmt, ...)
67764 if (ret)
67765 return ret;
67766
67767 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67768 + if (!current_uid()) {
67769 + /* hack to workaround consolekit/udisks stupidity */
67770 + read_lock(&tasklist_lock);
67771 + if (!strcmp(current->comm, "mount") &&
67772 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67773 + read_unlock(&tasklist_lock);
67774 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67775 + return -EPERM;
67776 + }
67777 + read_unlock(&tasklist_lock);
67778 + }
67779 +#endif
67780 +
67781 /* If modprobe needs a service that is in a module, we get a recursive
67782 * loop. Limit the number of running kmod threads to max_threads/2 or
67783 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67784 @@ -135,6 +146,47 @@ int __request_module(bool wait, const char *fmt, ...)
67785 atomic_dec(&kmod_concurrent);
67786 return ret;
67787 }
67788 +
67789 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67790 +{
67791 + va_list args;
67792 + int ret;
67793 +
67794 + va_start(args, fmt);
67795 + ret = ____request_module(wait, module_param, fmt, args);
67796 + va_end(args);
67797 +
67798 + return ret;
67799 +}
67800 +
67801 +int __request_module(bool wait, const char *fmt, ...)
67802 +{
67803 + va_list args;
67804 + int ret;
67805 +
67806 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67807 + if (current_uid()) {
67808 + char module_param[MODULE_NAME_LEN];
67809 +
67810 + memset(module_param, 0, sizeof(module_param));
67811 +
67812 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67813 +
67814 + va_start(args, fmt);
67815 + ret = ____request_module(wait, module_param, fmt, args);
67816 + va_end(args);
67817 +
67818 + return ret;
67819 + }
67820 +#endif
67821 +
67822 + va_start(args, fmt);
67823 + ret = ____request_module(wait, NULL, fmt, args);
67824 + va_end(args);
67825 +
67826 + return ret;
67827 +}
67828 +
67829 EXPORT_SYMBOL(__request_module);
67830 #endif /* CONFIG_MODULES */
67831
67832 @@ -224,7 +276,7 @@ static int wait_for_helper(void *data)
67833 *
67834 * Thus the __user pointer cast is valid here.
67835 */
67836 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67837 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67838
67839 /*
67840 * If ret is 0, either ____call_usermodehelper failed and the
67841 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67842 index c62b854..cb67968 100644
67843 --- a/kernel/kprobes.c
67844 +++ b/kernel/kprobes.c
67845 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67846 * kernel image and loaded module images reside. This is required
67847 * so x86_64 can correctly handle the %rip-relative fixups.
67848 */
67849 - kip->insns = module_alloc(PAGE_SIZE);
67850 + kip->insns = module_alloc_exec(PAGE_SIZE);
67851 if (!kip->insns) {
67852 kfree(kip);
67853 return NULL;
67854 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67855 */
67856 if (!list_is_singular(&kip->list)) {
67857 list_del(&kip->list);
67858 - module_free(NULL, kip->insns);
67859 + module_free_exec(NULL, kip->insns);
67860 kfree(kip);
67861 }
67862 return 1;
67863 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67864 {
67865 int i, err = 0;
67866 unsigned long offset = 0, size = 0;
67867 - char *modname, namebuf[128];
67868 + char *modname, namebuf[KSYM_NAME_LEN];
67869 const char *symbol_name;
67870 void *addr;
67871 struct kprobe_blackpoint *kb;
67872 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67873 const char *sym = NULL;
67874 unsigned int i = *(loff_t *) v;
67875 unsigned long offset = 0;
67876 - char *modname, namebuf[128];
67877 + char *modname, namebuf[KSYM_NAME_LEN];
67878
67879 head = &kprobe_table[i];
67880 preempt_disable();
67881 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67882 index 4e316e1..5501eef 100644
67883 --- a/kernel/ksysfs.c
67884 +++ b/kernel/ksysfs.c
67885 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67886 {
67887 if (count+1 > UEVENT_HELPER_PATH_LEN)
67888 return -ENOENT;
67889 + if (!capable(CAP_SYS_ADMIN))
67890 + return -EPERM;
67891 memcpy(uevent_helper, buf, count);
67892 uevent_helper[count] = '\0';
67893 if (count && uevent_helper[count-1] == '\n')
67894 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67895 index 8889f7d..95319b7 100644
67896 --- a/kernel/lockdep.c
67897 +++ b/kernel/lockdep.c
67898 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67899 end = (unsigned long) &_end,
67900 addr = (unsigned long) obj;
67901
67902 +#ifdef CONFIG_PAX_KERNEXEC
67903 + start = ktla_ktva(start);
67904 +#endif
67905 +
67906 /*
67907 * static variable?
67908 */
67909 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67910 if (!static_obj(lock->key)) {
67911 debug_locks_off();
67912 printk("INFO: trying to register non-static key.\n");
67913 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67914 printk("the code is fine but needs lockdep annotation.\n");
67915 printk("turning off the locking correctness validator.\n");
67916 dump_stack();
67917 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67918 if (!class)
67919 return 0;
67920 }
67921 - atomic_inc((atomic_t *)&class->ops);
67922 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67923 if (very_verbose(class)) {
67924 printk("\nacquire class [%p] %s", class->key, class->name);
67925 if (class->name_version > 1)
67926 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67927 index 91c32a0..b2c71c5 100644
67928 --- a/kernel/lockdep_proc.c
67929 +++ b/kernel/lockdep_proc.c
67930 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67931
67932 static void print_name(struct seq_file *m, struct lock_class *class)
67933 {
67934 - char str[128];
67935 + char str[KSYM_NAME_LEN];
67936 const char *name = class->name;
67937
67938 if (!name) {
67939 diff --git a/kernel/module.c b/kernel/module.c
67940 index 3d56b6f..2a22bd0 100644
67941 --- a/kernel/module.c
67942 +++ b/kernel/module.c
67943 @@ -58,6 +58,7 @@
67944 #include <linux/jump_label.h>
67945 #include <linux/pfn.h>
67946 #include <linux/bsearch.h>
67947 +#include <linux/grsecurity.h>
67948
67949 #define CREATE_TRACE_POINTS
67950 #include <trace/events/module.h>
67951 @@ -113,7 +114,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67952
67953 /* Bounds of module allocation, for speeding __module_address.
67954 * Protected by module_mutex. */
67955 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67956 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67957 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67958
67959 int register_module_notifier(struct notifier_block * nb)
67960 {
67961 @@ -277,7 +279,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67962 return true;
67963
67964 list_for_each_entry_rcu(mod, &modules, list) {
67965 - struct symsearch arr[] = {
67966 + struct symsearch modarr[] = {
67967 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67968 NOT_GPL_ONLY, false },
67969 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67970 @@ -299,7 +301,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67971 #endif
67972 };
67973
67974 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67975 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67976 return true;
67977 }
67978 return false;
67979 @@ -431,7 +433,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67980 static int percpu_modalloc(struct module *mod,
67981 unsigned long size, unsigned long align)
67982 {
67983 - if (align > PAGE_SIZE) {
67984 + if (align-1 >= PAGE_SIZE) {
67985 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67986 mod->name, align, PAGE_SIZE);
67987 align = PAGE_SIZE;
67988 @@ -1001,7 +1003,7 @@ struct module_attribute module_uevent =
67989 static ssize_t show_coresize(struct module_attribute *mattr,
67990 struct module_kobject *mk, char *buffer)
67991 {
67992 - return sprintf(buffer, "%u\n", mk->mod->core_size);
67993 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67994 }
67995
67996 static struct module_attribute modinfo_coresize =
67997 @@ -1010,7 +1012,7 @@ static struct module_attribute modinfo_coresize =
67998 static ssize_t show_initsize(struct module_attribute *mattr,
67999 struct module_kobject *mk, char *buffer)
68000 {
68001 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68002 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68003 }
68004
68005 static struct module_attribute modinfo_initsize =
68006 @@ -1224,7 +1226,7 @@ resolve_symbol_wait(struct module *mod,
68007 */
68008 #ifdef CONFIG_SYSFS
68009
68010 -#ifdef CONFIG_KALLSYMS
68011 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68012 static inline bool sect_empty(const Elf_Shdr *sect)
68013 {
68014 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68015 @@ -1690,21 +1692,21 @@ static void set_section_ro_nx(void *base,
68016
68017 static void unset_module_core_ro_nx(struct module *mod)
68018 {
68019 - set_page_attributes(mod->module_core + mod->core_text_size,
68020 - mod->module_core + mod->core_size,
68021 + set_page_attributes(mod->module_core_rw,
68022 + mod->module_core_rw + mod->core_size_rw,
68023 set_memory_x);
68024 - set_page_attributes(mod->module_core,
68025 - mod->module_core + mod->core_ro_size,
68026 + set_page_attributes(mod->module_core_rx,
68027 + mod->module_core_rx + mod->core_size_rx,
68028 set_memory_rw);
68029 }
68030
68031 static void unset_module_init_ro_nx(struct module *mod)
68032 {
68033 - set_page_attributes(mod->module_init + mod->init_text_size,
68034 - mod->module_init + mod->init_size,
68035 + set_page_attributes(mod->module_init_rw,
68036 + mod->module_init_rw + mod->init_size_rw,
68037 set_memory_x);
68038 - set_page_attributes(mod->module_init,
68039 - mod->module_init + mod->init_ro_size,
68040 + set_page_attributes(mod->module_init_rx,
68041 + mod->module_init_rx + mod->init_size_rx,
68042 set_memory_rw);
68043 }
68044
68045 @@ -1715,14 +1717,14 @@ void set_all_modules_text_rw(void)
68046
68047 mutex_lock(&module_mutex);
68048 list_for_each_entry_rcu(mod, &modules, list) {
68049 - if ((mod->module_core) && (mod->core_text_size)) {
68050 - set_page_attributes(mod->module_core,
68051 - mod->module_core + mod->core_text_size,
68052 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68053 + set_page_attributes(mod->module_core_rx,
68054 + mod->module_core_rx + mod->core_size_rx,
68055 set_memory_rw);
68056 }
68057 - if ((mod->module_init) && (mod->init_text_size)) {
68058 - set_page_attributes(mod->module_init,
68059 - mod->module_init + mod->init_text_size,
68060 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68061 + set_page_attributes(mod->module_init_rx,
68062 + mod->module_init_rx + mod->init_size_rx,
68063 set_memory_rw);
68064 }
68065 }
68066 @@ -1736,14 +1738,14 @@ void set_all_modules_text_ro(void)
68067
68068 mutex_lock(&module_mutex);
68069 list_for_each_entry_rcu(mod, &modules, list) {
68070 - if ((mod->module_core) && (mod->core_text_size)) {
68071 - set_page_attributes(mod->module_core,
68072 - mod->module_core + mod->core_text_size,
68073 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68074 + set_page_attributes(mod->module_core_rx,
68075 + mod->module_core_rx + mod->core_size_rx,
68076 set_memory_ro);
68077 }
68078 - if ((mod->module_init) && (mod->init_text_size)) {
68079 - set_page_attributes(mod->module_init,
68080 - mod->module_init + mod->init_text_size,
68081 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68082 + set_page_attributes(mod->module_init_rx,
68083 + mod->module_init_rx + mod->init_size_rx,
68084 set_memory_ro);
68085 }
68086 }
68087 @@ -1789,16 +1791,19 @@ static void free_module(struct module *mod)
68088
68089 /* This may be NULL, but that's OK */
68090 unset_module_init_ro_nx(mod);
68091 - module_free(mod, mod->module_init);
68092 + module_free(mod, mod->module_init_rw);
68093 + module_free_exec(mod, mod->module_init_rx);
68094 kfree(mod->args);
68095 percpu_modfree(mod);
68096
68097 /* Free lock-classes: */
68098 - lockdep_free_key_range(mod->module_core, mod->core_size);
68099 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68100 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68101
68102 /* Finally, free the core (containing the module structure) */
68103 unset_module_core_ro_nx(mod);
68104 - module_free(mod, mod->module_core);
68105 + module_free_exec(mod, mod->module_core_rx);
68106 + module_free(mod, mod->module_core_rw);
68107
68108 #ifdef CONFIG_MPU
68109 update_protections(current->mm);
68110 @@ -1867,10 +1872,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68111 unsigned int i;
68112 int ret = 0;
68113 const struct kernel_symbol *ksym;
68114 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68115 + int is_fs_load = 0;
68116 + int register_filesystem_found = 0;
68117 + char *p;
68118 +
68119 + p = strstr(mod->args, "grsec_modharden_fs");
68120 + if (p) {
68121 + char *endptr = p + strlen("grsec_modharden_fs");
68122 + /* copy \0 as well */
68123 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68124 + is_fs_load = 1;
68125 + }
68126 +#endif
68127
68128 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68129 const char *name = info->strtab + sym[i].st_name;
68130
68131 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68132 + /* it's a real shame this will never get ripped and copied
68133 + upstream! ;(
68134 + */
68135 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68136 + register_filesystem_found = 1;
68137 +#endif
68138 +
68139 switch (sym[i].st_shndx) {
68140 case SHN_COMMON:
68141 /* We compiled with -fno-common. These are not
68142 @@ -1891,7 +1917,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68143 ksym = resolve_symbol_wait(mod, info, name);
68144 /* Ok if resolved. */
68145 if (ksym && !IS_ERR(ksym)) {
68146 + pax_open_kernel();
68147 sym[i].st_value = ksym->value;
68148 + pax_close_kernel();
68149 break;
68150 }
68151
68152 @@ -1910,11 +1938,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68153 secbase = (unsigned long)mod_percpu(mod);
68154 else
68155 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68156 + pax_open_kernel();
68157 sym[i].st_value += secbase;
68158 + pax_close_kernel();
68159 break;
68160 }
68161 }
68162
68163 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68164 + if (is_fs_load && !register_filesystem_found) {
68165 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68166 + ret = -EPERM;
68167 + }
68168 +#endif
68169 +
68170 return ret;
68171 }
68172
68173 @@ -2018,22 +2055,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68174 || s->sh_entsize != ~0UL
68175 || strstarts(sname, ".init"))
68176 continue;
68177 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68178 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68179 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68180 + else
68181 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68182 pr_debug("\t%s\n", sname);
68183 }
68184 - switch (m) {
68185 - case 0: /* executable */
68186 - mod->core_size = debug_align(mod->core_size);
68187 - mod->core_text_size = mod->core_size;
68188 - break;
68189 - case 1: /* RO: text and ro-data */
68190 - mod->core_size = debug_align(mod->core_size);
68191 - mod->core_ro_size = mod->core_size;
68192 - break;
68193 - case 3: /* whole core */
68194 - mod->core_size = debug_align(mod->core_size);
68195 - break;
68196 - }
68197 }
68198
68199 pr_debug("Init section allocation order:\n");
68200 @@ -2047,23 +2074,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68201 || s->sh_entsize != ~0UL
68202 || !strstarts(sname, ".init"))
68203 continue;
68204 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68205 - | INIT_OFFSET_MASK);
68206 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68207 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68208 + else
68209 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68210 + s->sh_entsize |= INIT_OFFSET_MASK;
68211 pr_debug("\t%s\n", sname);
68212 }
68213 - switch (m) {
68214 - case 0: /* executable */
68215 - mod->init_size = debug_align(mod->init_size);
68216 - mod->init_text_size = mod->init_size;
68217 - break;
68218 - case 1: /* RO: text and ro-data */
68219 - mod->init_size = debug_align(mod->init_size);
68220 - mod->init_ro_size = mod->init_size;
68221 - break;
68222 - case 3: /* whole init */
68223 - mod->init_size = debug_align(mod->init_size);
68224 - break;
68225 - }
68226 }
68227 }
68228
68229 @@ -2235,7 +2252,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68230
68231 /* Put symbol section at end of init part of module. */
68232 symsect->sh_flags |= SHF_ALLOC;
68233 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68234 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68235 info->index.sym) | INIT_OFFSET_MASK;
68236 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68237
68238 @@ -2250,13 +2267,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68239 }
68240
68241 /* Append room for core symbols at end of core part. */
68242 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68243 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68244 - mod->core_size += strtab_size;
68245 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68246 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68247 + mod->core_size_rx += strtab_size;
68248
68249 /* Put string table section at end of init part of module. */
68250 strsect->sh_flags |= SHF_ALLOC;
68251 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68252 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68253 info->index.str) | INIT_OFFSET_MASK;
68254 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68255 }
68256 @@ -2274,12 +2291,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68257 /* Make sure we get permanent strtab: don't use info->strtab. */
68258 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68259
68260 + pax_open_kernel();
68261 +
68262 /* Set types up while we still have access to sections. */
68263 for (i = 0; i < mod->num_symtab; i++)
68264 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68265
68266 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68267 - mod->core_strtab = s = mod->module_core + info->stroffs;
68268 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68269 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68270 src = mod->symtab;
68271 *dst = *src;
68272 *s++ = 0;
68273 @@ -2292,6 +2311,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68274 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68275 }
68276 mod->core_num_syms = ndst;
68277 +
68278 + pax_close_kernel();
68279 }
68280 #else
68281 static inline void layout_symtab(struct module *mod, struct load_info *info)
68282 @@ -2325,17 +2346,33 @@ void * __weak module_alloc(unsigned long size)
68283 return size == 0 ? NULL : vmalloc_exec(size);
68284 }
68285
68286 -static void *module_alloc_update_bounds(unsigned long size)
68287 +static void *module_alloc_update_bounds_rw(unsigned long size)
68288 {
68289 void *ret = module_alloc(size);
68290
68291 if (ret) {
68292 mutex_lock(&module_mutex);
68293 /* Update module bounds. */
68294 - if ((unsigned long)ret < module_addr_min)
68295 - module_addr_min = (unsigned long)ret;
68296 - if ((unsigned long)ret + size > module_addr_max)
68297 - module_addr_max = (unsigned long)ret + size;
68298 + if ((unsigned long)ret < module_addr_min_rw)
68299 + module_addr_min_rw = (unsigned long)ret;
68300 + if ((unsigned long)ret + size > module_addr_max_rw)
68301 + module_addr_max_rw = (unsigned long)ret + size;
68302 + mutex_unlock(&module_mutex);
68303 + }
68304 + return ret;
68305 +}
68306 +
68307 +static void *module_alloc_update_bounds_rx(unsigned long size)
68308 +{
68309 + void *ret = module_alloc_exec(size);
68310 +
68311 + if (ret) {
68312 + mutex_lock(&module_mutex);
68313 + /* Update module bounds. */
68314 + if ((unsigned long)ret < module_addr_min_rx)
68315 + module_addr_min_rx = (unsigned long)ret;
68316 + if ((unsigned long)ret + size > module_addr_max_rx)
68317 + module_addr_max_rx = (unsigned long)ret + size;
68318 mutex_unlock(&module_mutex);
68319 }
68320 return ret;
68321 @@ -2512,8 +2549,14 @@ static struct module *setup_load_info(struct load_info *info)
68322 static int check_modinfo(struct module *mod, struct load_info *info)
68323 {
68324 const char *modmagic = get_modinfo(info, "vermagic");
68325 + const char *license = get_modinfo(info, "license");
68326 int err;
68327
68328 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68329 + if (!license || !license_is_gpl_compatible(license))
68330 + return -ENOEXEC;
68331 +#endif
68332 +
68333 /* This is allowed: modprobe --force will invalidate it. */
68334 if (!modmagic) {
68335 err = try_to_force_load(mod, "bad vermagic");
68336 @@ -2536,7 +2579,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68337 }
68338
68339 /* Set up license info based on the info section */
68340 - set_license(mod, get_modinfo(info, "license"));
68341 + set_license(mod, license);
68342
68343 return 0;
68344 }
68345 @@ -2630,7 +2673,7 @@ static int move_module(struct module *mod, struct load_info *info)
68346 void *ptr;
68347
68348 /* Do the allocs. */
68349 - ptr = module_alloc_update_bounds(mod->core_size);
68350 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68351 /*
68352 * The pointer to this block is stored in the module structure
68353 * which is inside the block. Just mark it as not being a
68354 @@ -2640,23 +2683,50 @@ static int move_module(struct module *mod, struct load_info *info)
68355 if (!ptr)
68356 return -ENOMEM;
68357
68358 - memset(ptr, 0, mod->core_size);
68359 - mod->module_core = ptr;
68360 + memset(ptr, 0, mod->core_size_rw);
68361 + mod->module_core_rw = ptr;
68362
68363 - ptr = module_alloc_update_bounds(mod->init_size);
68364 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68365 /*
68366 * The pointer to this block is stored in the module structure
68367 * which is inside the block. This block doesn't need to be
68368 * scanned as it contains data and code that will be freed
68369 * after the module is initialized.
68370 */
68371 - kmemleak_ignore(ptr);
68372 - if (!ptr && mod->init_size) {
68373 - module_free(mod, mod->module_core);
68374 + kmemleak_not_leak(ptr);
68375 + if (!ptr && mod->init_size_rw) {
68376 + module_free(mod, mod->module_core_rw);
68377 return -ENOMEM;
68378 }
68379 - memset(ptr, 0, mod->init_size);
68380 - mod->module_init = ptr;
68381 + memset(ptr, 0, mod->init_size_rw);
68382 + mod->module_init_rw = ptr;
68383 +
68384 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68385 + kmemleak_not_leak(ptr);
68386 + if (!ptr) {
68387 + module_free(mod, mod->module_init_rw);
68388 + module_free(mod, mod->module_core_rw);
68389 + return -ENOMEM;
68390 + }
68391 +
68392 + pax_open_kernel();
68393 + memset(ptr, 0, mod->core_size_rx);
68394 + pax_close_kernel();
68395 + mod->module_core_rx = ptr;
68396 +
68397 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68398 + kmemleak_not_leak(ptr);
68399 + if (!ptr && mod->init_size_rx) {
68400 + module_free_exec(mod, mod->module_core_rx);
68401 + module_free(mod, mod->module_init_rw);
68402 + module_free(mod, mod->module_core_rw);
68403 + return -ENOMEM;
68404 + }
68405 +
68406 + pax_open_kernel();
68407 + memset(ptr, 0, mod->init_size_rx);
68408 + pax_close_kernel();
68409 + mod->module_init_rx = ptr;
68410
68411 /* Transfer each section which specifies SHF_ALLOC */
68412 pr_debug("final section addresses:\n");
68413 @@ -2667,16 +2737,45 @@ static int move_module(struct module *mod, struct load_info *info)
68414 if (!(shdr->sh_flags & SHF_ALLOC))
68415 continue;
68416
68417 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68418 - dest = mod->module_init
68419 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68420 - else
68421 - dest = mod->module_core + shdr->sh_entsize;
68422 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68423 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68424 + dest = mod->module_init_rw
68425 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68426 + else
68427 + dest = mod->module_init_rx
68428 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68429 + } else {
68430 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68431 + dest = mod->module_core_rw + shdr->sh_entsize;
68432 + else
68433 + dest = mod->module_core_rx + shdr->sh_entsize;
68434 + }
68435 +
68436 + if (shdr->sh_type != SHT_NOBITS) {
68437 +
68438 +#ifdef CONFIG_PAX_KERNEXEC
68439 +#ifdef CONFIG_X86_64
68440 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68441 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68442 +#endif
68443 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68444 + pax_open_kernel();
68445 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68446 + pax_close_kernel();
68447 + } else
68448 +#endif
68449
68450 - if (shdr->sh_type != SHT_NOBITS)
68451 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68452 + }
68453 /* Update sh_addr to point to copy in image. */
68454 - shdr->sh_addr = (unsigned long)dest;
68455 +
68456 +#ifdef CONFIG_PAX_KERNEXEC
68457 + if (shdr->sh_flags & SHF_EXECINSTR)
68458 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68459 + else
68460 +#endif
68461 +
68462 + shdr->sh_addr = (unsigned long)dest;
68463 pr_debug("\t0x%lx %s\n",
68464 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68465 }
68466 @@ -2727,12 +2826,12 @@ static void flush_module_icache(const struct module *mod)
68467 * Do it before processing of module parameters, so the module
68468 * can provide parameter accessor functions of its own.
68469 */
68470 - if (mod->module_init)
68471 - flush_icache_range((unsigned long)mod->module_init,
68472 - (unsigned long)mod->module_init
68473 - + mod->init_size);
68474 - flush_icache_range((unsigned long)mod->module_core,
68475 - (unsigned long)mod->module_core + mod->core_size);
68476 + if (mod->module_init_rx)
68477 + flush_icache_range((unsigned long)mod->module_init_rx,
68478 + (unsigned long)mod->module_init_rx
68479 + + mod->init_size_rx);
68480 + flush_icache_range((unsigned long)mod->module_core_rx,
68481 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68482
68483 set_fs(old_fs);
68484 }
68485 @@ -2802,8 +2901,10 @@ out:
68486 static void module_deallocate(struct module *mod, struct load_info *info)
68487 {
68488 percpu_modfree(mod);
68489 - module_free(mod, mod->module_init);
68490 - module_free(mod, mod->module_core);
68491 + module_free_exec(mod, mod->module_init_rx);
68492 + module_free_exec(mod, mod->module_core_rx);
68493 + module_free(mod, mod->module_init_rw);
68494 + module_free(mod, mod->module_core_rw);
68495 }
68496
68497 int __weak module_finalize(const Elf_Ehdr *hdr,
68498 @@ -2867,9 +2968,38 @@ static struct module *load_module(void __user *umod,
68499 if (err)
68500 goto free_unload;
68501
68502 + /* Now copy in args */
68503 + mod->args = strndup_user(uargs, ~0UL >> 1);
68504 + if (IS_ERR(mod->args)) {
68505 + err = PTR_ERR(mod->args);
68506 + goto free_unload;
68507 + }
68508 +
68509 /* Set up MODINFO_ATTR fields */
68510 setup_modinfo(mod, &info);
68511
68512 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68513 + {
68514 + char *p, *p2;
68515 +
68516 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68517 + 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);
68518 + err = -EPERM;
68519 + goto free_modinfo;
68520 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68521 + p += strlen("grsec_modharden_normal");
68522 + p2 = strstr(p, "_");
68523 + if (p2) {
68524 + *p2 = '\0';
68525 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68526 + *p2 = '_';
68527 + }
68528 + err = -EPERM;
68529 + goto free_modinfo;
68530 + }
68531 + }
68532 +#endif
68533 +
68534 /* Fix up syms, so that st_value is a pointer to location. */
68535 err = simplify_symbols(mod, &info);
68536 if (err < 0)
68537 @@ -2885,13 +3015,6 @@ static struct module *load_module(void __user *umod,
68538
68539 flush_module_icache(mod);
68540
68541 - /* Now copy in args */
68542 - mod->args = strndup_user(uargs, ~0UL >> 1);
68543 - if (IS_ERR(mod->args)) {
68544 - err = PTR_ERR(mod->args);
68545 - goto free_arch_cleanup;
68546 - }
68547 -
68548 /* Mark state as coming so strong_try_module_get() ignores us. */
68549 mod->state = MODULE_STATE_COMING;
68550
68551 @@ -2948,11 +3071,10 @@ static struct module *load_module(void __user *umod,
68552 unlock:
68553 mutex_unlock(&module_mutex);
68554 synchronize_sched();
68555 - kfree(mod->args);
68556 - free_arch_cleanup:
68557 module_arch_cleanup(mod);
68558 free_modinfo:
68559 free_modinfo(mod);
68560 + kfree(mod->args);
68561 free_unload:
68562 module_unload_free(mod);
68563 free_module:
68564 @@ -2993,16 +3115,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68565 MODULE_STATE_COMING, mod);
68566
68567 /* Set RO and NX regions for core */
68568 - set_section_ro_nx(mod->module_core,
68569 - mod->core_text_size,
68570 - mod->core_ro_size,
68571 - mod->core_size);
68572 + set_section_ro_nx(mod->module_core_rx,
68573 + mod->core_size_rx,
68574 + mod->core_size_rx,
68575 + mod->core_size_rx);
68576
68577 /* Set RO and NX regions for init */
68578 - set_section_ro_nx(mod->module_init,
68579 - mod->init_text_size,
68580 - mod->init_ro_size,
68581 - mod->init_size);
68582 + set_section_ro_nx(mod->module_init_rx,
68583 + mod->init_size_rx,
68584 + mod->init_size_rx,
68585 + mod->init_size_rx);
68586
68587 do_mod_ctors(mod);
68588 /* Start the module */
68589 @@ -3048,11 +3170,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68590 mod->strtab = mod->core_strtab;
68591 #endif
68592 unset_module_init_ro_nx(mod);
68593 - module_free(mod, mod->module_init);
68594 - mod->module_init = NULL;
68595 - mod->init_size = 0;
68596 - mod->init_ro_size = 0;
68597 - mod->init_text_size = 0;
68598 + module_free(mod, mod->module_init_rw);
68599 + module_free_exec(mod, mod->module_init_rx);
68600 + mod->module_init_rw = NULL;
68601 + mod->module_init_rx = NULL;
68602 + mod->init_size_rw = 0;
68603 + mod->init_size_rx = 0;
68604 mutex_unlock(&module_mutex);
68605
68606 return 0;
68607 @@ -3083,10 +3206,16 @@ static const char *get_ksymbol(struct module *mod,
68608 unsigned long nextval;
68609
68610 /* At worse, next value is at end of module */
68611 - if (within_module_init(addr, mod))
68612 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68613 + if (within_module_init_rx(addr, mod))
68614 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68615 + else if (within_module_init_rw(addr, mod))
68616 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68617 + else if (within_module_core_rx(addr, mod))
68618 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68619 + else if (within_module_core_rw(addr, mod))
68620 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68621 else
68622 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68623 + return NULL;
68624
68625 /* Scan for closest preceding symbol, and next symbol. (ELF
68626 starts real symbols at 1). */
68627 @@ -3321,7 +3450,7 @@ static int m_show(struct seq_file *m, void *p)
68628 char buf[8];
68629
68630 seq_printf(m, "%s %u",
68631 - mod->name, mod->init_size + mod->core_size);
68632 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68633 print_unload_info(m, mod);
68634
68635 /* Informative for users. */
68636 @@ -3330,7 +3459,7 @@ static int m_show(struct seq_file *m, void *p)
68637 mod->state == MODULE_STATE_COMING ? "Loading":
68638 "Live");
68639 /* Used by oprofile and other similar tools. */
68640 - seq_printf(m, " 0x%pK", mod->module_core);
68641 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68642
68643 /* Taints info */
68644 if (mod->taints)
68645 @@ -3366,7 +3495,17 @@ static const struct file_operations proc_modules_operations = {
68646
68647 static int __init proc_modules_init(void)
68648 {
68649 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68650 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68651 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68652 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68653 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68654 +#else
68655 proc_create("modules", 0, NULL, &proc_modules_operations);
68656 +#endif
68657 +#else
68658 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68659 +#endif
68660 return 0;
68661 }
68662 module_init(proc_modules_init);
68663 @@ -3425,12 +3564,12 @@ struct module *__module_address(unsigned long addr)
68664 {
68665 struct module *mod;
68666
68667 - if (addr < module_addr_min || addr > module_addr_max)
68668 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68669 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68670 return NULL;
68671
68672 list_for_each_entry_rcu(mod, &modules, list)
68673 - if (within_module_core(addr, mod)
68674 - || within_module_init(addr, mod))
68675 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68676 return mod;
68677 return NULL;
68678 }
68679 @@ -3464,11 +3603,20 @@ bool is_module_text_address(unsigned long addr)
68680 */
68681 struct module *__module_text_address(unsigned long addr)
68682 {
68683 - struct module *mod = __module_address(addr);
68684 + struct module *mod;
68685 +
68686 +#ifdef CONFIG_X86_32
68687 + addr = ktla_ktva(addr);
68688 +#endif
68689 +
68690 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68691 + return NULL;
68692 +
68693 + mod = __module_address(addr);
68694 +
68695 if (mod) {
68696 /* Make sure it's within the text section. */
68697 - if (!within(addr, mod->module_init, mod->init_text_size)
68698 - && !within(addr, mod->module_core, mod->core_text_size))
68699 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68700 mod = NULL;
68701 }
68702 return mod;
68703 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68704 index 7e3443f..b2a1e6b 100644
68705 --- a/kernel/mutex-debug.c
68706 +++ b/kernel/mutex-debug.c
68707 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68708 }
68709
68710 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68711 - struct thread_info *ti)
68712 + struct task_struct *task)
68713 {
68714 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68715
68716 /* Mark the current thread as blocked on the lock: */
68717 - ti->task->blocked_on = waiter;
68718 + task->blocked_on = waiter;
68719 }
68720
68721 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68722 - struct thread_info *ti)
68723 + struct task_struct *task)
68724 {
68725 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68726 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68727 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68728 - ti->task->blocked_on = NULL;
68729 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68730 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68731 + task->blocked_on = NULL;
68732
68733 list_del_init(&waiter->list);
68734 waiter->task = NULL;
68735 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68736 index 0799fd3..d06ae3b 100644
68737 --- a/kernel/mutex-debug.h
68738 +++ b/kernel/mutex-debug.h
68739 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68740 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68741 extern void debug_mutex_add_waiter(struct mutex *lock,
68742 struct mutex_waiter *waiter,
68743 - struct thread_info *ti);
68744 + struct task_struct *task);
68745 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68746 - struct thread_info *ti);
68747 + struct task_struct *task);
68748 extern void debug_mutex_unlock(struct mutex *lock);
68749 extern void debug_mutex_init(struct mutex *lock, const char *name,
68750 struct lock_class_key *key);
68751 diff --git a/kernel/mutex.c b/kernel/mutex.c
68752 index 89096dd..f91ebc5 100644
68753 --- a/kernel/mutex.c
68754 +++ b/kernel/mutex.c
68755 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68756 spin_lock_mutex(&lock->wait_lock, flags);
68757
68758 debug_mutex_lock_common(lock, &waiter);
68759 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68760 + debug_mutex_add_waiter(lock, &waiter, task);
68761
68762 /* add waiting tasks to the end of the waitqueue (FIFO): */
68763 list_add_tail(&waiter.list, &lock->wait_list);
68764 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68765 * TASK_UNINTERRUPTIBLE case.)
68766 */
68767 if (unlikely(signal_pending_state(state, task))) {
68768 - mutex_remove_waiter(lock, &waiter,
68769 - task_thread_info(task));
68770 + mutex_remove_waiter(lock, &waiter, task);
68771 mutex_release(&lock->dep_map, 1, ip);
68772 spin_unlock_mutex(&lock->wait_lock, flags);
68773
68774 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68775 done:
68776 lock_acquired(&lock->dep_map, ip);
68777 /* got the lock - rejoice! */
68778 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68779 + mutex_remove_waiter(lock, &waiter, task);
68780 mutex_set_owner(lock);
68781
68782 /* set it to 0 if there are no waiters left: */
68783 diff --git a/kernel/padata.c b/kernel/padata.c
68784 index b452599..5d68f4e 100644
68785 --- a/kernel/padata.c
68786 +++ b/kernel/padata.c
68787 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
68788 padata->pd = pd;
68789 padata->cb_cpu = cb_cpu;
68790
68791 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
68792 - atomic_set(&pd->seq_nr, -1);
68793 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
68794 + atomic_set_unchecked(&pd->seq_nr, -1);
68795
68796 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
68797 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
68798
68799 target_cpu = padata_cpu_hash(padata);
68800 queue = per_cpu_ptr(pd->pqueue, target_cpu);
68801 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
68802 padata_init_pqueues(pd);
68803 padata_init_squeues(pd);
68804 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
68805 - atomic_set(&pd->seq_nr, -1);
68806 + atomic_set_unchecked(&pd->seq_nr, -1);
68807 atomic_set(&pd->reorder_objects, 0);
68808 atomic_set(&pd->refcnt, 0);
68809 pd->pinst = pinst;
68810 diff --git a/kernel/panic.c b/kernel/panic.c
68811 index 8ed89a1..e83856a 100644
68812 --- a/kernel/panic.c
68813 +++ b/kernel/panic.c
68814 @@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68815 const char *board;
68816
68817 printk(KERN_WARNING "------------[ cut here ]------------\n");
68818 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68819 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68820 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68821 if (board)
68822 printk(KERN_WARNING "Hardware name: %s\n", board);
68823 @@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68824 */
68825 void __stack_chk_fail(void)
68826 {
68827 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68828 + dump_stack();
68829 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68830 __builtin_return_address(0));
68831 }
68832 EXPORT_SYMBOL(__stack_chk_fail);
68833 diff --git a/kernel/pid.c b/kernel/pid.c
68834 index 9f08dfa..6765c40 100644
68835 --- a/kernel/pid.c
68836 +++ b/kernel/pid.c
68837 @@ -33,6 +33,7 @@
68838 #include <linux/rculist.h>
68839 #include <linux/bootmem.h>
68840 #include <linux/hash.h>
68841 +#include <linux/security.h>
68842 #include <linux/pid_namespace.h>
68843 #include <linux/init_task.h>
68844 #include <linux/syscalls.h>
68845 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68846
68847 int pid_max = PID_MAX_DEFAULT;
68848
68849 -#define RESERVED_PIDS 300
68850 +#define RESERVED_PIDS 500
68851
68852 int pid_max_min = RESERVED_PIDS + 1;
68853 int pid_max_max = PID_MAX_LIMIT;
68854 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68855 */
68856 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68857 {
68858 + struct task_struct *task;
68859 +
68860 rcu_lockdep_assert(rcu_read_lock_held(),
68861 "find_task_by_pid_ns() needs rcu_read_lock()"
68862 " protection");
68863 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68864 +
68865 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68866 +
68867 + if (gr_pid_is_chrooted(task))
68868 + return NULL;
68869 +
68870 + return task;
68871 }
68872
68873 struct task_struct *find_task_by_vpid(pid_t vnr)
68874 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68875 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68876 }
68877
68878 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68879 +{
68880 + rcu_lockdep_assert(rcu_read_lock_held(),
68881 + "find_task_by_pid_ns() needs rcu_read_lock()"
68882 + " protection");
68883 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68884 +}
68885 +
68886 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68887 {
68888 struct pid *pid;
68889 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68890 index 125cb67..a4d1c30 100644
68891 --- a/kernel/posix-cpu-timers.c
68892 +++ b/kernel/posix-cpu-timers.c
68893 @@ -6,6 +6,7 @@
68894 #include <linux/posix-timers.h>
68895 #include <linux/errno.h>
68896 #include <linux/math64.h>
68897 +#include <linux/security.h>
68898 #include <asm/uaccess.h>
68899 #include <linux/kernel_stat.h>
68900 #include <trace/events/timer.h>
68901 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68902
68903 static __init int init_posix_cpu_timers(void)
68904 {
68905 - struct k_clock process = {
68906 + static struct k_clock process = {
68907 .clock_getres = process_cpu_clock_getres,
68908 .clock_get = process_cpu_clock_get,
68909 .timer_create = process_cpu_timer_create,
68910 .nsleep = process_cpu_nsleep,
68911 .nsleep_restart = process_cpu_nsleep_restart,
68912 };
68913 - struct k_clock thread = {
68914 + static struct k_clock thread = {
68915 .clock_getres = thread_cpu_clock_getres,
68916 .clock_get = thread_cpu_clock_get,
68917 .timer_create = thread_cpu_timer_create,
68918 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68919 index 69185ae..cc2847a 100644
68920 --- a/kernel/posix-timers.c
68921 +++ b/kernel/posix-timers.c
68922 @@ -43,6 +43,7 @@
68923 #include <linux/idr.h>
68924 #include <linux/posix-clock.h>
68925 #include <linux/posix-timers.h>
68926 +#include <linux/grsecurity.h>
68927 #include <linux/syscalls.h>
68928 #include <linux/wait.h>
68929 #include <linux/workqueue.h>
68930 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68931 * which we beg off on and pass to do_sys_settimeofday().
68932 */
68933
68934 -static struct k_clock posix_clocks[MAX_CLOCKS];
68935 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68936
68937 /*
68938 * These ones are defined below.
68939 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68940 */
68941 static __init int init_posix_timers(void)
68942 {
68943 - struct k_clock clock_realtime = {
68944 + static struct k_clock clock_realtime = {
68945 .clock_getres = hrtimer_get_res,
68946 .clock_get = posix_clock_realtime_get,
68947 .clock_set = posix_clock_realtime_set,
68948 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68949 .timer_get = common_timer_get,
68950 .timer_del = common_timer_del,
68951 };
68952 - struct k_clock clock_monotonic = {
68953 + static struct k_clock clock_monotonic = {
68954 .clock_getres = hrtimer_get_res,
68955 .clock_get = posix_ktime_get_ts,
68956 .nsleep = common_nsleep,
68957 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68958 .timer_get = common_timer_get,
68959 .timer_del = common_timer_del,
68960 };
68961 - struct k_clock clock_monotonic_raw = {
68962 + static struct k_clock clock_monotonic_raw = {
68963 .clock_getres = hrtimer_get_res,
68964 .clock_get = posix_get_monotonic_raw,
68965 };
68966 - struct k_clock clock_realtime_coarse = {
68967 + static struct k_clock clock_realtime_coarse = {
68968 .clock_getres = posix_get_coarse_res,
68969 .clock_get = posix_get_realtime_coarse,
68970 };
68971 - struct k_clock clock_monotonic_coarse = {
68972 + static struct k_clock clock_monotonic_coarse = {
68973 .clock_getres = posix_get_coarse_res,
68974 .clock_get = posix_get_monotonic_coarse,
68975 };
68976 - struct k_clock clock_boottime = {
68977 + static struct k_clock clock_boottime = {
68978 .clock_getres = hrtimer_get_res,
68979 .clock_get = posix_get_boottime,
68980 .nsleep = common_nsleep,
68981 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68982 return;
68983 }
68984
68985 - posix_clocks[clock_id] = *new_clock;
68986 + posix_clocks[clock_id] = new_clock;
68987 }
68988 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68989
68990 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68991 return (id & CLOCKFD_MASK) == CLOCKFD ?
68992 &clock_posix_dynamic : &clock_posix_cpu;
68993
68994 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68995 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68996 return NULL;
68997 - return &posix_clocks[id];
68998 + return posix_clocks[id];
68999 }
69000
69001 static int common_timer_create(struct k_itimer *new_timer)
69002 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69003 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69004 return -EFAULT;
69005
69006 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69007 + have their clock_set fptr set to a nosettime dummy function
69008 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69009 + call common_clock_set, which calls do_sys_settimeofday, which
69010 + we hook
69011 + */
69012 +
69013 return kc->clock_set(which_clock, &new_tp);
69014 }
69015
69016 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69017 index d523593..68197a4 100644
69018 --- a/kernel/power/poweroff.c
69019 +++ b/kernel/power/poweroff.c
69020 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69021 .enable_mask = SYSRQ_ENABLE_BOOT,
69022 };
69023
69024 -static int pm_sysrq_init(void)
69025 +static int __init pm_sysrq_init(void)
69026 {
69027 register_sysrq_key('o', &sysrq_poweroff_op);
69028 return 0;
69029 diff --git a/kernel/power/process.c b/kernel/power/process.c
69030 index 7aac07a..2d3c6dc 100644
69031 --- a/kernel/power/process.c
69032 +++ b/kernel/power/process.c
69033 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69034 u64 elapsed_csecs64;
69035 unsigned int elapsed_csecs;
69036 bool wakeup = false;
69037 + bool timedout = false;
69038
69039 do_gettimeofday(&start);
69040
69041 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69042
69043 while (true) {
69044 todo = 0;
69045 + if (time_after(jiffies, end_time))
69046 + timedout = true;
69047 read_lock(&tasklist_lock);
69048 do_each_thread(g, p) {
69049 if (p == current || !freeze_task(p))
69050 @@ -60,9 +63,13 @@ static int try_to_freeze_tasks(bool user_only)
69051 * try_to_stop() after schedule() in ptrace/signal
69052 * stop sees TIF_FREEZE.
69053 */
69054 - if (!task_is_stopped_or_traced(p) &&
69055 - !freezer_should_skip(p))
69056 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69057 todo++;
69058 + if (timedout) {
69059 + printk(KERN_ERR "Task refusing to freeze:\n");
69060 + sched_show_task(p);
69061 + }
69062 + }
69063 } while_each_thread(g, p);
69064 read_unlock(&tasklist_lock);
69065
69066 @@ -71,7 +78,7 @@ static int try_to_freeze_tasks(bool user_only)
69067 todo += wq_busy;
69068 }
69069
69070 - if (!todo || time_after(jiffies, end_time))
69071 + if (!todo || timedout)
69072 break;
69073
69074 if (pm_wakeup_pending()) {
69075 diff --git a/kernel/printk.c b/kernel/printk.c
69076 index 32690a0..cd7c798 100644
69077 --- a/kernel/printk.c
69078 +++ b/kernel/printk.c
69079 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
69080 if (from_file && type != SYSLOG_ACTION_OPEN)
69081 return 0;
69082
69083 +#ifdef CONFIG_GRKERNSEC_DMESG
69084 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69085 + return -EPERM;
69086 +#endif
69087 +
69088 if (syslog_action_restricted(type)) {
69089 if (capable(CAP_SYSLOG))
69090 return 0;
69091 diff --git a/kernel/profile.c b/kernel/profile.c
69092 index 76b8e77..a2930e8 100644
69093 --- a/kernel/profile.c
69094 +++ b/kernel/profile.c
69095 @@ -39,7 +39,7 @@ struct profile_hit {
69096 /* Oprofile timer tick hook */
69097 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69098
69099 -static atomic_t *prof_buffer;
69100 +static atomic_unchecked_t *prof_buffer;
69101 static unsigned long prof_len, prof_shift;
69102
69103 int prof_on __read_mostly;
69104 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69105 hits[i].pc = 0;
69106 continue;
69107 }
69108 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69109 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69110 hits[i].hits = hits[i].pc = 0;
69111 }
69112 }
69113 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69114 * Add the current hit(s) and flush the write-queue out
69115 * to the global buffer:
69116 */
69117 - atomic_add(nr_hits, &prof_buffer[pc]);
69118 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69119 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69120 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69121 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69122 hits[i].pc = hits[i].hits = 0;
69123 }
69124 out:
69125 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69126 {
69127 unsigned long pc;
69128 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69129 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69130 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69131 }
69132 #endif /* !CONFIG_SMP */
69133
69134 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69135 return -EFAULT;
69136 buf++; p++; count--; read++;
69137 }
69138 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69139 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69140 if (copy_to_user(buf, (void *)pnt, count))
69141 return -EFAULT;
69142 read += count;
69143 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69144 }
69145 #endif
69146 profile_discard_flip_buffers();
69147 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69148 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69149 return count;
69150 }
69151
69152 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69153 index 00ab2ca..d237f61 100644
69154 --- a/kernel/ptrace.c
69155 +++ b/kernel/ptrace.c
69156 @@ -285,7 +285,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69157 task->ptrace = PT_PTRACED;
69158 if (seize)
69159 task->ptrace |= PT_SEIZED;
69160 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69161 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69162 task->ptrace |= PT_PTRACE_CAP;
69163
69164 __ptrace_link(task, current);
69165 @@ -491,7 +491,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69166 break;
69167 return -EIO;
69168 }
69169 - if (copy_to_user(dst, buf, retval))
69170 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69171 return -EFAULT;
69172 copied += retval;
69173 src += retval;
69174 @@ -688,7 +688,7 @@ int ptrace_request(struct task_struct *child, long request,
69175 bool seized = child->ptrace & PT_SEIZED;
69176 int ret = -EIO;
69177 siginfo_t siginfo, *si;
69178 - void __user *datavp = (void __user *) data;
69179 + void __user *datavp = (__force void __user *) data;
69180 unsigned long __user *datalp = datavp;
69181 unsigned long flags;
69182
69183 @@ -890,14 +890,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69184 goto out;
69185 }
69186
69187 + if (gr_handle_ptrace(child, request)) {
69188 + ret = -EPERM;
69189 + goto out_put_task_struct;
69190 + }
69191 +
69192 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69193 ret = ptrace_attach(child, request, data);
69194 /*
69195 * Some architectures need to do book-keeping after
69196 * a ptrace attach.
69197 */
69198 - if (!ret)
69199 + if (!ret) {
69200 arch_ptrace_attach(child);
69201 + gr_audit_ptrace(child);
69202 + }
69203 goto out_put_task_struct;
69204 }
69205
69206 @@ -923,7 +930,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69207 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69208 if (copied != sizeof(tmp))
69209 return -EIO;
69210 - return put_user(tmp, (unsigned long __user *)data);
69211 + return put_user(tmp, (__force unsigned long __user *)data);
69212 }
69213
69214 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69215 @@ -1033,14 +1040,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69216 goto out;
69217 }
69218
69219 + if (gr_handle_ptrace(child, request)) {
69220 + ret = -EPERM;
69221 + goto out_put_task_struct;
69222 + }
69223 +
69224 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69225 ret = ptrace_attach(child, request, data);
69226 /*
69227 * Some architectures need to do book-keeping after
69228 * a ptrace attach.
69229 */
69230 - if (!ret)
69231 + if (!ret) {
69232 arch_ptrace_attach(child);
69233 + gr_audit_ptrace(child);
69234 + }
69235 goto out_put_task_struct;
69236 }
69237
69238 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69239 index 977296d..c4744dc 100644
69240 --- a/kernel/rcutiny.c
69241 +++ b/kernel/rcutiny.c
69242 @@ -46,7 +46,7 @@
69243 struct rcu_ctrlblk;
69244 static void invoke_rcu_callbacks(void);
69245 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69246 -static void rcu_process_callbacks(struct softirq_action *unused);
69247 +static void rcu_process_callbacks(void);
69248 static void __call_rcu(struct rcu_head *head,
69249 void (*func)(struct rcu_head *rcu),
69250 struct rcu_ctrlblk *rcp);
69251 @@ -297,7 +297,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69252 rcu_is_callbacks_kthread()));
69253 }
69254
69255 -static void rcu_process_callbacks(struct softirq_action *unused)
69256 +static void rcu_process_callbacks(void)
69257 {
69258 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69259 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69260 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69261 index 9cb1ae4..aac7d3e 100644
69262 --- a/kernel/rcutiny_plugin.h
69263 +++ b/kernel/rcutiny_plugin.h
69264 @@ -920,7 +920,7 @@ static int rcu_kthread(void *arg)
69265 have_rcu_kthread_work = morework;
69266 local_irq_restore(flags);
69267 if (work)
69268 - rcu_process_callbacks(NULL);
69269 + rcu_process_callbacks();
69270 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69271 }
69272
69273 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69274 index a58ac28..196a3d8 100644
69275 --- a/kernel/rcutorture.c
69276 +++ b/kernel/rcutorture.c
69277 @@ -148,12 +148,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69278 { 0 };
69279 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69280 { 0 };
69281 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69282 -static atomic_t n_rcu_torture_alloc;
69283 -static atomic_t n_rcu_torture_alloc_fail;
69284 -static atomic_t n_rcu_torture_free;
69285 -static atomic_t n_rcu_torture_mberror;
69286 -static atomic_t n_rcu_torture_error;
69287 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69288 +static atomic_unchecked_t n_rcu_torture_alloc;
69289 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69290 +static atomic_unchecked_t n_rcu_torture_free;
69291 +static atomic_unchecked_t n_rcu_torture_mberror;
69292 +static atomic_unchecked_t n_rcu_torture_error;
69293 static long n_rcu_torture_boost_ktrerror;
69294 static long n_rcu_torture_boost_rterror;
69295 static long n_rcu_torture_boost_failure;
69296 @@ -243,11 +243,11 @@ rcu_torture_alloc(void)
69297
69298 spin_lock_bh(&rcu_torture_lock);
69299 if (list_empty(&rcu_torture_freelist)) {
69300 - atomic_inc(&n_rcu_torture_alloc_fail);
69301 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69302 spin_unlock_bh(&rcu_torture_lock);
69303 return NULL;
69304 }
69305 - atomic_inc(&n_rcu_torture_alloc);
69306 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69307 p = rcu_torture_freelist.next;
69308 list_del_init(p);
69309 spin_unlock_bh(&rcu_torture_lock);
69310 @@ -260,7 +260,7 @@ rcu_torture_alloc(void)
69311 static void
69312 rcu_torture_free(struct rcu_torture *p)
69313 {
69314 - atomic_inc(&n_rcu_torture_free);
69315 + atomic_inc_unchecked(&n_rcu_torture_free);
69316 spin_lock_bh(&rcu_torture_lock);
69317 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69318 spin_unlock_bh(&rcu_torture_lock);
69319 @@ -380,7 +380,7 @@ rcu_torture_cb(struct rcu_head *p)
69320 i = rp->rtort_pipe_count;
69321 if (i > RCU_TORTURE_PIPE_LEN)
69322 i = RCU_TORTURE_PIPE_LEN;
69323 - atomic_inc(&rcu_torture_wcount[i]);
69324 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69325 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69326 rp->rtort_mbtest = 0;
69327 rcu_torture_free(rp);
69328 @@ -427,7 +427,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69329 i = rp->rtort_pipe_count;
69330 if (i > RCU_TORTURE_PIPE_LEN)
69331 i = RCU_TORTURE_PIPE_LEN;
69332 - atomic_inc(&rcu_torture_wcount[i]);
69333 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69334 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69335 rp->rtort_mbtest = 0;
69336 list_del(&rp->rtort_free);
69337 @@ -916,7 +916,7 @@ rcu_torture_writer(void *arg)
69338 i = old_rp->rtort_pipe_count;
69339 if (i > RCU_TORTURE_PIPE_LEN)
69340 i = RCU_TORTURE_PIPE_LEN;
69341 - atomic_inc(&rcu_torture_wcount[i]);
69342 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69343 old_rp->rtort_pipe_count++;
69344 cur_ops->deferred_free(old_rp);
69345 }
69346 @@ -997,7 +997,7 @@ static void rcu_torture_timer(unsigned long unused)
69347 return;
69348 }
69349 if (p->rtort_mbtest == 0)
69350 - atomic_inc(&n_rcu_torture_mberror);
69351 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69352 spin_lock(&rand_lock);
69353 cur_ops->read_delay(&rand);
69354 n_rcu_torture_timers++;
69355 @@ -1061,7 +1061,7 @@ rcu_torture_reader(void *arg)
69356 continue;
69357 }
69358 if (p->rtort_mbtest == 0)
69359 - atomic_inc(&n_rcu_torture_mberror);
69360 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69361 cur_ops->read_delay(&rand);
69362 preempt_disable();
69363 pipe_count = p->rtort_pipe_count;
69364 @@ -1123,10 +1123,10 @@ rcu_torture_printk(char *page)
69365 rcu_torture_current,
69366 rcu_torture_current_version,
69367 list_empty(&rcu_torture_freelist),
69368 - atomic_read(&n_rcu_torture_alloc),
69369 - atomic_read(&n_rcu_torture_alloc_fail),
69370 - atomic_read(&n_rcu_torture_free),
69371 - atomic_read(&n_rcu_torture_mberror),
69372 + atomic_read_unchecked(&n_rcu_torture_alloc),
69373 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69374 + atomic_read_unchecked(&n_rcu_torture_free),
69375 + atomic_read_unchecked(&n_rcu_torture_mberror),
69376 n_rcu_torture_boost_ktrerror,
69377 n_rcu_torture_boost_rterror,
69378 n_rcu_torture_boost_failure,
69379 @@ -1136,7 +1136,7 @@ rcu_torture_printk(char *page)
69380 n_online_attempts,
69381 n_offline_successes,
69382 n_offline_attempts);
69383 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69384 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69385 n_rcu_torture_boost_ktrerror != 0 ||
69386 n_rcu_torture_boost_rterror != 0 ||
69387 n_rcu_torture_boost_failure != 0)
69388 @@ -1144,7 +1144,7 @@ rcu_torture_printk(char *page)
69389 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69390 if (i > 1) {
69391 cnt += sprintf(&page[cnt], "!!! ");
69392 - atomic_inc(&n_rcu_torture_error);
69393 + atomic_inc_unchecked(&n_rcu_torture_error);
69394 WARN_ON_ONCE(1);
69395 }
69396 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69397 @@ -1158,7 +1158,7 @@ rcu_torture_printk(char *page)
69398 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69399 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69400 cnt += sprintf(&page[cnt], " %d",
69401 - atomic_read(&rcu_torture_wcount[i]));
69402 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69403 }
69404 cnt += sprintf(&page[cnt], "\n");
69405 if (cur_ops->stats)
69406 @@ -1600,7 +1600,7 @@ rcu_torture_cleanup(void)
69407
69408 if (cur_ops->cleanup)
69409 cur_ops->cleanup();
69410 - if (atomic_read(&n_rcu_torture_error))
69411 + if (atomic_read_unchecked(&n_rcu_torture_error))
69412 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69413 else
69414 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
69415 @@ -1664,17 +1664,17 @@ rcu_torture_init(void)
69416
69417 rcu_torture_current = NULL;
69418 rcu_torture_current_version = 0;
69419 - atomic_set(&n_rcu_torture_alloc, 0);
69420 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69421 - atomic_set(&n_rcu_torture_free, 0);
69422 - atomic_set(&n_rcu_torture_mberror, 0);
69423 - atomic_set(&n_rcu_torture_error, 0);
69424 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69425 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69426 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69427 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69428 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69429 n_rcu_torture_boost_ktrerror = 0;
69430 n_rcu_torture_boost_rterror = 0;
69431 n_rcu_torture_boost_failure = 0;
69432 n_rcu_torture_boosts = 0;
69433 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69434 - atomic_set(&rcu_torture_wcount[i], 0);
69435 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69436 for_each_possible_cpu(cpu) {
69437 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69438 per_cpu(rcu_torture_count, cpu)[i] = 0;
69439 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69440 index 6c4a672..70f3202 100644
69441 --- a/kernel/rcutree.c
69442 +++ b/kernel/rcutree.c
69443 @@ -363,9 +363,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69444 rcu_prepare_for_idle(smp_processor_id());
69445 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69446 smp_mb__before_atomic_inc(); /* See above. */
69447 - atomic_inc(&rdtp->dynticks);
69448 + atomic_inc_unchecked(&rdtp->dynticks);
69449 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69450 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69451 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69452 }
69453
69454 /**
69455 @@ -438,10 +438,10 @@ void rcu_irq_exit(void)
69456 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69457 {
69458 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69459 - atomic_inc(&rdtp->dynticks);
69460 + atomic_inc_unchecked(&rdtp->dynticks);
69461 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69462 smp_mb__after_atomic_inc(); /* See above. */
69463 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69464 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69465 rcu_cleanup_after_idle(smp_processor_id());
69466 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69467 if (!is_idle_task(current)) {
69468 @@ -531,14 +531,14 @@ void rcu_nmi_enter(void)
69469 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69470
69471 if (rdtp->dynticks_nmi_nesting == 0 &&
69472 - (atomic_read(&rdtp->dynticks) & 0x1))
69473 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69474 return;
69475 rdtp->dynticks_nmi_nesting++;
69476 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69477 - atomic_inc(&rdtp->dynticks);
69478 + atomic_inc_unchecked(&rdtp->dynticks);
69479 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69480 smp_mb__after_atomic_inc(); /* See above. */
69481 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69482 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69483 }
69484
69485 /**
69486 @@ -557,9 +557,9 @@ void rcu_nmi_exit(void)
69487 return;
69488 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69489 smp_mb__before_atomic_inc(); /* See above. */
69490 - atomic_inc(&rdtp->dynticks);
69491 + atomic_inc_unchecked(&rdtp->dynticks);
69492 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69493 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69494 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69495 }
69496
69497 #ifdef CONFIG_PROVE_RCU
69498 @@ -575,7 +575,7 @@ int rcu_is_cpu_idle(void)
69499 int ret;
69500
69501 preempt_disable();
69502 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69503 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69504 preempt_enable();
69505 return ret;
69506 }
69507 @@ -604,7 +604,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69508 */
69509 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69510 {
69511 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69512 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69513 return (rdp->dynticks_snap & 0x1) == 0;
69514 }
69515
69516 @@ -619,7 +619,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69517 unsigned int curr;
69518 unsigned int snap;
69519
69520 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69521 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69522 snap = (unsigned int)rdp->dynticks_snap;
69523
69524 /*
69525 @@ -1667,7 +1667,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
69526 /*
69527 * Do RCU core processing for the current CPU.
69528 */
69529 -static void rcu_process_callbacks(struct softirq_action *unused)
69530 +static void rcu_process_callbacks(void)
69531 {
69532 trace_rcu_utilization("Start RCU core");
69533 __rcu_process_callbacks(&rcu_sched_state,
69534 @@ -2030,7 +2030,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69535 rdp->qlen = 0;
69536 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69537 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_NESTING);
69538 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69539 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69540 rdp->cpu = cpu;
69541 rdp->rsp = rsp;
69542 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69543 @@ -2058,8 +2058,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69544 rdp->n_force_qs_snap = rsp->n_force_qs;
69545 rdp->blimit = blimit;
69546 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_NESTING;
69547 - atomic_set(&rdp->dynticks->dynticks,
69548 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69549 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69550 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69551 rcu_prepare_for_idle_init(cpu);
69552 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69553
69554 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69555 index fddff92..2c08359 100644
69556 --- a/kernel/rcutree.h
69557 +++ b/kernel/rcutree.h
69558 @@ -87,7 +87,7 @@ struct rcu_dynticks {
69559 long long dynticks_nesting; /* Track irq/process nesting level. */
69560 /* Process level is worth LLONG_MAX/2. */
69561 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69562 - atomic_t dynticks; /* Even value for idle, else odd. */
69563 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69564 };
69565
69566 /* RCU's kthread states for tracing. */
69567 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69568 index 8bb35d7..6ea0a463 100644
69569 --- a/kernel/rcutree_plugin.h
69570 +++ b/kernel/rcutree_plugin.h
69571 @@ -850,7 +850,7 @@ void synchronize_rcu_expedited(void)
69572
69573 /* Clean up and exit. */
69574 smp_mb(); /* ensure expedited GP seen before counter increment. */
69575 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69576 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69577 unlock_mb_ret:
69578 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69579 mb_ret:
69580 @@ -1833,8 +1833,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
69581
69582 #else /* #ifndef CONFIG_SMP */
69583
69584 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69585 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69586 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69587 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69588
69589 static int synchronize_sched_expedited_cpu_stop(void *data)
69590 {
69591 @@ -1889,7 +1889,7 @@ void synchronize_sched_expedited(void)
69592 int firstsnap, s, snap, trycount = 0;
69593
69594 /* Note that atomic_inc_return() implies full memory barrier. */
69595 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69596 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69597 get_online_cpus();
69598
69599 /*
69600 @@ -1910,7 +1910,7 @@ void synchronize_sched_expedited(void)
69601 }
69602
69603 /* Check to see if someone else did our work for us. */
69604 - s = atomic_read(&sync_sched_expedited_done);
69605 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69606 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69607 smp_mb(); /* ensure test happens before caller kfree */
69608 return;
69609 @@ -1925,7 +1925,7 @@ void synchronize_sched_expedited(void)
69610 * grace period works for us.
69611 */
69612 get_online_cpus();
69613 - snap = atomic_read(&sync_sched_expedited_started);
69614 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69615 smp_mb(); /* ensure read is before try_stop_cpus(). */
69616 }
69617
69618 @@ -1936,12 +1936,12 @@ void synchronize_sched_expedited(void)
69619 * than we did beat us to the punch.
69620 */
69621 do {
69622 - s = atomic_read(&sync_sched_expedited_done);
69623 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69624 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69625 smp_mb(); /* ensure test happens before caller kfree */
69626 break;
69627 }
69628 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69629 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69630
69631 put_online_cpus();
69632 }
69633 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69634 index 654cfe6..c0b28e2 100644
69635 --- a/kernel/rcutree_trace.c
69636 +++ b/kernel/rcutree_trace.c
69637 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69638 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69639 rdp->qs_pending);
69640 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69641 - atomic_read(&rdp->dynticks->dynticks),
69642 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69643 rdp->dynticks->dynticks_nesting,
69644 rdp->dynticks->dynticks_nmi_nesting,
69645 rdp->dynticks_fqs);
69646 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69647 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69648 rdp->qs_pending);
69649 seq_printf(m, ",%d,%llx,%d,%lu",
69650 - atomic_read(&rdp->dynticks->dynticks),
69651 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69652 rdp->dynticks->dynticks_nesting,
69653 rdp->dynticks->dynticks_nmi_nesting,
69654 rdp->dynticks_fqs);
69655 diff --git a/kernel/resource.c b/kernel/resource.c
69656 index 7640b3a..5879283 100644
69657 --- a/kernel/resource.c
69658 +++ b/kernel/resource.c
69659 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
69660
69661 static int __init ioresources_init(void)
69662 {
69663 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69664 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69665 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69666 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69667 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69668 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69669 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69670 +#endif
69671 +#else
69672 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69673 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69674 +#endif
69675 return 0;
69676 }
69677 __initcall(ioresources_init);
69678 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69679 index 98ec494..4241d6d 100644
69680 --- a/kernel/rtmutex-tester.c
69681 +++ b/kernel/rtmutex-tester.c
69682 @@ -20,7 +20,7 @@
69683 #define MAX_RT_TEST_MUTEXES 8
69684
69685 static spinlock_t rttest_lock;
69686 -static atomic_t rttest_event;
69687 +static atomic_unchecked_t rttest_event;
69688
69689 struct test_thread_data {
69690 int opcode;
69691 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69692
69693 case RTTEST_LOCKCONT:
69694 td->mutexes[td->opdata] = 1;
69695 - td->event = atomic_add_return(1, &rttest_event);
69696 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69697 return 0;
69698
69699 case RTTEST_RESET:
69700 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69701 return 0;
69702
69703 case RTTEST_RESETEVENT:
69704 - atomic_set(&rttest_event, 0);
69705 + atomic_set_unchecked(&rttest_event, 0);
69706 return 0;
69707
69708 default:
69709 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69710 return ret;
69711
69712 td->mutexes[id] = 1;
69713 - td->event = atomic_add_return(1, &rttest_event);
69714 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69715 rt_mutex_lock(&mutexes[id]);
69716 - td->event = atomic_add_return(1, &rttest_event);
69717 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69718 td->mutexes[id] = 4;
69719 return 0;
69720
69721 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69722 return ret;
69723
69724 td->mutexes[id] = 1;
69725 - td->event = atomic_add_return(1, &rttest_event);
69726 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69727 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69728 - td->event = atomic_add_return(1, &rttest_event);
69729 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69730 td->mutexes[id] = ret ? 0 : 4;
69731 return ret ? -EINTR : 0;
69732
69733 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69734 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69735 return ret;
69736
69737 - td->event = atomic_add_return(1, &rttest_event);
69738 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69739 rt_mutex_unlock(&mutexes[id]);
69740 - td->event = atomic_add_return(1, &rttest_event);
69741 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69742 td->mutexes[id] = 0;
69743 return 0;
69744
69745 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69746 break;
69747
69748 td->mutexes[dat] = 2;
69749 - td->event = atomic_add_return(1, &rttest_event);
69750 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69751 break;
69752
69753 default:
69754 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69755 return;
69756
69757 td->mutexes[dat] = 3;
69758 - td->event = atomic_add_return(1, &rttest_event);
69759 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69760 break;
69761
69762 case RTTEST_LOCKNOWAIT:
69763 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69764 return;
69765
69766 td->mutexes[dat] = 1;
69767 - td->event = atomic_add_return(1, &rttest_event);
69768 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69769 return;
69770
69771 default:
69772 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69773 index e8a1f83..363d17d 100644
69774 --- a/kernel/sched/auto_group.c
69775 +++ b/kernel/sched/auto_group.c
69776 @@ -11,7 +11,7 @@
69777
69778 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69779 static struct autogroup autogroup_default;
69780 -static atomic_t autogroup_seq_nr;
69781 +static atomic_unchecked_t autogroup_seq_nr;
69782
69783 void __init autogroup_init(struct task_struct *init_task)
69784 {
69785 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69786
69787 kref_init(&ag->kref);
69788 init_rwsem(&ag->lock);
69789 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69790 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69791 ag->tg = tg;
69792 #ifdef CONFIG_RT_GROUP_SCHED
69793 /*
69794 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69795 index 478a04c..e16339a 100644
69796 --- a/kernel/sched/core.c
69797 +++ b/kernel/sched/core.c
69798 @@ -3851,6 +3851,8 @@ int can_nice(const struct task_struct *p, const int nice)
69799 /* convert nice value [19,-20] to rlimit style value [1,40] */
69800 int nice_rlim = 20 - nice;
69801
69802 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69803 +
69804 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69805 capable(CAP_SYS_NICE));
69806 }
69807 @@ -3884,7 +3886,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69808 if (nice > 19)
69809 nice = 19;
69810
69811 - if (increment < 0 && !can_nice(current, nice))
69812 + if (increment < 0 && (!can_nice(current, nice) ||
69813 + gr_handle_chroot_nice()))
69814 return -EPERM;
69815
69816 retval = security_task_setnice(current, nice);
69817 @@ -4041,6 +4044,7 @@ recheck:
69818 unsigned long rlim_rtprio =
69819 task_rlimit(p, RLIMIT_RTPRIO);
69820
69821 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69822 /* can't set/change the rt policy */
69823 if (policy != p->policy && !rlim_rtprio)
69824 return -EPERM;
69825 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69826 index aca16b8..8e3acc4 100644
69827 --- a/kernel/sched/fair.c
69828 +++ b/kernel/sched/fair.c
69829 @@ -5147,7 +5147,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69830 * run_rebalance_domains is triggered when needed from the scheduler tick.
69831 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69832 */
69833 -static void run_rebalance_domains(struct softirq_action *h)
69834 +static void run_rebalance_domains(void)
69835 {
69836 int this_cpu = smp_processor_id();
69837 struct rq *this_rq = cpu_rq(this_cpu);
69838 diff --git a/kernel/signal.c b/kernel/signal.c
69839 index b09cf3b..b291c66 100644
69840 --- a/kernel/signal.c
69841 +++ b/kernel/signal.c
69842 @@ -46,12 +46,12 @@ static struct kmem_cache *sigqueue_cachep;
69843
69844 int print_fatal_signals __read_mostly;
69845
69846 -static void __user *sig_handler(struct task_struct *t, int sig)
69847 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69848 {
69849 return t->sighand->action[sig - 1].sa.sa_handler;
69850 }
69851
69852 -static int sig_handler_ignored(void __user *handler, int sig)
69853 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69854 {
69855 /* Is it explicitly or implicitly ignored? */
69856 return handler == SIG_IGN ||
69857 @@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69858 static int sig_task_ignored(struct task_struct *t, int sig,
69859 int from_ancestor_ns)
69860 {
69861 - void __user *handler;
69862 + __sighandler_t handler;
69863
69864 handler = sig_handler(t, sig);
69865
69866 @@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69867 atomic_inc(&user->sigpending);
69868 rcu_read_unlock();
69869
69870 + if (!override_rlimit)
69871 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69872 +
69873 if (override_rlimit ||
69874 atomic_read(&user->sigpending) <=
69875 task_rlimit(t, RLIMIT_SIGPENDING)) {
69876 @@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69877
69878 int unhandled_signal(struct task_struct *tsk, int sig)
69879 {
69880 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69881 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69882 if (is_global_init(tsk))
69883 return 1;
69884 if (handler != SIG_IGN && handler != SIG_DFL)
69885 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69886 }
69887 }
69888
69889 + /* allow glibc communication via tgkill to other threads in our
69890 + thread group */
69891 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69892 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69893 + && gr_handle_signal(t, sig))
69894 + return -EPERM;
69895 +
69896 return security_task_kill(t, info, sig, 0);
69897 }
69898
69899 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69900 return send_signal(sig, info, p, 1);
69901 }
69902
69903 -static int
69904 +int
69905 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69906 {
69907 return send_signal(sig, info, t, 0);
69908 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69909 unsigned long int flags;
69910 int ret, blocked, ignored;
69911 struct k_sigaction *action;
69912 + int is_unhandled = 0;
69913
69914 spin_lock_irqsave(&t->sighand->siglock, flags);
69915 action = &t->sighand->action[sig-1];
69916 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69917 }
69918 if (action->sa.sa_handler == SIG_DFL)
69919 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69920 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69921 + is_unhandled = 1;
69922 ret = specific_send_sig_info(sig, info, t);
69923 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69924
69925 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
69926 + normal operation */
69927 + if (is_unhandled) {
69928 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69929 + gr_handle_crash(t, sig);
69930 + }
69931 +
69932 return ret;
69933 }
69934
69935 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69936 ret = check_kill_permission(sig, info, p);
69937 rcu_read_unlock();
69938
69939 - if (!ret && sig)
69940 + if (!ret && sig) {
69941 ret = do_send_sig_info(sig, info, p, true);
69942 + if (!ret)
69943 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69944 + }
69945
69946 return ret;
69947 }
69948 @@ -2829,7 +2852,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69949 int error = -ESRCH;
69950
69951 rcu_read_lock();
69952 - p = find_task_by_vpid(pid);
69953 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69954 + /* allow glibc communication via tgkill to other threads in our
69955 + thread group */
69956 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69957 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
69958 + p = find_task_by_vpid_unrestricted(pid);
69959 + else
69960 +#endif
69961 + p = find_task_by_vpid(pid);
69962 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69963 error = check_kill_permission(sig, info, p);
69964 /*
69965 diff --git a/kernel/smp.c b/kernel/smp.c
69966 index db197d6..17aef0b 100644
69967 --- a/kernel/smp.c
69968 +++ b/kernel/smp.c
69969 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69970 }
69971 EXPORT_SYMBOL(smp_call_function);
69972
69973 -void ipi_call_lock(void)
69974 +void ipi_call_lock(void) __acquires(call_function.lock)
69975 {
69976 raw_spin_lock(&call_function.lock);
69977 }
69978
69979 -void ipi_call_unlock(void)
69980 +void ipi_call_unlock(void) __releases(call_function.lock)
69981 {
69982 raw_spin_unlock(&call_function.lock);
69983 }
69984
69985 -void ipi_call_lock_irq(void)
69986 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
69987 {
69988 raw_spin_lock_irq(&call_function.lock);
69989 }
69990
69991 -void ipi_call_unlock_irq(void)
69992 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
69993 {
69994 raw_spin_unlock_irq(&call_function.lock);
69995 }
69996 diff --git a/kernel/softirq.c b/kernel/softirq.c
69997 index 4eb3a0f..6f1fa81 100644
69998 --- a/kernel/softirq.c
69999 +++ b/kernel/softirq.c
70000 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70001
70002 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70003
70004 -char *softirq_to_name[NR_SOFTIRQS] = {
70005 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70006 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70007 "TASKLET", "SCHED", "HRTIMER", "RCU"
70008 };
70009 @@ -235,7 +235,7 @@ restart:
70010 kstat_incr_softirqs_this_cpu(vec_nr);
70011
70012 trace_softirq_entry(vec_nr);
70013 - h->action(h);
70014 + h->action();
70015 trace_softirq_exit(vec_nr);
70016 if (unlikely(prev_count != preempt_count())) {
70017 printk(KERN_ERR "huh, entered softirq %u %s %p"
70018 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
70019 local_irq_restore(flags);
70020 }
70021
70022 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70023 +void open_softirq(int nr, void (*action)(void))
70024 {
70025 - softirq_vec[nr].action = action;
70026 + pax_open_kernel();
70027 + *(void **)&softirq_vec[nr].action = action;
70028 + pax_close_kernel();
70029 }
70030
70031 /*
70032 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70033
70034 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70035
70036 -static void tasklet_action(struct softirq_action *a)
70037 +static void tasklet_action(void)
70038 {
70039 struct tasklet_struct *list;
70040
70041 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
70042 }
70043 }
70044
70045 -static void tasklet_hi_action(struct softirq_action *a)
70046 +static void tasklet_hi_action(void)
70047 {
70048 struct tasklet_struct *list;
70049
70050 diff --git a/kernel/sys.c b/kernel/sys.c
70051 index 888d227..f04b318 100644
70052 --- a/kernel/sys.c
70053 +++ b/kernel/sys.c
70054 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70055 error = -EACCES;
70056 goto out;
70057 }
70058 +
70059 + if (gr_handle_chroot_setpriority(p, niceval)) {
70060 + error = -EACCES;
70061 + goto out;
70062 + }
70063 +
70064 no_nice = security_task_setnice(p, niceval);
70065 if (no_nice) {
70066 error = no_nice;
70067 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70068 goto error;
70069 }
70070
70071 + if (gr_check_group_change(new->gid, new->egid, -1))
70072 + goto error;
70073 +
70074 if (rgid != (gid_t) -1 ||
70075 (egid != (gid_t) -1 && egid != old->gid))
70076 new->sgid = new->egid;
70077 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70078 old = current_cred();
70079
70080 retval = -EPERM;
70081 +
70082 + if (gr_check_group_change(gid, gid, gid))
70083 + goto error;
70084 +
70085 if (nsown_capable(CAP_SETGID))
70086 new->gid = new->egid = new->sgid = new->fsgid = gid;
70087 else if (gid == old->gid || gid == old->sgid)
70088 @@ -618,7 +631,7 @@ error:
70089 /*
70090 * change the user struct in a credentials set to match the new UID
70091 */
70092 -static int set_user(struct cred *new)
70093 +int set_user(struct cred *new)
70094 {
70095 struct user_struct *new_user;
70096
70097 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70098 goto error;
70099 }
70100
70101 + if (gr_check_user_change(new->uid, new->euid, -1))
70102 + goto error;
70103 +
70104 if (new->uid != old->uid) {
70105 retval = set_user(new);
70106 if (retval < 0)
70107 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70108 old = current_cred();
70109
70110 retval = -EPERM;
70111 +
70112 + if (gr_check_crash_uid(uid))
70113 + goto error;
70114 + if (gr_check_user_change(uid, uid, uid))
70115 + goto error;
70116 +
70117 if (nsown_capable(CAP_SETUID)) {
70118 new->suid = new->uid = uid;
70119 if (uid != old->uid) {
70120 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70121 goto error;
70122 }
70123
70124 + if (gr_check_user_change(ruid, euid, -1))
70125 + goto error;
70126 +
70127 if (ruid != (uid_t) -1) {
70128 new->uid = ruid;
70129 if (ruid != old->uid) {
70130 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70131 goto error;
70132 }
70133
70134 + if (gr_check_group_change(rgid, egid, -1))
70135 + goto error;
70136 +
70137 if (rgid != (gid_t) -1)
70138 new->gid = rgid;
70139 if (egid != (gid_t) -1)
70140 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70141 old = current_cred();
70142 old_fsuid = old->fsuid;
70143
70144 + if (gr_check_user_change(-1, -1, uid))
70145 + goto error;
70146 +
70147 if (uid == old->uid || uid == old->euid ||
70148 uid == old->suid || uid == old->fsuid ||
70149 nsown_capable(CAP_SETUID)) {
70150 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70151 }
70152 }
70153
70154 +error:
70155 abort_creds(new);
70156 return old_fsuid;
70157
70158 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70159 if (gid == old->gid || gid == old->egid ||
70160 gid == old->sgid || gid == old->fsgid ||
70161 nsown_capable(CAP_SETGID)) {
70162 + if (gr_check_group_change(-1, -1, gid))
70163 + goto error;
70164 +
70165 if (gid != old_fsgid) {
70166 new->fsgid = gid;
70167 goto change_okay;
70168 }
70169 }
70170
70171 +error:
70172 abort_creds(new);
70173 return old_fsgid;
70174
70175 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
70176 }
70177 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
70178 snprintf(buf, len, "2.6.%u%s", v, rest);
70179 - ret = copy_to_user(release, buf, len);
70180 + if (len > sizeof(buf))
70181 + ret = -EFAULT;
70182 + else
70183 + ret = copy_to_user(release, buf, len);
70184 }
70185 return ret;
70186 }
70187 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70188 return -EFAULT;
70189
70190 down_read(&uts_sem);
70191 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70192 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70193 __OLD_UTS_LEN);
70194 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70195 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70196 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70197 __OLD_UTS_LEN);
70198 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70199 - error |= __copy_to_user(&name->release, &utsname()->release,
70200 + error |= __copy_to_user(name->release, &utsname()->release,
70201 __OLD_UTS_LEN);
70202 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70203 - error |= __copy_to_user(&name->version, &utsname()->version,
70204 + error |= __copy_to_user(name->version, &utsname()->version,
70205 __OLD_UTS_LEN);
70206 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70207 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70208 + error |= __copy_to_user(name->machine, &utsname()->machine,
70209 __OLD_UTS_LEN);
70210 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70211 up_read(&uts_sem);
70212 @@ -1838,7 +1877,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70213 error = get_dumpable(me->mm);
70214 break;
70215 case PR_SET_DUMPABLE:
70216 - if (arg2 < 0 || arg2 > 1) {
70217 + if (arg2 > 1) {
70218 error = -EINVAL;
70219 break;
70220 }
70221 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70222 index f03a6ef..5fcc8af 100644
70223 --- a/kernel/sysctl.c
70224 +++ b/kernel/sysctl.c
70225 @@ -86,6 +86,13 @@
70226
70227
70228 #if defined(CONFIG_SYSCTL)
70229 +#include <linux/grsecurity.h>
70230 +#include <linux/grinternal.h>
70231 +
70232 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
70233 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
70234 + const int op);
70235 +extern int gr_handle_chroot_sysctl(const int op);
70236
70237 /* External variables not in a header file. */
70238 extern int sysctl_overcommit_memory;
70239 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70240 }
70241
70242 #endif
70243 +extern struct ctl_table grsecurity_table[];
70244
70245 static struct ctl_table root_table[];
70246 static struct ctl_table_root sysctl_table_root;
70247 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
70248 int sysctl_legacy_va_layout;
70249 #endif
70250
70251 +#ifdef CONFIG_PAX_SOFTMODE
70252 +static ctl_table pax_table[] = {
70253 + {
70254 + .procname = "softmode",
70255 + .data = &pax_softmode,
70256 + .maxlen = sizeof(unsigned int),
70257 + .mode = 0600,
70258 + .proc_handler = &proc_dointvec,
70259 + },
70260 +
70261 + { }
70262 +};
70263 +#endif
70264 +
70265 /* The default sysctl tables: */
70266
70267 static struct ctl_table root_table[] = {
70268 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
70269 #endif
70270
70271 static struct ctl_table kern_table[] = {
70272 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70273 + {
70274 + .procname = "grsecurity",
70275 + .mode = 0500,
70276 + .child = grsecurity_table,
70277 + },
70278 +#endif
70279 +
70280 +#ifdef CONFIG_PAX_SOFTMODE
70281 + {
70282 + .procname = "pax",
70283 + .mode = 0500,
70284 + .child = pax_table,
70285 + },
70286 +#endif
70287 +
70288 {
70289 .procname = "sched_child_runs_first",
70290 .data = &sysctl_sched_child_runs_first,
70291 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
70292 .data = &modprobe_path,
70293 .maxlen = KMOD_PATH_LEN,
70294 .mode = 0644,
70295 - .proc_handler = proc_dostring,
70296 + .proc_handler = proc_dostring_modpriv,
70297 },
70298 {
70299 .procname = "modules_disabled",
70300 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
70301 .extra1 = &zero,
70302 .extra2 = &one,
70303 },
70304 +#endif
70305 {
70306 .procname = "kptr_restrict",
70307 .data = &kptr_restrict,
70308 .maxlen = sizeof(int),
70309 .mode = 0644,
70310 .proc_handler = proc_dointvec_minmax_sysadmin,
70311 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70312 + .extra1 = &two,
70313 +#else
70314 .extra1 = &zero,
70315 +#endif
70316 .extra2 = &two,
70317 },
70318 -#endif
70319 {
70320 .procname = "ngroups_max",
70321 .data = &ngroups_max,
70322 @@ -1225,6 +1267,13 @@ static struct ctl_table vm_table[] = {
70323 .proc_handler = proc_dointvec_minmax,
70324 .extra1 = &zero,
70325 },
70326 + {
70327 + .procname = "heap_stack_gap",
70328 + .data = &sysctl_heap_stack_gap,
70329 + .maxlen = sizeof(sysctl_heap_stack_gap),
70330 + .mode = 0644,
70331 + .proc_handler = proc_doulongvec_minmax,
70332 + },
70333 #else
70334 {
70335 .procname = "nr_trim_pages",
70336 @@ -1729,6 +1778,17 @@ static int test_perm(int mode, int op)
70337 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
70338 {
70339 int mode;
70340 + int error;
70341 +
70342 + if (table->parent != NULL && table->parent->procname != NULL &&
70343 + table->procname != NULL &&
70344 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
70345 + return -EACCES;
70346 + if (gr_handle_chroot_sysctl(op))
70347 + return -EACCES;
70348 + error = gr_handle_sysctl(table, op);
70349 + if (error)
70350 + return error;
70351
70352 if (root->permissions)
70353 mode = root->permissions(root, current->nsproxy, table);
70354 @@ -2133,6 +2193,16 @@ int proc_dostring(struct ctl_table *table, int write,
70355 buffer, lenp, ppos);
70356 }
70357
70358 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70359 + void __user *buffer, size_t *lenp, loff_t *ppos)
70360 +{
70361 + if (write && !capable(CAP_SYS_MODULE))
70362 + return -EPERM;
70363 +
70364 + return _proc_do_string(table->data, table->maxlen, write,
70365 + buffer, lenp, ppos);
70366 +}
70367 +
70368 static size_t proc_skip_spaces(char **buf)
70369 {
70370 size_t ret;
70371 @@ -2238,6 +2308,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70372 len = strlen(tmp);
70373 if (len > *size)
70374 len = *size;
70375 + if (len > sizeof(tmp))
70376 + len = sizeof(tmp);
70377 if (copy_to_user(*buf, tmp, len))
70378 return -EFAULT;
70379 *size -= len;
70380 @@ -2554,8 +2626,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70381 *i = val;
70382 } else {
70383 val = convdiv * (*i) / convmul;
70384 - if (!first)
70385 + if (!first) {
70386 err = proc_put_char(&buffer, &left, '\t');
70387 + if (err)
70388 + break;
70389 + }
70390 err = proc_put_long(&buffer, &left, val, false);
70391 if (err)
70392 break;
70393 @@ -2950,6 +3025,12 @@ int proc_dostring(struct ctl_table *table, int write,
70394 return -ENOSYS;
70395 }
70396
70397 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70398 + void __user *buffer, size_t *lenp, loff_t *ppos)
70399 +{
70400 + return -ENOSYS;
70401 +}
70402 +
70403 int proc_dointvec(struct ctl_table *table, int write,
70404 void __user *buffer, size_t *lenp, loff_t *ppos)
70405 {
70406 @@ -3006,6 +3087,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70407 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70408 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70409 EXPORT_SYMBOL(proc_dostring);
70410 +EXPORT_SYMBOL(proc_dostring_modpriv);
70411 EXPORT_SYMBOL(proc_doulongvec_minmax);
70412 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70413 EXPORT_SYMBOL(register_sysctl_table);
70414 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70415 index a650694..aaeeb20 100644
70416 --- a/kernel/sysctl_binary.c
70417 +++ b/kernel/sysctl_binary.c
70418 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70419 int i;
70420
70421 set_fs(KERNEL_DS);
70422 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70423 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70424 set_fs(old_fs);
70425 if (result < 0)
70426 goto out_kfree;
70427 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70428 }
70429
70430 set_fs(KERNEL_DS);
70431 - result = vfs_write(file, buffer, str - buffer, &pos);
70432 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70433 set_fs(old_fs);
70434 if (result < 0)
70435 goto out_kfree;
70436 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70437 int i;
70438
70439 set_fs(KERNEL_DS);
70440 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70441 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70442 set_fs(old_fs);
70443 if (result < 0)
70444 goto out_kfree;
70445 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70446 }
70447
70448 set_fs(KERNEL_DS);
70449 - result = vfs_write(file, buffer, str - buffer, &pos);
70450 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70451 set_fs(old_fs);
70452 if (result < 0)
70453 goto out_kfree;
70454 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70455 int i;
70456
70457 set_fs(KERNEL_DS);
70458 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70459 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70460 set_fs(old_fs);
70461 if (result < 0)
70462 goto out;
70463 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70464 __le16 dnaddr;
70465
70466 set_fs(KERNEL_DS);
70467 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70468 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70469 set_fs(old_fs);
70470 if (result < 0)
70471 goto out;
70472 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70473 le16_to_cpu(dnaddr) & 0x3ff);
70474
70475 set_fs(KERNEL_DS);
70476 - result = vfs_write(file, buf, len, &pos);
70477 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70478 set_fs(old_fs);
70479 if (result < 0)
70480 goto out;
70481 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
70482 index 362da65..ab8ef8c 100644
70483 --- a/kernel/sysctl_check.c
70484 +++ b/kernel/sysctl_check.c
70485 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
70486 set_fail(&fail, table, "Directory with extra2");
70487 } else {
70488 if ((table->proc_handler == proc_dostring) ||
70489 + (table->proc_handler == proc_dostring_modpriv) ||
70490 (table->proc_handler == proc_dointvec) ||
70491 (table->proc_handler == proc_dointvec_minmax) ||
70492 (table->proc_handler == proc_dointvec_jiffies) ||
70493 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70494 index e660464..c8b9e67 100644
70495 --- a/kernel/taskstats.c
70496 +++ b/kernel/taskstats.c
70497 @@ -27,9 +27,12 @@
70498 #include <linux/cgroup.h>
70499 #include <linux/fs.h>
70500 #include <linux/file.h>
70501 +#include <linux/grsecurity.h>
70502 #include <net/genetlink.h>
70503 #include <linux/atomic.h>
70504
70505 +extern int gr_is_taskstats_denied(int pid);
70506 +
70507 /*
70508 * Maximum length of a cpumask that can be specified in
70509 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70510 @@ -556,6 +559,9 @@ err:
70511
70512 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70513 {
70514 + if (gr_is_taskstats_denied(current->pid))
70515 + return -EACCES;
70516 +
70517 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70518 return cmd_attr_register_cpumask(info);
70519 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70520 diff --git a/kernel/time.c b/kernel/time.c
70521 index 73e416d..cfc6f69 100644
70522 --- a/kernel/time.c
70523 +++ b/kernel/time.c
70524 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70525 return error;
70526
70527 if (tz) {
70528 + /* we log in do_settimeofday called below, so don't log twice
70529 + */
70530 + if (!tv)
70531 + gr_log_timechange();
70532 +
70533 /* SMP safe, global irq locking makes it work. */
70534 sys_tz = *tz;
70535 update_vsyscall_tz();
70536 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70537 index 8a46f5d..bbe6f9c 100644
70538 --- a/kernel/time/alarmtimer.c
70539 +++ b/kernel/time/alarmtimer.c
70540 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
70541 struct platform_device *pdev;
70542 int error = 0;
70543 int i;
70544 - struct k_clock alarm_clock = {
70545 + static struct k_clock alarm_clock = {
70546 .clock_getres = alarm_clock_getres,
70547 .clock_get = alarm_clock_get,
70548 .timer_create = alarm_timer_create,
70549 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70550 index fd4a7b1..fae5c2a 100644
70551 --- a/kernel/time/tick-broadcast.c
70552 +++ b/kernel/time/tick-broadcast.c
70553 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70554 * then clear the broadcast bit.
70555 */
70556 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70557 - int cpu = smp_processor_id();
70558 + cpu = smp_processor_id();
70559
70560 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70561 tick_broadcast_clear_oneshot(cpu);
70562 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70563 index 0c63581..e25dcb6 100644
70564 --- a/kernel/time/timekeeping.c
70565 +++ b/kernel/time/timekeeping.c
70566 @@ -14,6 +14,7 @@
70567 #include <linux/init.h>
70568 #include <linux/mm.h>
70569 #include <linux/sched.h>
70570 +#include <linux/grsecurity.h>
70571 #include <linux/syscore_ops.h>
70572 #include <linux/clocksource.h>
70573 #include <linux/jiffies.h>
70574 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
70575 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70576 return -EINVAL;
70577
70578 + gr_log_timechange();
70579 +
70580 write_seqlock_irqsave(&xtime_lock, flags);
70581
70582 timekeeping_forward_now();
70583 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70584 index 3258455..f35227d 100644
70585 --- a/kernel/time/timer_list.c
70586 +++ b/kernel/time/timer_list.c
70587 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70588
70589 static void print_name_offset(struct seq_file *m, void *sym)
70590 {
70591 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70592 + SEQ_printf(m, "<%p>", NULL);
70593 +#else
70594 char symname[KSYM_NAME_LEN];
70595
70596 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70597 SEQ_printf(m, "<%pK>", sym);
70598 else
70599 SEQ_printf(m, "%s", symname);
70600 +#endif
70601 }
70602
70603 static void
70604 @@ -112,7 +116,11 @@ next_one:
70605 static void
70606 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70607 {
70608 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70609 + SEQ_printf(m, " .base: %p\n", NULL);
70610 +#else
70611 SEQ_printf(m, " .base: %pK\n", base);
70612 +#endif
70613 SEQ_printf(m, " .index: %d\n",
70614 base->index);
70615 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70616 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70617 {
70618 struct proc_dir_entry *pe;
70619
70620 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70621 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70622 +#else
70623 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70624 +#endif
70625 if (!pe)
70626 return -ENOMEM;
70627 return 0;
70628 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70629 index 0b537f2..9e71eca 100644
70630 --- a/kernel/time/timer_stats.c
70631 +++ b/kernel/time/timer_stats.c
70632 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70633 static unsigned long nr_entries;
70634 static struct entry entries[MAX_ENTRIES];
70635
70636 -static atomic_t overflow_count;
70637 +static atomic_unchecked_t overflow_count;
70638
70639 /*
70640 * The entries are in a hash-table, for fast lookup:
70641 @@ -140,7 +140,7 @@ static void reset_entries(void)
70642 nr_entries = 0;
70643 memset(entries, 0, sizeof(entries));
70644 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70645 - atomic_set(&overflow_count, 0);
70646 + atomic_set_unchecked(&overflow_count, 0);
70647 }
70648
70649 static struct entry *alloc_entry(void)
70650 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70651 if (likely(entry))
70652 entry->count++;
70653 else
70654 - atomic_inc(&overflow_count);
70655 + atomic_inc_unchecked(&overflow_count);
70656
70657 out_unlock:
70658 raw_spin_unlock_irqrestore(lock, flags);
70659 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70660
70661 static void print_name_offset(struct seq_file *m, unsigned long addr)
70662 {
70663 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70664 + seq_printf(m, "<%p>", NULL);
70665 +#else
70666 char symname[KSYM_NAME_LEN];
70667
70668 if (lookup_symbol_name(addr, symname) < 0)
70669 seq_printf(m, "<%p>", (void *)addr);
70670 else
70671 seq_printf(m, "%s", symname);
70672 +#endif
70673 }
70674
70675 static int tstats_show(struct seq_file *m, void *v)
70676 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70677
70678 seq_puts(m, "Timer Stats Version: v0.2\n");
70679 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70680 - if (atomic_read(&overflow_count))
70681 + if (atomic_read_unchecked(&overflow_count))
70682 seq_printf(m, "Overflow: %d entries\n",
70683 - atomic_read(&overflow_count));
70684 + atomic_read_unchecked(&overflow_count));
70685
70686 for (i = 0; i < nr_entries; i++) {
70687 entry = entries + i;
70688 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70689 {
70690 struct proc_dir_entry *pe;
70691
70692 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70693 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70694 +#else
70695 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70696 +#endif
70697 if (!pe)
70698 return -ENOMEM;
70699 return 0;
70700 diff --git a/kernel/timer.c b/kernel/timer.c
70701 index a297ffc..5e16b0b 100644
70702 --- a/kernel/timer.c
70703 +++ b/kernel/timer.c
70704 @@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
70705 /*
70706 * This function runs timers and the timer-tq in bottom half context.
70707 */
70708 -static void run_timer_softirq(struct softirq_action *h)
70709 +static void run_timer_softirq(void)
70710 {
70711 struct tvec_base *base = __this_cpu_read(tvec_bases);
70712
70713 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70714 index cdea7b5..9b820d4 100644
70715 --- a/kernel/trace/blktrace.c
70716 +++ b/kernel/trace/blktrace.c
70717 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70718 struct blk_trace *bt = filp->private_data;
70719 char buf[16];
70720
70721 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70722 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70723
70724 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70725 }
70726 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70727 return 1;
70728
70729 bt = buf->chan->private_data;
70730 - atomic_inc(&bt->dropped);
70731 + atomic_inc_unchecked(&bt->dropped);
70732 return 0;
70733 }
70734
70735 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70736
70737 bt->dir = dir;
70738 bt->dev = dev;
70739 - atomic_set(&bt->dropped, 0);
70740 + atomic_set_unchecked(&bt->dropped, 0);
70741
70742 ret = -EIO;
70743 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70744 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70745 index 683d559..d70d914 100644
70746 --- a/kernel/trace/ftrace.c
70747 +++ b/kernel/trace/ftrace.c
70748 @@ -1726,12 +1726,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70749 if (unlikely(ftrace_disabled))
70750 return 0;
70751
70752 + ret = ftrace_arch_code_modify_prepare();
70753 + FTRACE_WARN_ON(ret);
70754 + if (ret)
70755 + return 0;
70756 +
70757 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70758 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70759 if (ret) {
70760 ftrace_bug(ret, ip);
70761 - return 0;
70762 }
70763 - return 1;
70764 + return ret ? 0 : 1;
70765 }
70766
70767 /*
70768 @@ -2843,7 +2848,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70769
70770 int
70771 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70772 - void *data)
70773 + void *data)
70774 {
70775 struct ftrace_func_probe *entry;
70776 struct ftrace_page *pg;
70777 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70778 index c4579f1..6a439da 100644
70779 --- a/kernel/trace/trace.c
70780 +++ b/kernel/trace/trace.c
70781 @@ -4258,10 +4258,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70782 };
70783 #endif
70784
70785 -static struct dentry *d_tracer;
70786 -
70787 struct dentry *tracing_init_dentry(void)
70788 {
70789 + static struct dentry *d_tracer;
70790 static int once;
70791
70792 if (d_tracer)
70793 @@ -4281,10 +4280,9 @@ struct dentry *tracing_init_dentry(void)
70794 return d_tracer;
70795 }
70796
70797 -static struct dentry *d_percpu;
70798 -
70799 struct dentry *tracing_dentry_percpu(void)
70800 {
70801 + static struct dentry *d_percpu;
70802 static int once;
70803 struct dentry *d_tracer;
70804
70805 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70806 index c212a7f..7b02394 100644
70807 --- a/kernel/trace/trace_events.c
70808 +++ b/kernel/trace/trace_events.c
70809 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
70810 struct ftrace_module_file_ops {
70811 struct list_head list;
70812 struct module *mod;
70813 - struct file_operations id;
70814 - struct file_operations enable;
70815 - struct file_operations format;
70816 - struct file_operations filter;
70817 };
70818
70819 static struct ftrace_module_file_ops *
70820 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
70821
70822 file_ops->mod = mod;
70823
70824 - file_ops->id = ftrace_event_id_fops;
70825 - file_ops->id.owner = mod;
70826 -
70827 - file_ops->enable = ftrace_enable_fops;
70828 - file_ops->enable.owner = mod;
70829 -
70830 - file_ops->filter = ftrace_event_filter_fops;
70831 - file_ops->filter.owner = mod;
70832 -
70833 - file_ops->format = ftrace_event_format_fops;
70834 - file_ops->format.owner = mod;
70835 + pax_open_kernel();
70836 + *(void **)&mod->trace_id.owner = mod;
70837 + *(void **)&mod->trace_enable.owner = mod;
70838 + *(void **)&mod->trace_filter.owner = mod;
70839 + *(void **)&mod->trace_format.owner = mod;
70840 + pax_close_kernel();
70841
70842 list_add(&file_ops->list, &ftrace_module_file_list);
70843
70844 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
70845
70846 for_each_event(call, start, end) {
70847 __trace_add_event_call(*call, mod,
70848 - &file_ops->id, &file_ops->enable,
70849 - &file_ops->filter, &file_ops->format);
70850 + &mod->trace_id, &mod->trace_enable,
70851 + &mod->trace_filter, &mod->trace_format);
70852 }
70853 }
70854
70855 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
70856 index 00d527c..7c5b1a3 100644
70857 --- a/kernel/trace/trace_kprobe.c
70858 +++ b/kernel/trace/trace_kprobe.c
70859 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70860 long ret;
70861 int maxlen = get_rloc_len(*(u32 *)dest);
70862 u8 *dst = get_rloc_data(dest);
70863 - u8 *src = addr;
70864 + const u8 __user *src = (const u8 __force_user *)addr;
70865 mm_segment_t old_fs = get_fs();
70866 if (!maxlen)
70867 return;
70868 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70869 pagefault_disable();
70870 do
70871 ret = __copy_from_user_inatomic(dst++, src++, 1);
70872 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
70873 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
70874 dst[-1] = '\0';
70875 pagefault_enable();
70876 set_fs(old_fs);
70877 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
70878 ((u8 *)get_rloc_data(dest))[0] = '\0';
70879 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
70880 } else
70881 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
70882 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
70883 get_rloc_offs(*(u32 *)dest));
70884 }
70885 /* Return the length of string -- including null terminal byte */
70886 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
70887 set_fs(KERNEL_DS);
70888 pagefault_disable();
70889 do {
70890 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
70891 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
70892 len++;
70893 } while (c && ret == 0 && len < MAX_STRING_SIZE);
70894 pagefault_enable();
70895 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70896 index fd3c8aa..5f324a6 100644
70897 --- a/kernel/trace/trace_mmiotrace.c
70898 +++ b/kernel/trace/trace_mmiotrace.c
70899 @@ -24,7 +24,7 @@ struct header_iter {
70900 static struct trace_array *mmio_trace_array;
70901 static bool overrun_detected;
70902 static unsigned long prev_overruns;
70903 -static atomic_t dropped_count;
70904 +static atomic_unchecked_t dropped_count;
70905
70906 static void mmio_reset_data(struct trace_array *tr)
70907 {
70908 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70909
70910 static unsigned long count_overruns(struct trace_iterator *iter)
70911 {
70912 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70913 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70914 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70915
70916 if (over > prev_overruns)
70917 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70918 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70919 sizeof(*entry), 0, pc);
70920 if (!event) {
70921 - atomic_inc(&dropped_count);
70922 + atomic_inc_unchecked(&dropped_count);
70923 return;
70924 }
70925 entry = ring_buffer_event_data(event);
70926 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70927 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70928 sizeof(*entry), 0, pc);
70929 if (!event) {
70930 - atomic_inc(&dropped_count);
70931 + atomic_inc_unchecked(&dropped_count);
70932 return;
70933 }
70934 entry = ring_buffer_event_data(event);
70935 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70936 index d9c07f0..c1eeceb 100644
70937 --- a/kernel/trace/trace_output.c
70938 +++ b/kernel/trace/trace_output.c
70939 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
70940
70941 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70942 if (!IS_ERR(p)) {
70943 - p = mangle_path(s->buffer + s->len, p, "\n");
70944 + p = mangle_path(s->buffer + s->len, p, "\n\\");
70945 if (p) {
70946 s->len = p - s->buffer;
70947 return 1;
70948 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70949 index d4545f4..a9010a1 100644
70950 --- a/kernel/trace/trace_stack.c
70951 +++ b/kernel/trace/trace_stack.c
70952 @@ -53,7 +53,7 @@ static inline void check_stack(void)
70953 return;
70954
70955 /* we do not handle interrupt stacks yet */
70956 - if (!object_is_on_stack(&this_size))
70957 + if (!object_starts_on_stack(&this_size))
70958 return;
70959
70960 local_irq_save(flags);
70961 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
70962 index 209b379..7f76423 100644
70963 --- a/kernel/trace/trace_workqueue.c
70964 +++ b/kernel/trace/trace_workqueue.c
70965 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
70966 int cpu;
70967 pid_t pid;
70968 /* Can be inserted from interrupt or user context, need to be atomic */
70969 - atomic_t inserted;
70970 + atomic_unchecked_t inserted;
70971 /*
70972 * Don't need to be atomic, works are serialized in a single workqueue thread
70973 * on a single CPU.
70974 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
70975 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
70976 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
70977 if (node->pid == wq_thread->pid) {
70978 - atomic_inc(&node->inserted);
70979 + atomic_inc_unchecked(&node->inserted);
70980 goto found;
70981 }
70982 }
70983 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
70984 tsk = get_pid_task(pid, PIDTYPE_PID);
70985 if (tsk) {
70986 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
70987 - atomic_read(&cws->inserted), cws->executed,
70988 + atomic_read_unchecked(&cws->inserted), cws->executed,
70989 tsk->comm);
70990 put_task_struct(tsk);
70991 }
70992 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70993 index 8745ac7..d144e37 100644
70994 --- a/lib/Kconfig.debug
70995 +++ b/lib/Kconfig.debug
70996 @@ -1103,6 +1103,7 @@ config LATENCYTOP
70997 depends on DEBUG_KERNEL
70998 depends on STACKTRACE_SUPPORT
70999 depends on PROC_FS
71000 + depends on !GRKERNSEC_HIDESYM
71001 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71002 select KALLSYMS
71003 select KALLSYMS_ALL
71004 diff --git a/lib/bitmap.c b/lib/bitmap.c
71005 index 0d4a127..33a06c7 100644
71006 --- a/lib/bitmap.c
71007 +++ b/lib/bitmap.c
71008 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71009 {
71010 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71011 u32 chunk;
71012 - const char __user __force *ubuf = (const char __user __force *)buf;
71013 + const char __user *ubuf = (const char __force_user *)buf;
71014
71015 bitmap_zero(maskp, nmaskbits);
71016
71017 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
71018 {
71019 if (!access_ok(VERIFY_READ, ubuf, ulen))
71020 return -EFAULT;
71021 - return __bitmap_parse((const char __force *)ubuf,
71022 + return __bitmap_parse((const char __force_kernel *)ubuf,
71023 ulen, 1, maskp, nmaskbits);
71024
71025 }
71026 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71027 {
71028 unsigned a, b;
71029 int c, old_c, totaldigits;
71030 - const char __user __force *ubuf = (const char __user __force *)buf;
71031 + const char __user *ubuf = (const char __force_user *)buf;
71032 int exp_digit, in_range;
71033
71034 totaldigits = c = 0;
71035 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71036 {
71037 if (!access_ok(VERIFY_READ, ubuf, ulen))
71038 return -EFAULT;
71039 - return __bitmap_parselist((const char __force *)ubuf,
71040 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71041 ulen, 1, maskp, nmaskbits);
71042 }
71043 EXPORT_SYMBOL(bitmap_parselist_user);
71044 diff --git a/lib/bug.c b/lib/bug.c
71045 index a28c141..2bd3d95 100644
71046 --- a/lib/bug.c
71047 +++ b/lib/bug.c
71048 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71049 return BUG_TRAP_TYPE_NONE;
71050
71051 bug = find_bug(bugaddr);
71052 + if (!bug)
71053 + return BUG_TRAP_TYPE_NONE;
71054
71055 file = NULL;
71056 line = 0;
71057 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71058 index 0ab9ae8..f01ceca 100644
71059 --- a/lib/debugobjects.c
71060 +++ b/lib/debugobjects.c
71061 @@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71062 if (limit > 4)
71063 return;
71064
71065 - is_on_stack = object_is_on_stack(addr);
71066 + is_on_stack = object_starts_on_stack(addr);
71067 if (is_on_stack == onstack)
71068 return;
71069
71070 diff --git a/lib/devres.c b/lib/devres.c
71071 index 9676617..5149e15 100644
71072 --- a/lib/devres.c
71073 +++ b/lib/devres.c
71074 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71075 void devm_iounmap(struct device *dev, void __iomem *addr)
71076 {
71077 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71078 - (void *)addr));
71079 + (void __force *)addr));
71080 iounmap(addr);
71081 }
71082 EXPORT_SYMBOL(devm_iounmap);
71083 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71084 {
71085 ioport_unmap(addr);
71086 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71087 - devm_ioport_map_match, (void *)addr));
71088 + devm_ioport_map_match, (void __force *)addr));
71089 }
71090 EXPORT_SYMBOL(devm_ioport_unmap);
71091
71092 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71093 index fea790a..ebb0e82 100644
71094 --- a/lib/dma-debug.c
71095 +++ b/lib/dma-debug.c
71096 @@ -925,7 +925,7 @@ out:
71097
71098 static void check_for_stack(struct device *dev, void *addr)
71099 {
71100 - if (object_is_on_stack(addr))
71101 + if (object_starts_on_stack(addr))
71102 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71103 "stack [addr=%p]\n", addr);
71104 }
71105 diff --git a/lib/extable.c b/lib/extable.c
71106 index 4cac81e..63e9b8f 100644
71107 --- a/lib/extable.c
71108 +++ b/lib/extable.c
71109 @@ -13,6 +13,7 @@
71110 #include <linux/init.h>
71111 #include <linux/sort.h>
71112 #include <asm/uaccess.h>
71113 +#include <asm/pgtable.h>
71114
71115 #ifndef ARCH_HAS_SORT_EXTABLE
71116 /*
71117 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
71118 void sort_extable(struct exception_table_entry *start,
71119 struct exception_table_entry *finish)
71120 {
71121 + pax_open_kernel();
71122 sort(start, finish - start, sizeof(struct exception_table_entry),
71123 cmp_ex, NULL);
71124 + pax_close_kernel();
71125 }
71126
71127 #ifdef CONFIG_MODULES
71128 diff --git a/lib/inflate.c b/lib/inflate.c
71129 index 013a761..c28f3fc 100644
71130 --- a/lib/inflate.c
71131 +++ b/lib/inflate.c
71132 @@ -269,7 +269,7 @@ static void free(void *where)
71133 malloc_ptr = free_mem_ptr;
71134 }
71135 #else
71136 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71137 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71138 #define free(a) kfree(a)
71139 #endif
71140
71141 diff --git a/lib/ioremap.c b/lib/ioremap.c
71142 index da4e2ad..6373b5f 100644
71143 --- a/lib/ioremap.c
71144 +++ b/lib/ioremap.c
71145 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71146 unsigned long next;
71147
71148 phys_addr -= addr;
71149 - pmd = pmd_alloc(&init_mm, pud, addr);
71150 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71151 if (!pmd)
71152 return -ENOMEM;
71153 do {
71154 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71155 unsigned long next;
71156
71157 phys_addr -= addr;
71158 - pud = pud_alloc(&init_mm, pgd, addr);
71159 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71160 if (!pud)
71161 return -ENOMEM;
71162 do {
71163 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71164 index bd2bea9..6b3c95e 100644
71165 --- a/lib/is_single_threaded.c
71166 +++ b/lib/is_single_threaded.c
71167 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71168 struct task_struct *p, *t;
71169 bool ret;
71170
71171 + if (!mm)
71172 + return true;
71173 +
71174 if (atomic_read(&task->signal->live) != 1)
71175 return false;
71176
71177 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71178 index dc63d08..95ae14a 100644
71179 --- a/lib/radix-tree.c
71180 +++ b/lib/radix-tree.c
71181 @@ -78,7 +78,7 @@ struct radix_tree_preload {
71182 int nr;
71183 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
71184 };
71185 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71186 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71187
71188 static inline void *ptr_to_indirect(void *ptr)
71189 {
71190 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71191 index 38e612e..4fb99a8 100644
71192 --- a/lib/vsprintf.c
71193 +++ b/lib/vsprintf.c
71194 @@ -16,6 +16,9 @@
71195 * - scnprintf and vscnprintf
71196 */
71197
71198 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71199 +#define __INCLUDED_BY_HIDESYM 1
71200 +#endif
71201 #include <stdarg.h>
71202 #include <linux/module.h>
71203 #include <linux/types.h>
71204 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71205 char sym[KSYM_SYMBOL_LEN];
71206 if (ext == 'B')
71207 sprint_backtrace(sym, value);
71208 - else if (ext != 'f' && ext != 's')
71209 + else if (ext != 'f' && ext != 's' && ext != 'a')
71210 sprint_symbol(sym, value);
71211 else
71212 kallsyms_lookup(value, NULL, NULL, NULL, sym);
71213 @@ -789,7 +792,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71214 return number(buf, end, *(const netdev_features_t *)addr, spec);
71215 }
71216
71217 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71218 +int kptr_restrict __read_mostly = 2;
71219 +#else
71220 int kptr_restrict __read_mostly;
71221 +#endif
71222
71223 /*
71224 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71225 @@ -803,6 +810,8 @@ int kptr_restrict __read_mostly;
71226 * - 'S' For symbolic direct pointers with offset
71227 * - 's' For symbolic direct pointers without offset
71228 * - 'B' For backtraced symbolic direct pointers with offset
71229 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71230 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71231 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71232 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71233 * - 'M' For a 6-byte MAC address, it prints the address in the
71234 @@ -848,12 +857,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71235 {
71236 if (!ptr && *fmt != 'K') {
71237 /*
71238 - * Print (null) with the same width as a pointer so it makes
71239 + * Print (nil) with the same width as a pointer so it makes
71240 * tabular output look nice.
71241 */
71242 if (spec.field_width == -1)
71243 spec.field_width = 2 * sizeof(void *);
71244 - return string(buf, end, "(null)", spec);
71245 + return string(buf, end, "(nil)", spec);
71246 }
71247
71248 switch (*fmt) {
71249 @@ -863,6 +872,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71250 /* Fallthrough */
71251 case 'S':
71252 case 's':
71253 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71254 + break;
71255 +#else
71256 + return symbol_string(buf, end, ptr, spec, *fmt);
71257 +#endif
71258 + case 'A':
71259 + case 'a':
71260 case 'B':
71261 return symbol_string(buf, end, ptr, spec, *fmt);
71262 case 'R':
71263 @@ -1633,11 +1649,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71264 typeof(type) value; \
71265 if (sizeof(type) == 8) { \
71266 args = PTR_ALIGN(args, sizeof(u32)); \
71267 - *(u32 *)&value = *(u32 *)args; \
71268 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71269 + *(u32 *)&value = *(const u32 *)args; \
71270 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71271 } else { \
71272 args = PTR_ALIGN(args, sizeof(type)); \
71273 - value = *(typeof(type) *)args; \
71274 + value = *(const typeof(type) *)args; \
71275 } \
71276 args += sizeof(type); \
71277 value; \
71278 @@ -1700,7 +1716,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71279 case FORMAT_TYPE_STR: {
71280 const char *str_arg = args;
71281 args += strlen(str_arg) + 1;
71282 - str = string(str, end, (char *)str_arg, spec);
71283 + str = string(str, end, str_arg, spec);
71284 break;
71285 }
71286
71287 diff --git a/localversion-grsec b/localversion-grsec
71288 new file mode 100644
71289 index 0000000..7cd6065
71290 --- /dev/null
71291 +++ b/localversion-grsec
71292 @@ -0,0 +1 @@
71293 +-grsec
71294 diff --git a/mm/Kconfig b/mm/Kconfig
71295 index e338407..49b5b7a 100644
71296 --- a/mm/Kconfig
71297 +++ b/mm/Kconfig
71298 @@ -247,10 +247,10 @@ config KSM
71299 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71300
71301 config DEFAULT_MMAP_MIN_ADDR
71302 - int "Low address space to protect from user allocation"
71303 + int "Low address space to protect from user allocation"
71304 depends on MMU
71305 - default 4096
71306 - help
71307 + default 65536
71308 + help
71309 This is the portion of low virtual memory which should be protected
71310 from userspace allocation. Keeping a user from writing to low pages
71311 can help reduce the impact of kernel NULL pointer bugs.
71312 diff --git a/mm/filemap.c b/mm/filemap.c
71313 index b662757..3081ddd 100644
71314 --- a/mm/filemap.c
71315 +++ b/mm/filemap.c
71316 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71317 struct address_space *mapping = file->f_mapping;
71318
71319 if (!mapping->a_ops->readpage)
71320 - return -ENOEXEC;
71321 + return -ENODEV;
71322 file_accessed(file);
71323 vma->vm_ops = &generic_file_vm_ops;
71324 vma->vm_flags |= VM_CAN_NONLINEAR;
71325 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71326 *pos = i_size_read(inode);
71327
71328 if (limit != RLIM_INFINITY) {
71329 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71330 if (*pos >= limit) {
71331 send_sig(SIGXFSZ, current, 0);
71332 return -EFBIG;
71333 diff --git a/mm/fremap.c b/mm/fremap.c
71334 index 9ed4fd4..c42648d 100644
71335 --- a/mm/fremap.c
71336 +++ b/mm/fremap.c
71337 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71338 retry:
71339 vma = find_vma(mm, start);
71340
71341 +#ifdef CONFIG_PAX_SEGMEXEC
71342 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71343 + goto out;
71344 +#endif
71345 +
71346 /*
71347 * Make sure the vma is shared, that it supports prefaulting,
71348 * and that the remapped range is valid and fully within
71349 diff --git a/mm/highmem.c b/mm/highmem.c
71350 index 57d82c6..e9e0552 100644
71351 --- a/mm/highmem.c
71352 +++ b/mm/highmem.c
71353 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
71354 * So no dangers, even with speculative execution.
71355 */
71356 page = pte_page(pkmap_page_table[i]);
71357 + pax_open_kernel();
71358 pte_clear(&init_mm, (unsigned long)page_address(page),
71359 &pkmap_page_table[i]);
71360 -
71361 + pax_close_kernel();
71362 set_page_address(page, NULL);
71363 need_flush = 1;
71364 }
71365 @@ -186,9 +187,11 @@ start:
71366 }
71367 }
71368 vaddr = PKMAP_ADDR(last_pkmap_nr);
71369 +
71370 + pax_open_kernel();
71371 set_pte_at(&init_mm, vaddr,
71372 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71373 -
71374 + pax_close_kernel();
71375 pkmap_count[last_pkmap_nr] = 1;
71376 set_page_address(page, (void *)vaddr);
71377
71378 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71379 index 8f7fc39..69bf1e9 100644
71380 --- a/mm/huge_memory.c
71381 +++ b/mm/huge_memory.c
71382 @@ -733,7 +733,7 @@ out:
71383 * run pte_offset_map on the pmd, if an huge pmd could
71384 * materialize from under us from a different thread.
71385 */
71386 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71387 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71388 return VM_FAULT_OOM;
71389 /* if an huge pmd materialized from under us just retry later */
71390 if (unlikely(pmd_trans_huge(*pmd)))
71391 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71392 index 24b1787..e0fbc01 100644
71393 --- a/mm/hugetlb.c
71394 +++ b/mm/hugetlb.c
71395 @@ -2425,6 +2425,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71396 return 1;
71397 }
71398
71399 +#ifdef CONFIG_PAX_SEGMEXEC
71400 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71401 +{
71402 + struct mm_struct *mm = vma->vm_mm;
71403 + struct vm_area_struct *vma_m;
71404 + unsigned long address_m;
71405 + pte_t *ptep_m;
71406 +
71407 + vma_m = pax_find_mirror_vma(vma);
71408 + if (!vma_m)
71409 + return;
71410 +
71411 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71412 + address_m = address + SEGMEXEC_TASK_SIZE;
71413 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71414 + get_page(page_m);
71415 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71416 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71417 +}
71418 +#endif
71419 +
71420 /*
71421 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71422 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71423 @@ -2538,6 +2559,11 @@ retry_avoidcopy:
71424 make_huge_pte(vma, new_page, 1));
71425 page_remove_rmap(old_page);
71426 hugepage_add_new_anon_rmap(new_page, vma, address);
71427 +
71428 +#ifdef CONFIG_PAX_SEGMEXEC
71429 + pax_mirror_huge_pte(vma, address, new_page);
71430 +#endif
71431 +
71432 /* Make the old page be freed below */
71433 new_page = old_page;
71434 mmu_notifier_invalidate_range_end(mm,
71435 @@ -2692,6 +2718,10 @@ retry:
71436 && (vma->vm_flags & VM_SHARED)));
71437 set_huge_pte_at(mm, address, ptep, new_pte);
71438
71439 +#ifdef CONFIG_PAX_SEGMEXEC
71440 + pax_mirror_huge_pte(vma, address, page);
71441 +#endif
71442 +
71443 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71444 /* Optimization, do the COW without a second fault */
71445 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71446 @@ -2721,6 +2751,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71447 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71448 struct hstate *h = hstate_vma(vma);
71449
71450 +#ifdef CONFIG_PAX_SEGMEXEC
71451 + struct vm_area_struct *vma_m;
71452 +#endif
71453 +
71454 address &= huge_page_mask(h);
71455
71456 ptep = huge_pte_offset(mm, address);
71457 @@ -2734,6 +2768,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71458 VM_FAULT_SET_HINDEX(h - hstates);
71459 }
71460
71461 +#ifdef CONFIG_PAX_SEGMEXEC
71462 + vma_m = pax_find_mirror_vma(vma);
71463 + if (vma_m) {
71464 + unsigned long address_m;
71465 +
71466 + if (vma->vm_start > vma_m->vm_start) {
71467 + address_m = address;
71468 + address -= SEGMEXEC_TASK_SIZE;
71469 + vma = vma_m;
71470 + h = hstate_vma(vma);
71471 + } else
71472 + address_m = address + SEGMEXEC_TASK_SIZE;
71473 +
71474 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71475 + return VM_FAULT_OOM;
71476 + address_m &= HPAGE_MASK;
71477 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71478 + }
71479 +#endif
71480 +
71481 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71482 if (!ptep)
71483 return VM_FAULT_OOM;
71484 diff --git a/mm/internal.h b/mm/internal.h
71485 index 2189af4..f2ca332 100644
71486 --- a/mm/internal.h
71487 +++ b/mm/internal.h
71488 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71489 * in mm/page_alloc.c
71490 */
71491 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71492 +extern void free_compound_page(struct page *page);
71493 extern void prep_compound_page(struct page *page, unsigned long order);
71494 #ifdef CONFIG_MEMORY_FAILURE
71495 extern bool is_free_buddy_page(struct page *page);
71496 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71497 index 45eb621..6ccd8ea 100644
71498 --- a/mm/kmemleak.c
71499 +++ b/mm/kmemleak.c
71500 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71501
71502 for (i = 0; i < object->trace_len; i++) {
71503 void *ptr = (void *)object->trace[i];
71504 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71505 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71506 }
71507 }
71508
71509 diff --git a/mm/maccess.c b/mm/maccess.c
71510 index d53adf9..03a24bf 100644
71511 --- a/mm/maccess.c
71512 +++ b/mm/maccess.c
71513 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71514 set_fs(KERNEL_DS);
71515 pagefault_disable();
71516 ret = __copy_from_user_inatomic(dst,
71517 - (__force const void __user *)src, size);
71518 + (const void __force_user *)src, size);
71519 pagefault_enable();
71520 set_fs(old_fs);
71521
71522 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71523
71524 set_fs(KERNEL_DS);
71525 pagefault_disable();
71526 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71527 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71528 pagefault_enable();
71529 set_fs(old_fs);
71530
71531 diff --git a/mm/madvise.c b/mm/madvise.c
71532 index 74bf193..feb6fd3 100644
71533 --- a/mm/madvise.c
71534 +++ b/mm/madvise.c
71535 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71536 pgoff_t pgoff;
71537 unsigned long new_flags = vma->vm_flags;
71538
71539 +#ifdef CONFIG_PAX_SEGMEXEC
71540 + struct vm_area_struct *vma_m;
71541 +#endif
71542 +
71543 switch (behavior) {
71544 case MADV_NORMAL:
71545 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71546 @@ -110,6 +114,13 @@ success:
71547 /*
71548 * vm_flags is protected by the mmap_sem held in write mode.
71549 */
71550 +
71551 +#ifdef CONFIG_PAX_SEGMEXEC
71552 + vma_m = pax_find_mirror_vma(vma);
71553 + if (vma_m)
71554 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71555 +#endif
71556 +
71557 vma->vm_flags = new_flags;
71558
71559 out:
71560 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71561 struct vm_area_struct ** prev,
71562 unsigned long start, unsigned long end)
71563 {
71564 +
71565 +#ifdef CONFIG_PAX_SEGMEXEC
71566 + struct vm_area_struct *vma_m;
71567 +#endif
71568 +
71569 *prev = vma;
71570 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71571 return -EINVAL;
71572 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71573 zap_page_range(vma, start, end - start, &details);
71574 } else
71575 zap_page_range(vma, start, end - start, NULL);
71576 +
71577 +#ifdef CONFIG_PAX_SEGMEXEC
71578 + vma_m = pax_find_mirror_vma(vma);
71579 + if (vma_m) {
71580 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71581 + struct zap_details details = {
71582 + .nonlinear_vma = vma_m,
71583 + .last_index = ULONG_MAX,
71584 + };
71585 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71586 + } else
71587 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71588 + }
71589 +#endif
71590 +
71591 return 0;
71592 }
71593
71594 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71595 if (end < start)
71596 goto out;
71597
71598 +#ifdef CONFIG_PAX_SEGMEXEC
71599 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71600 + if (end > SEGMEXEC_TASK_SIZE)
71601 + goto out;
71602 + } else
71603 +#endif
71604 +
71605 + if (end > TASK_SIZE)
71606 + goto out;
71607 +
71608 error = 0;
71609 if (end == start)
71610 goto out;
71611 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71612 index 56080ea..115071e 100644
71613 --- a/mm/memory-failure.c
71614 +++ b/mm/memory-failure.c
71615 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71616
71617 int sysctl_memory_failure_recovery __read_mostly = 1;
71618
71619 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71620 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71621
71622 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71623
71624 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
71625 si.si_signo = SIGBUS;
71626 si.si_errno = 0;
71627 si.si_code = BUS_MCEERR_AO;
71628 - si.si_addr = (void *)addr;
71629 + si.si_addr = (void __user *)addr;
71630 #ifdef __ARCH_SI_TRAPNO
71631 si.si_trapno = trapno;
71632 #endif
71633 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
71634 }
71635
71636 nr_pages = 1 << compound_trans_order(hpage);
71637 - atomic_long_add(nr_pages, &mce_bad_pages);
71638 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71639
71640 /*
71641 * We need/can do nothing about count=0 pages.
71642 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
71643 if (!PageHWPoison(hpage)
71644 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71645 || (p != hpage && TestSetPageHWPoison(hpage))) {
71646 - atomic_long_sub(nr_pages, &mce_bad_pages);
71647 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71648 return 0;
71649 }
71650 set_page_hwpoison_huge_page(hpage);
71651 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
71652 }
71653 if (hwpoison_filter(p)) {
71654 if (TestClearPageHWPoison(p))
71655 - atomic_long_sub(nr_pages, &mce_bad_pages);
71656 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71657 unlock_page(hpage);
71658 put_page(hpage);
71659 return 0;
71660 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
71661 return 0;
71662 }
71663 if (TestClearPageHWPoison(p))
71664 - atomic_long_sub(nr_pages, &mce_bad_pages);
71665 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71666 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71667 return 0;
71668 }
71669 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
71670 */
71671 if (TestClearPageHWPoison(page)) {
71672 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71673 - atomic_long_sub(nr_pages, &mce_bad_pages);
71674 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71675 freeit = 1;
71676 if (PageHuge(page))
71677 clear_page_hwpoison_huge_page(page);
71678 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71679 }
71680 done:
71681 if (!PageHWPoison(hpage))
71682 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71683 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71684 set_page_hwpoison_huge_page(hpage);
71685 dequeue_hwpoisoned_huge_page(hpage);
71686 /* keep elevated page count for bad page */
71687 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
71688 return ret;
71689
71690 done:
71691 - atomic_long_add(1, &mce_bad_pages);
71692 + atomic_long_add_unchecked(1, &mce_bad_pages);
71693 SetPageHWPoison(page);
71694 /* keep elevated page count for bad page */
71695 return ret;
71696 diff --git a/mm/memory.c b/mm/memory.c
71697 index 10b4dda..06857f3 100644
71698 --- a/mm/memory.c
71699 +++ b/mm/memory.c
71700 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71701 return;
71702
71703 pmd = pmd_offset(pud, start);
71704 +
71705 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71706 pud_clear(pud);
71707 pmd_free_tlb(tlb, pmd, start);
71708 +#endif
71709 +
71710 }
71711
71712 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71713 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71714 if (end - 1 > ceiling - 1)
71715 return;
71716
71717 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71718 pud = pud_offset(pgd, start);
71719 pgd_clear(pgd);
71720 pud_free_tlb(tlb, pud, start);
71721 +#endif
71722 +
71723 }
71724
71725 /*
71726 @@ -1593,12 +1600,6 @@ no_page_table:
71727 return page;
71728 }
71729
71730 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71731 -{
71732 - return stack_guard_page_start(vma, addr) ||
71733 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71734 -}
71735 -
71736 /**
71737 * __get_user_pages() - pin user pages in memory
71738 * @tsk: task_struct of target task
71739 @@ -1671,10 +1672,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71740 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71741 i = 0;
71742
71743 - do {
71744 + while (nr_pages) {
71745 struct vm_area_struct *vma;
71746
71747 - vma = find_extend_vma(mm, start);
71748 + vma = find_vma(mm, start);
71749 if (!vma && in_gate_area(mm, start)) {
71750 unsigned long pg = start & PAGE_MASK;
71751 pgd_t *pgd;
71752 @@ -1722,7 +1723,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71753 goto next_page;
71754 }
71755
71756 - if (!vma ||
71757 + if (!vma || start < vma->vm_start ||
71758 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71759 !(vm_flags & vma->vm_flags))
71760 return i ? : -EFAULT;
71761 @@ -1749,11 +1750,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71762 int ret;
71763 unsigned int fault_flags = 0;
71764
71765 - /* For mlock, just skip the stack guard page. */
71766 - if (foll_flags & FOLL_MLOCK) {
71767 - if (stack_guard_page(vma, start))
71768 - goto next_page;
71769 - }
71770 if (foll_flags & FOLL_WRITE)
71771 fault_flags |= FAULT_FLAG_WRITE;
71772 if (nonblocking)
71773 @@ -1827,7 +1823,7 @@ next_page:
71774 start += PAGE_SIZE;
71775 nr_pages--;
71776 } while (nr_pages && start < vma->vm_end);
71777 - } while (nr_pages);
71778 + }
71779 return i;
71780 }
71781 EXPORT_SYMBOL(__get_user_pages);
71782 @@ -2034,6 +2030,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71783 page_add_file_rmap(page);
71784 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71785
71786 +#ifdef CONFIG_PAX_SEGMEXEC
71787 + pax_mirror_file_pte(vma, addr, page, ptl);
71788 +#endif
71789 +
71790 retval = 0;
71791 pte_unmap_unlock(pte, ptl);
71792 return retval;
71793 @@ -2068,10 +2068,22 @@ out:
71794 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71795 struct page *page)
71796 {
71797 +
71798 +#ifdef CONFIG_PAX_SEGMEXEC
71799 + struct vm_area_struct *vma_m;
71800 +#endif
71801 +
71802 if (addr < vma->vm_start || addr >= vma->vm_end)
71803 return -EFAULT;
71804 if (!page_count(page))
71805 return -EINVAL;
71806 +
71807 +#ifdef CONFIG_PAX_SEGMEXEC
71808 + vma_m = pax_find_mirror_vma(vma);
71809 + if (vma_m)
71810 + vma_m->vm_flags |= VM_INSERTPAGE;
71811 +#endif
71812 +
71813 vma->vm_flags |= VM_INSERTPAGE;
71814 return insert_page(vma, addr, page, vma->vm_page_prot);
71815 }
71816 @@ -2157,6 +2169,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71817 unsigned long pfn)
71818 {
71819 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71820 + BUG_ON(vma->vm_mirror);
71821
71822 if (addr < vma->vm_start || addr >= vma->vm_end)
71823 return -EFAULT;
71824 @@ -2364,7 +2377,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71825
71826 BUG_ON(pud_huge(*pud));
71827
71828 - pmd = pmd_alloc(mm, pud, addr);
71829 + pmd = (mm == &init_mm) ?
71830 + pmd_alloc_kernel(mm, pud, addr) :
71831 + pmd_alloc(mm, pud, addr);
71832 if (!pmd)
71833 return -ENOMEM;
71834 do {
71835 @@ -2384,7 +2399,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71836 unsigned long next;
71837 int err;
71838
71839 - pud = pud_alloc(mm, pgd, addr);
71840 + pud = (mm == &init_mm) ?
71841 + pud_alloc_kernel(mm, pgd, addr) :
71842 + pud_alloc(mm, pgd, addr);
71843 if (!pud)
71844 return -ENOMEM;
71845 do {
71846 @@ -2472,6 +2489,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71847 copy_user_highpage(dst, src, va, vma);
71848 }
71849
71850 +#ifdef CONFIG_PAX_SEGMEXEC
71851 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71852 +{
71853 + struct mm_struct *mm = vma->vm_mm;
71854 + spinlock_t *ptl;
71855 + pte_t *pte, entry;
71856 +
71857 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71858 + entry = *pte;
71859 + if (!pte_present(entry)) {
71860 + if (!pte_none(entry)) {
71861 + BUG_ON(pte_file(entry));
71862 + free_swap_and_cache(pte_to_swp_entry(entry));
71863 + pte_clear_not_present_full(mm, address, pte, 0);
71864 + }
71865 + } else {
71866 + struct page *page;
71867 +
71868 + flush_cache_page(vma, address, pte_pfn(entry));
71869 + entry = ptep_clear_flush(vma, address, pte);
71870 + BUG_ON(pte_dirty(entry));
71871 + page = vm_normal_page(vma, address, entry);
71872 + if (page) {
71873 + update_hiwater_rss(mm);
71874 + if (PageAnon(page))
71875 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71876 + else
71877 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71878 + page_remove_rmap(page);
71879 + page_cache_release(page);
71880 + }
71881 + }
71882 + pte_unmap_unlock(pte, ptl);
71883 +}
71884 +
71885 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71886 + *
71887 + * the ptl of the lower mapped page is held on entry and is not released on exit
71888 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71889 + */
71890 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71891 +{
71892 + struct mm_struct *mm = vma->vm_mm;
71893 + unsigned long address_m;
71894 + spinlock_t *ptl_m;
71895 + struct vm_area_struct *vma_m;
71896 + pmd_t *pmd_m;
71897 + pte_t *pte_m, entry_m;
71898 +
71899 + BUG_ON(!page_m || !PageAnon(page_m));
71900 +
71901 + vma_m = pax_find_mirror_vma(vma);
71902 + if (!vma_m)
71903 + return;
71904 +
71905 + BUG_ON(!PageLocked(page_m));
71906 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71907 + address_m = address + SEGMEXEC_TASK_SIZE;
71908 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71909 + pte_m = pte_offset_map(pmd_m, address_m);
71910 + ptl_m = pte_lockptr(mm, pmd_m);
71911 + if (ptl != ptl_m) {
71912 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71913 + if (!pte_none(*pte_m))
71914 + goto out;
71915 + }
71916 +
71917 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71918 + page_cache_get(page_m);
71919 + page_add_anon_rmap(page_m, vma_m, address_m);
71920 + inc_mm_counter_fast(mm, MM_ANONPAGES);
71921 + set_pte_at(mm, address_m, pte_m, entry_m);
71922 + update_mmu_cache(vma_m, address_m, entry_m);
71923 +out:
71924 + if (ptl != ptl_m)
71925 + spin_unlock(ptl_m);
71926 + pte_unmap(pte_m);
71927 + unlock_page(page_m);
71928 +}
71929 +
71930 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71931 +{
71932 + struct mm_struct *mm = vma->vm_mm;
71933 + unsigned long address_m;
71934 + spinlock_t *ptl_m;
71935 + struct vm_area_struct *vma_m;
71936 + pmd_t *pmd_m;
71937 + pte_t *pte_m, entry_m;
71938 +
71939 + BUG_ON(!page_m || PageAnon(page_m));
71940 +
71941 + vma_m = pax_find_mirror_vma(vma);
71942 + if (!vma_m)
71943 + return;
71944 +
71945 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71946 + address_m = address + SEGMEXEC_TASK_SIZE;
71947 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71948 + pte_m = pte_offset_map(pmd_m, address_m);
71949 + ptl_m = pte_lockptr(mm, pmd_m);
71950 + if (ptl != ptl_m) {
71951 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71952 + if (!pte_none(*pte_m))
71953 + goto out;
71954 + }
71955 +
71956 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71957 + page_cache_get(page_m);
71958 + page_add_file_rmap(page_m);
71959 + inc_mm_counter_fast(mm, MM_FILEPAGES);
71960 + set_pte_at(mm, address_m, pte_m, entry_m);
71961 + update_mmu_cache(vma_m, address_m, entry_m);
71962 +out:
71963 + if (ptl != ptl_m)
71964 + spin_unlock(ptl_m);
71965 + pte_unmap(pte_m);
71966 +}
71967 +
71968 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71969 +{
71970 + struct mm_struct *mm = vma->vm_mm;
71971 + unsigned long address_m;
71972 + spinlock_t *ptl_m;
71973 + struct vm_area_struct *vma_m;
71974 + pmd_t *pmd_m;
71975 + pte_t *pte_m, entry_m;
71976 +
71977 + vma_m = pax_find_mirror_vma(vma);
71978 + if (!vma_m)
71979 + return;
71980 +
71981 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71982 + address_m = address + SEGMEXEC_TASK_SIZE;
71983 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71984 + pte_m = pte_offset_map(pmd_m, address_m);
71985 + ptl_m = pte_lockptr(mm, pmd_m);
71986 + if (ptl != ptl_m) {
71987 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71988 + if (!pte_none(*pte_m))
71989 + goto out;
71990 + }
71991 +
71992 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71993 + set_pte_at(mm, address_m, pte_m, entry_m);
71994 +out:
71995 + if (ptl != ptl_m)
71996 + spin_unlock(ptl_m);
71997 + pte_unmap(pte_m);
71998 +}
71999 +
72000 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72001 +{
72002 + struct page *page_m;
72003 + pte_t entry;
72004 +
72005 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72006 + goto out;
72007 +
72008 + entry = *pte;
72009 + page_m = vm_normal_page(vma, address, entry);
72010 + if (!page_m)
72011 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72012 + else if (PageAnon(page_m)) {
72013 + if (pax_find_mirror_vma(vma)) {
72014 + pte_unmap_unlock(pte, ptl);
72015 + lock_page(page_m);
72016 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72017 + if (pte_same(entry, *pte))
72018 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72019 + else
72020 + unlock_page(page_m);
72021 + }
72022 + } else
72023 + pax_mirror_file_pte(vma, address, page_m, ptl);
72024 +
72025 +out:
72026 + pte_unmap_unlock(pte, ptl);
72027 +}
72028 +#endif
72029 +
72030 /*
72031 * This routine handles present pages, when users try to write
72032 * to a shared page. It is done by copying the page to a new address
72033 @@ -2683,6 +2880,12 @@ gotten:
72034 */
72035 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72036 if (likely(pte_same(*page_table, orig_pte))) {
72037 +
72038 +#ifdef CONFIG_PAX_SEGMEXEC
72039 + if (pax_find_mirror_vma(vma))
72040 + BUG_ON(!trylock_page(new_page));
72041 +#endif
72042 +
72043 if (old_page) {
72044 if (!PageAnon(old_page)) {
72045 dec_mm_counter_fast(mm, MM_FILEPAGES);
72046 @@ -2734,6 +2937,10 @@ gotten:
72047 page_remove_rmap(old_page);
72048 }
72049
72050 +#ifdef CONFIG_PAX_SEGMEXEC
72051 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72052 +#endif
72053 +
72054 /* Free the old page.. */
72055 new_page = old_page;
72056 ret |= VM_FAULT_WRITE;
72057 @@ -3013,6 +3220,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72058 swap_free(entry);
72059 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72060 try_to_free_swap(page);
72061 +
72062 +#ifdef CONFIG_PAX_SEGMEXEC
72063 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72064 +#endif
72065 +
72066 unlock_page(page);
72067 if (swapcache) {
72068 /*
72069 @@ -3036,6 +3248,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72070
72071 /* No need to invalidate - it was non-present before */
72072 update_mmu_cache(vma, address, page_table);
72073 +
72074 +#ifdef CONFIG_PAX_SEGMEXEC
72075 + pax_mirror_anon_pte(vma, address, page, ptl);
72076 +#endif
72077 +
72078 unlock:
72079 pte_unmap_unlock(page_table, ptl);
72080 out:
72081 @@ -3055,40 +3272,6 @@ out_release:
72082 }
72083
72084 /*
72085 - * This is like a special single-page "expand_{down|up}wards()",
72086 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72087 - * doesn't hit another vma.
72088 - */
72089 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72090 -{
72091 - address &= PAGE_MASK;
72092 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72093 - struct vm_area_struct *prev = vma->vm_prev;
72094 -
72095 - /*
72096 - * Is there a mapping abutting this one below?
72097 - *
72098 - * That's only ok if it's the same stack mapping
72099 - * that has gotten split..
72100 - */
72101 - if (prev && prev->vm_end == address)
72102 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72103 -
72104 - expand_downwards(vma, address - PAGE_SIZE);
72105 - }
72106 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72107 - struct vm_area_struct *next = vma->vm_next;
72108 -
72109 - /* As VM_GROWSDOWN but s/below/above/ */
72110 - if (next && next->vm_start == address + PAGE_SIZE)
72111 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72112 -
72113 - expand_upwards(vma, address + PAGE_SIZE);
72114 - }
72115 - return 0;
72116 -}
72117 -
72118 -/*
72119 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72120 * but allow concurrent faults), and pte mapped but not yet locked.
72121 * We return with mmap_sem still held, but pte unmapped and unlocked.
72122 @@ -3097,27 +3280,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72123 unsigned long address, pte_t *page_table, pmd_t *pmd,
72124 unsigned int flags)
72125 {
72126 - struct page *page;
72127 + struct page *page = NULL;
72128 spinlock_t *ptl;
72129 pte_t entry;
72130
72131 - pte_unmap(page_table);
72132 -
72133 - /* Check if we need to add a guard page to the stack */
72134 - if (check_stack_guard_page(vma, address) < 0)
72135 - return VM_FAULT_SIGBUS;
72136 -
72137 - /* Use the zero-page for reads */
72138 if (!(flags & FAULT_FLAG_WRITE)) {
72139 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72140 vma->vm_page_prot));
72141 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72142 + ptl = pte_lockptr(mm, pmd);
72143 + spin_lock(ptl);
72144 if (!pte_none(*page_table))
72145 goto unlock;
72146 goto setpte;
72147 }
72148
72149 /* Allocate our own private page. */
72150 + pte_unmap(page_table);
72151 +
72152 if (unlikely(anon_vma_prepare(vma)))
72153 goto oom;
72154 page = alloc_zeroed_user_highpage_movable(vma, address);
72155 @@ -3136,6 +3315,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72156 if (!pte_none(*page_table))
72157 goto release;
72158
72159 +#ifdef CONFIG_PAX_SEGMEXEC
72160 + if (pax_find_mirror_vma(vma))
72161 + BUG_ON(!trylock_page(page));
72162 +#endif
72163 +
72164 inc_mm_counter_fast(mm, MM_ANONPAGES);
72165 page_add_new_anon_rmap(page, vma, address);
72166 setpte:
72167 @@ -3143,6 +3327,12 @@ setpte:
72168
72169 /* No need to invalidate - it was non-present before */
72170 update_mmu_cache(vma, address, page_table);
72171 +
72172 +#ifdef CONFIG_PAX_SEGMEXEC
72173 + if (page)
72174 + pax_mirror_anon_pte(vma, address, page, ptl);
72175 +#endif
72176 +
72177 unlock:
72178 pte_unmap_unlock(page_table, ptl);
72179 return 0;
72180 @@ -3286,6 +3476,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72181 */
72182 /* Only go through if we didn't race with anybody else... */
72183 if (likely(pte_same(*page_table, orig_pte))) {
72184 +
72185 +#ifdef CONFIG_PAX_SEGMEXEC
72186 + if (anon && pax_find_mirror_vma(vma))
72187 + BUG_ON(!trylock_page(page));
72188 +#endif
72189 +
72190 flush_icache_page(vma, page);
72191 entry = mk_pte(page, vma->vm_page_prot);
72192 if (flags & FAULT_FLAG_WRITE)
72193 @@ -3305,6 +3501,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72194
72195 /* no need to invalidate: a not-present page won't be cached */
72196 update_mmu_cache(vma, address, page_table);
72197 +
72198 +#ifdef CONFIG_PAX_SEGMEXEC
72199 + if (anon)
72200 + pax_mirror_anon_pte(vma, address, page, ptl);
72201 + else
72202 + pax_mirror_file_pte(vma, address, page, ptl);
72203 +#endif
72204 +
72205 } else {
72206 if (cow_page)
72207 mem_cgroup_uncharge_page(cow_page);
72208 @@ -3458,6 +3662,12 @@ int handle_pte_fault(struct mm_struct *mm,
72209 if (flags & FAULT_FLAG_WRITE)
72210 flush_tlb_fix_spurious_fault(vma, address);
72211 }
72212 +
72213 +#ifdef CONFIG_PAX_SEGMEXEC
72214 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72215 + return 0;
72216 +#endif
72217 +
72218 unlock:
72219 pte_unmap_unlock(pte, ptl);
72220 return 0;
72221 @@ -3474,6 +3684,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72222 pmd_t *pmd;
72223 pte_t *pte;
72224
72225 +#ifdef CONFIG_PAX_SEGMEXEC
72226 + struct vm_area_struct *vma_m;
72227 +#endif
72228 +
72229 __set_current_state(TASK_RUNNING);
72230
72231 count_vm_event(PGFAULT);
72232 @@ -3485,6 +3699,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72233 if (unlikely(is_vm_hugetlb_page(vma)))
72234 return hugetlb_fault(mm, vma, address, flags);
72235
72236 +#ifdef CONFIG_PAX_SEGMEXEC
72237 + vma_m = pax_find_mirror_vma(vma);
72238 + if (vma_m) {
72239 + unsigned long address_m;
72240 + pgd_t *pgd_m;
72241 + pud_t *pud_m;
72242 + pmd_t *pmd_m;
72243 +
72244 + if (vma->vm_start > vma_m->vm_start) {
72245 + address_m = address;
72246 + address -= SEGMEXEC_TASK_SIZE;
72247 + vma = vma_m;
72248 + } else
72249 + address_m = address + SEGMEXEC_TASK_SIZE;
72250 +
72251 + pgd_m = pgd_offset(mm, address_m);
72252 + pud_m = pud_alloc(mm, pgd_m, address_m);
72253 + if (!pud_m)
72254 + return VM_FAULT_OOM;
72255 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72256 + if (!pmd_m)
72257 + return VM_FAULT_OOM;
72258 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72259 + return VM_FAULT_OOM;
72260 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72261 + }
72262 +#endif
72263 +
72264 pgd = pgd_offset(mm, address);
72265 pud = pud_alloc(mm, pgd, address);
72266 if (!pud)
72267 @@ -3514,7 +3756,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72268 * run pte_offset_map on the pmd, if an huge pmd could
72269 * materialize from under us from a different thread.
72270 */
72271 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72272 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72273 return VM_FAULT_OOM;
72274 /* if an huge pmd materialized from under us just retry later */
72275 if (unlikely(pmd_trans_huge(*pmd)))
72276 @@ -3551,6 +3793,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72277 spin_unlock(&mm->page_table_lock);
72278 return 0;
72279 }
72280 +
72281 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72282 +{
72283 + pud_t *new = pud_alloc_one(mm, address);
72284 + if (!new)
72285 + return -ENOMEM;
72286 +
72287 + smp_wmb(); /* See comment in __pte_alloc */
72288 +
72289 + spin_lock(&mm->page_table_lock);
72290 + if (pgd_present(*pgd)) /* Another has populated it */
72291 + pud_free(mm, new);
72292 + else
72293 + pgd_populate_kernel(mm, pgd, new);
72294 + spin_unlock(&mm->page_table_lock);
72295 + return 0;
72296 +}
72297 #endif /* __PAGETABLE_PUD_FOLDED */
72298
72299 #ifndef __PAGETABLE_PMD_FOLDED
72300 @@ -3581,6 +3840,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72301 spin_unlock(&mm->page_table_lock);
72302 return 0;
72303 }
72304 +
72305 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72306 +{
72307 + pmd_t *new = pmd_alloc_one(mm, address);
72308 + if (!new)
72309 + return -ENOMEM;
72310 +
72311 + smp_wmb(); /* See comment in __pte_alloc */
72312 +
72313 + spin_lock(&mm->page_table_lock);
72314 +#ifndef __ARCH_HAS_4LEVEL_HACK
72315 + if (pud_present(*pud)) /* Another has populated it */
72316 + pmd_free(mm, new);
72317 + else
72318 + pud_populate_kernel(mm, pud, new);
72319 +#else
72320 + if (pgd_present(*pud)) /* Another has populated it */
72321 + pmd_free(mm, new);
72322 + else
72323 + pgd_populate_kernel(mm, pud, new);
72324 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72325 + spin_unlock(&mm->page_table_lock);
72326 + return 0;
72327 +}
72328 #endif /* __PAGETABLE_PMD_FOLDED */
72329
72330 int make_pages_present(unsigned long addr, unsigned long end)
72331 @@ -3618,7 +3901,7 @@ static int __init gate_vma_init(void)
72332 gate_vma.vm_start = FIXADDR_USER_START;
72333 gate_vma.vm_end = FIXADDR_USER_END;
72334 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72335 - gate_vma.vm_page_prot = __P101;
72336 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72337 /*
72338 * Make sure the vDSO gets into every core dump.
72339 * Dumping its contents makes post-mortem fully interpretable later
72340 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72341 index 0a37570..2048346 100644
72342 --- a/mm/mempolicy.c
72343 +++ b/mm/mempolicy.c
72344 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72345 unsigned long vmstart;
72346 unsigned long vmend;
72347
72348 +#ifdef CONFIG_PAX_SEGMEXEC
72349 + struct vm_area_struct *vma_m;
72350 +#endif
72351 +
72352 vma = find_vma(mm, start);
72353 if (!vma || vma->vm_start > start)
72354 return -EFAULT;
72355 @@ -679,6 +683,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72356 err = policy_vma(vma, new_pol);
72357 if (err)
72358 goto out;
72359 +
72360 +#ifdef CONFIG_PAX_SEGMEXEC
72361 + vma_m = pax_find_mirror_vma(vma);
72362 + if (vma_m) {
72363 + err = policy_vma(vma_m, new_pol);
72364 + if (err)
72365 + goto out;
72366 + }
72367 +#endif
72368 +
72369 }
72370
72371 out:
72372 @@ -1112,6 +1126,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72373
72374 if (end < start)
72375 return -EINVAL;
72376 +
72377 +#ifdef CONFIG_PAX_SEGMEXEC
72378 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72379 + if (end > SEGMEXEC_TASK_SIZE)
72380 + return -EINVAL;
72381 + } else
72382 +#endif
72383 +
72384 + if (end > TASK_SIZE)
72385 + return -EINVAL;
72386 +
72387 if (end == start)
72388 return 0;
72389
72390 @@ -1330,6 +1355,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72391 if (!mm)
72392 goto out;
72393
72394 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72395 + if (mm != current->mm &&
72396 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72397 + err = -EPERM;
72398 + goto out;
72399 + }
72400 +#endif
72401 +
72402 /*
72403 * Check if this process has the right to modify the specified
72404 * process. The right exists if the process has administrative
72405 @@ -1339,8 +1372,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72406 rcu_read_lock();
72407 tcred = __task_cred(task);
72408 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72409 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
72410 - !capable(CAP_SYS_NICE)) {
72411 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72412 rcu_read_unlock();
72413 err = -EPERM;
72414 goto out;
72415 diff --git a/mm/migrate.c b/mm/migrate.c
72416 index 1503b6b..156c672 100644
72417 --- a/mm/migrate.c
72418 +++ b/mm/migrate.c
72419 @@ -1370,6 +1370,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72420 if (!mm)
72421 return -EINVAL;
72422
72423 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72424 + if (mm != current->mm &&
72425 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72426 + err = -EPERM;
72427 + goto out;
72428 + }
72429 +#endif
72430 +
72431 /*
72432 * Check if this process has the right to modify the specified
72433 * process. The right exists if the process has administrative
72434 @@ -1379,8 +1387,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72435 rcu_read_lock();
72436 tcred = __task_cred(task);
72437 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
72438 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
72439 - !capable(CAP_SYS_NICE)) {
72440 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
72441 rcu_read_unlock();
72442 err = -EPERM;
72443 goto out;
72444 diff --git a/mm/mlock.c b/mm/mlock.c
72445 index ef726e8..13e0901 100644
72446 --- a/mm/mlock.c
72447 +++ b/mm/mlock.c
72448 @@ -13,6 +13,7 @@
72449 #include <linux/pagemap.h>
72450 #include <linux/mempolicy.h>
72451 #include <linux/syscalls.h>
72452 +#include <linux/security.h>
72453 #include <linux/sched.h>
72454 #include <linux/export.h>
72455 #include <linux/rmap.h>
72456 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72457 return -EINVAL;
72458 if (end == start)
72459 return 0;
72460 + if (end > TASK_SIZE)
72461 + return -EINVAL;
72462 +
72463 vma = find_vma(current->mm, start);
72464 if (!vma || vma->vm_start > start)
72465 return -ENOMEM;
72466 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72467 for (nstart = start ; ; ) {
72468 vm_flags_t newflags;
72469
72470 +#ifdef CONFIG_PAX_SEGMEXEC
72471 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72472 + break;
72473 +#endif
72474 +
72475 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72476
72477 newflags = vma->vm_flags | VM_LOCKED;
72478 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72479 lock_limit >>= PAGE_SHIFT;
72480
72481 /* check against resource limits */
72482 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72483 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72484 error = do_mlock(start, len, 1);
72485 up_write(&current->mm->mmap_sem);
72486 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72487 static int do_mlockall(int flags)
72488 {
72489 struct vm_area_struct * vma, * prev = NULL;
72490 - unsigned int def_flags = 0;
72491
72492 if (flags & MCL_FUTURE)
72493 - def_flags = VM_LOCKED;
72494 - current->mm->def_flags = def_flags;
72495 + current->mm->def_flags |= VM_LOCKED;
72496 + else
72497 + current->mm->def_flags &= ~VM_LOCKED;
72498 if (flags == MCL_FUTURE)
72499 goto out;
72500
72501 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72502 vm_flags_t newflags;
72503
72504 +#ifdef CONFIG_PAX_SEGMEXEC
72505 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72506 + break;
72507 +#endif
72508 +
72509 + BUG_ON(vma->vm_end > TASK_SIZE);
72510 newflags = vma->vm_flags | VM_LOCKED;
72511 if (!(flags & MCL_CURRENT))
72512 newflags &= ~VM_LOCKED;
72513 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72514 lock_limit >>= PAGE_SHIFT;
72515
72516 ret = -ENOMEM;
72517 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72518 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72519 capable(CAP_IPC_LOCK))
72520 ret = do_mlockall(flags);
72521 diff --git a/mm/mmap.c b/mm/mmap.c
72522 index da15a79..314aef3 100644
72523 --- a/mm/mmap.c
72524 +++ b/mm/mmap.c
72525 @@ -46,6 +46,16 @@
72526 #define arch_rebalance_pgtables(addr, len) (addr)
72527 #endif
72528
72529 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72530 +{
72531 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72532 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72533 + up_read(&mm->mmap_sem);
72534 + BUG();
72535 + }
72536 +#endif
72537 +}
72538 +
72539 static void unmap_region(struct mm_struct *mm,
72540 struct vm_area_struct *vma, struct vm_area_struct *prev,
72541 unsigned long start, unsigned long end);
72542 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
72543 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72544 *
72545 */
72546 -pgprot_t protection_map[16] = {
72547 +pgprot_t protection_map[16] __read_only = {
72548 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72549 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72550 };
72551
72552 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72553 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72554 {
72555 - return __pgprot(pgprot_val(protection_map[vm_flags &
72556 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72557 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72558 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72559 +
72560 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72561 + if (!(__supported_pte_mask & _PAGE_NX) &&
72562 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72563 + (vm_flags & (VM_READ | VM_WRITE)))
72564 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72565 +#endif
72566 +
72567 + return prot;
72568 }
72569 EXPORT_SYMBOL(vm_get_page_prot);
72570
72571 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72572 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72573 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72574 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72575 /*
72576 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72577 * other variables. It can be updated by several CPUs frequently.
72578 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72579 struct vm_area_struct *next = vma->vm_next;
72580
72581 might_sleep();
72582 + BUG_ON(vma->vm_mirror);
72583 if (vma->vm_ops && vma->vm_ops->close)
72584 vma->vm_ops->close(vma);
72585 if (vma->vm_file) {
72586 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72587 * not page aligned -Ram Gupta
72588 */
72589 rlim = rlimit(RLIMIT_DATA);
72590 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72591 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72592 (mm->end_data - mm->start_data) > rlim)
72593 goto out;
72594 @@ -689,6 +711,12 @@ static int
72595 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72596 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72597 {
72598 +
72599 +#ifdef CONFIG_PAX_SEGMEXEC
72600 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72601 + return 0;
72602 +#endif
72603 +
72604 if (is_mergeable_vma(vma, file, vm_flags) &&
72605 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72606 if (vma->vm_pgoff == vm_pgoff)
72607 @@ -708,6 +736,12 @@ static int
72608 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72609 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72610 {
72611 +
72612 +#ifdef CONFIG_PAX_SEGMEXEC
72613 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72614 + return 0;
72615 +#endif
72616 +
72617 if (is_mergeable_vma(vma, file, vm_flags) &&
72618 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72619 pgoff_t vm_pglen;
72620 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72621 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72622 struct vm_area_struct *prev, unsigned long addr,
72623 unsigned long end, unsigned long vm_flags,
72624 - struct anon_vma *anon_vma, struct file *file,
72625 + struct anon_vma *anon_vma, struct file *file,
72626 pgoff_t pgoff, struct mempolicy *policy)
72627 {
72628 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72629 struct vm_area_struct *area, *next;
72630 int err;
72631
72632 +#ifdef CONFIG_PAX_SEGMEXEC
72633 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72634 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72635 +
72636 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72637 +#endif
72638 +
72639 /*
72640 * We later require that vma->vm_flags == vm_flags,
72641 * so this tests vma->vm_flags & VM_SPECIAL, too.
72642 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72643 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72644 next = next->vm_next;
72645
72646 +#ifdef CONFIG_PAX_SEGMEXEC
72647 + if (prev)
72648 + prev_m = pax_find_mirror_vma(prev);
72649 + if (area)
72650 + area_m = pax_find_mirror_vma(area);
72651 + if (next)
72652 + next_m = pax_find_mirror_vma(next);
72653 +#endif
72654 +
72655 /*
72656 * Can it merge with the predecessor?
72657 */
72658 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72659 /* cases 1, 6 */
72660 err = vma_adjust(prev, prev->vm_start,
72661 next->vm_end, prev->vm_pgoff, NULL);
72662 - } else /* cases 2, 5, 7 */
72663 +
72664 +#ifdef CONFIG_PAX_SEGMEXEC
72665 + if (!err && prev_m)
72666 + err = vma_adjust(prev_m, prev_m->vm_start,
72667 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72668 +#endif
72669 +
72670 + } else { /* cases 2, 5, 7 */
72671 err = vma_adjust(prev, prev->vm_start,
72672 end, prev->vm_pgoff, NULL);
72673 +
72674 +#ifdef CONFIG_PAX_SEGMEXEC
72675 + if (!err && prev_m)
72676 + err = vma_adjust(prev_m, prev_m->vm_start,
72677 + end_m, prev_m->vm_pgoff, NULL);
72678 +#endif
72679 +
72680 + }
72681 if (err)
72682 return NULL;
72683 khugepaged_enter_vma_merge(prev);
72684 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72685 mpol_equal(policy, vma_policy(next)) &&
72686 can_vma_merge_before(next, vm_flags,
72687 anon_vma, file, pgoff+pglen)) {
72688 - if (prev && addr < prev->vm_end) /* case 4 */
72689 + if (prev && addr < prev->vm_end) { /* case 4 */
72690 err = vma_adjust(prev, prev->vm_start,
72691 addr, prev->vm_pgoff, NULL);
72692 - else /* cases 3, 8 */
72693 +
72694 +#ifdef CONFIG_PAX_SEGMEXEC
72695 + if (!err && prev_m)
72696 + err = vma_adjust(prev_m, prev_m->vm_start,
72697 + addr_m, prev_m->vm_pgoff, NULL);
72698 +#endif
72699 +
72700 + } else { /* cases 3, 8 */
72701 err = vma_adjust(area, addr, next->vm_end,
72702 next->vm_pgoff - pglen, NULL);
72703 +
72704 +#ifdef CONFIG_PAX_SEGMEXEC
72705 + if (!err && area_m)
72706 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72707 + next_m->vm_pgoff - pglen, NULL);
72708 +#endif
72709 +
72710 + }
72711 if (err)
72712 return NULL;
72713 khugepaged_enter_vma_merge(area);
72714 @@ -921,14 +1001,11 @@ none:
72715 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72716 struct file *file, long pages)
72717 {
72718 - const unsigned long stack_flags
72719 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72720 -
72721 if (file) {
72722 mm->shared_vm += pages;
72723 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72724 mm->exec_vm += pages;
72725 - } else if (flags & stack_flags)
72726 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72727 mm->stack_vm += pages;
72728 if (flags & (VM_RESERVED|VM_IO))
72729 mm->reserved_vm += pages;
72730 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72731 * (the exception is when the underlying filesystem is noexec
72732 * mounted, in which case we dont add PROT_EXEC.)
72733 */
72734 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72735 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72736 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72737 prot |= PROT_EXEC;
72738
72739 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72740 /* Obtain the address to map to. we verify (or select) it and ensure
72741 * that it represents a valid section of the address space.
72742 */
72743 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72744 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72745 if (addr & ~PAGE_MASK)
72746 return addr;
72747
72748 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72749 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72750 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72751
72752 +#ifdef CONFIG_PAX_MPROTECT
72753 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72754 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72755 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72756 + gr_log_rwxmmap(file);
72757 +
72758 +#ifdef CONFIG_PAX_EMUPLT
72759 + vm_flags &= ~VM_EXEC;
72760 +#else
72761 + return -EPERM;
72762 +#endif
72763 +
72764 + }
72765 +
72766 + if (!(vm_flags & VM_EXEC))
72767 + vm_flags &= ~VM_MAYEXEC;
72768 +#else
72769 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72770 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72771 +#endif
72772 + else
72773 + vm_flags &= ~VM_MAYWRITE;
72774 + }
72775 +#endif
72776 +
72777 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72778 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72779 + vm_flags &= ~VM_PAGEEXEC;
72780 +#endif
72781 +
72782 if (flags & MAP_LOCKED)
72783 if (!can_do_mlock())
72784 return -EPERM;
72785 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72786 locked += mm->locked_vm;
72787 lock_limit = rlimit(RLIMIT_MEMLOCK);
72788 lock_limit >>= PAGE_SHIFT;
72789 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72790 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72791 return -EAGAIN;
72792 }
72793 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72794 if (error)
72795 return error;
72796
72797 + if (!gr_acl_handle_mmap(file, prot))
72798 + return -EACCES;
72799 +
72800 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72801 }
72802 EXPORT_SYMBOL(do_mmap_pgoff);
72803 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72804 vm_flags_t vm_flags = vma->vm_flags;
72805
72806 /* If it was private or non-writable, the write bit is already clear */
72807 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72808 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72809 return 0;
72810
72811 /* The backer wishes to know when pages are first written to? */
72812 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72813 unsigned long charged = 0;
72814 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72815
72816 +#ifdef CONFIG_PAX_SEGMEXEC
72817 + struct vm_area_struct *vma_m = NULL;
72818 +#endif
72819 +
72820 + /*
72821 + * mm->mmap_sem is required to protect against another thread
72822 + * changing the mappings in case we sleep.
72823 + */
72824 + verify_mm_writelocked(mm);
72825 +
72826 /* Clear old maps */
72827 error = -ENOMEM;
72828 -munmap_back:
72829 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72830 if (vma && vma->vm_start < addr + len) {
72831 if (do_munmap(mm, addr, len))
72832 return -ENOMEM;
72833 - goto munmap_back;
72834 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72835 + BUG_ON(vma && vma->vm_start < addr + len);
72836 }
72837
72838 /* Check against address space limit. */
72839 @@ -1258,6 +1379,16 @@ munmap_back:
72840 goto unacct_error;
72841 }
72842
72843 +#ifdef CONFIG_PAX_SEGMEXEC
72844 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72845 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72846 + if (!vma_m) {
72847 + error = -ENOMEM;
72848 + goto free_vma;
72849 + }
72850 + }
72851 +#endif
72852 +
72853 vma->vm_mm = mm;
72854 vma->vm_start = addr;
72855 vma->vm_end = addr + len;
72856 @@ -1282,6 +1413,19 @@ munmap_back:
72857 error = file->f_op->mmap(file, vma);
72858 if (error)
72859 goto unmap_and_free_vma;
72860 +
72861 +#ifdef CONFIG_PAX_SEGMEXEC
72862 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72863 + added_exe_file_vma(mm);
72864 +#endif
72865 +
72866 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72867 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72868 + vma->vm_flags |= VM_PAGEEXEC;
72869 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72870 + }
72871 +#endif
72872 +
72873 if (vm_flags & VM_EXECUTABLE)
72874 added_exe_file_vma(mm);
72875
72876 @@ -1319,6 +1463,11 @@ munmap_back:
72877 vma_link(mm, vma, prev, rb_link, rb_parent);
72878 file = vma->vm_file;
72879
72880 +#ifdef CONFIG_PAX_SEGMEXEC
72881 + if (vma_m)
72882 + BUG_ON(pax_mirror_vma(vma_m, vma));
72883 +#endif
72884 +
72885 /* Once vma denies write, undo our temporary denial count */
72886 if (correct_wcount)
72887 atomic_inc(&inode->i_writecount);
72888 @@ -1327,6 +1476,7 @@ out:
72889
72890 mm->total_vm += len >> PAGE_SHIFT;
72891 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72892 + track_exec_limit(mm, addr, addr + len, vm_flags);
72893 if (vm_flags & VM_LOCKED) {
72894 if (!mlock_vma_pages_range(vma, addr, addr + len))
72895 mm->locked_vm += (len >> PAGE_SHIFT);
72896 @@ -1344,6 +1494,12 @@ unmap_and_free_vma:
72897 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72898 charged = 0;
72899 free_vma:
72900 +
72901 +#ifdef CONFIG_PAX_SEGMEXEC
72902 + if (vma_m)
72903 + kmem_cache_free(vm_area_cachep, vma_m);
72904 +#endif
72905 +
72906 kmem_cache_free(vm_area_cachep, vma);
72907 unacct_error:
72908 if (charged)
72909 @@ -1351,6 +1507,44 @@ unacct_error:
72910 return error;
72911 }
72912
72913 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72914 +{
72915 + if (!vma) {
72916 +#ifdef CONFIG_STACK_GROWSUP
72917 + if (addr > sysctl_heap_stack_gap)
72918 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72919 + else
72920 + vma = find_vma(current->mm, 0);
72921 + if (vma && (vma->vm_flags & VM_GROWSUP))
72922 + return false;
72923 +#endif
72924 + return true;
72925 + }
72926 +
72927 + if (addr + len > vma->vm_start)
72928 + return false;
72929 +
72930 + if (vma->vm_flags & VM_GROWSDOWN)
72931 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72932 +#ifdef CONFIG_STACK_GROWSUP
72933 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72934 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72935 +#endif
72936 +
72937 + return true;
72938 +}
72939 +
72940 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72941 +{
72942 + if (vma->vm_start < len)
72943 + return -ENOMEM;
72944 + if (!(vma->vm_flags & VM_GROWSDOWN))
72945 + return vma->vm_start - len;
72946 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
72947 + return vma->vm_start - len - sysctl_heap_stack_gap;
72948 + return -ENOMEM;
72949 +}
72950 +
72951 /* Get an address range which is currently unmapped.
72952 * For shmat() with addr=0.
72953 *
72954 @@ -1377,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72955 if (flags & MAP_FIXED)
72956 return addr;
72957
72958 +#ifdef CONFIG_PAX_RANDMMAP
72959 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72960 +#endif
72961 +
72962 if (addr) {
72963 addr = PAGE_ALIGN(addr);
72964 - vma = find_vma(mm, addr);
72965 - if (TASK_SIZE - len >= addr &&
72966 - (!vma || addr + len <= vma->vm_start))
72967 - return addr;
72968 + if (TASK_SIZE - len >= addr) {
72969 + vma = find_vma(mm, addr);
72970 + if (check_heap_stack_gap(vma, addr, len))
72971 + return addr;
72972 + }
72973 }
72974 if (len > mm->cached_hole_size) {
72975 - start_addr = addr = mm->free_area_cache;
72976 + start_addr = addr = mm->free_area_cache;
72977 } else {
72978 - start_addr = addr = TASK_UNMAPPED_BASE;
72979 - mm->cached_hole_size = 0;
72980 + start_addr = addr = mm->mmap_base;
72981 + mm->cached_hole_size = 0;
72982 }
72983
72984 full_search:
72985 @@ -1399,34 +1598,40 @@ full_search:
72986 * Start a new search - just in case we missed
72987 * some holes.
72988 */
72989 - if (start_addr != TASK_UNMAPPED_BASE) {
72990 - addr = TASK_UNMAPPED_BASE;
72991 - start_addr = addr;
72992 + if (start_addr != mm->mmap_base) {
72993 + start_addr = addr = mm->mmap_base;
72994 mm->cached_hole_size = 0;
72995 goto full_search;
72996 }
72997 return -ENOMEM;
72998 }
72999 - if (!vma || addr + len <= vma->vm_start) {
73000 - /*
73001 - * Remember the place where we stopped the search:
73002 - */
73003 - mm->free_area_cache = addr + len;
73004 - return addr;
73005 - }
73006 + if (check_heap_stack_gap(vma, addr, len))
73007 + break;
73008 if (addr + mm->cached_hole_size < vma->vm_start)
73009 mm->cached_hole_size = vma->vm_start - addr;
73010 addr = vma->vm_end;
73011 }
73012 +
73013 + /*
73014 + * Remember the place where we stopped the search:
73015 + */
73016 + mm->free_area_cache = addr + len;
73017 + return addr;
73018 }
73019 #endif
73020
73021 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73022 {
73023 +
73024 +#ifdef CONFIG_PAX_SEGMEXEC
73025 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73026 + return;
73027 +#endif
73028 +
73029 /*
73030 * Is this a new hole at the lowest possible address?
73031 */
73032 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
73033 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
73034 mm->free_area_cache = addr;
73035 mm->cached_hole_size = ~0UL;
73036 }
73037 @@ -1444,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73038 {
73039 struct vm_area_struct *vma;
73040 struct mm_struct *mm = current->mm;
73041 - unsigned long addr = addr0;
73042 + unsigned long base = mm->mmap_base, addr = addr0;
73043
73044 /* requested length too big for entire address space */
73045 if (len > TASK_SIZE)
73046 @@ -1453,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73047 if (flags & MAP_FIXED)
73048 return addr;
73049
73050 +#ifdef CONFIG_PAX_RANDMMAP
73051 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73052 +#endif
73053 +
73054 /* requesting a specific address */
73055 if (addr) {
73056 addr = PAGE_ALIGN(addr);
73057 - vma = find_vma(mm, addr);
73058 - if (TASK_SIZE - len >= addr &&
73059 - (!vma || addr + len <= vma->vm_start))
73060 - return addr;
73061 + if (TASK_SIZE - len >= addr) {
73062 + vma = find_vma(mm, addr);
73063 + if (check_heap_stack_gap(vma, addr, len))
73064 + return addr;
73065 + }
73066 }
73067
73068 /* check if free_area_cache is useful for us */
73069 @@ -1474,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73070 /* make sure it can fit in the remaining address space */
73071 if (addr > len) {
73072 vma = find_vma(mm, addr-len);
73073 - if (!vma || addr <= vma->vm_start)
73074 + if (check_heap_stack_gap(vma, addr - len, len))
73075 /* remember the address as a hint for next time */
73076 return (mm->free_area_cache = addr-len);
73077 }
73078 @@ -1491,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73079 * return with success:
73080 */
73081 vma = find_vma(mm, addr);
73082 - if (!vma || addr+len <= vma->vm_start)
73083 + if (check_heap_stack_gap(vma, addr, len))
73084 /* remember the address as a hint for next time */
73085 return (mm->free_area_cache = addr);
73086
73087 @@ -1500,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73088 mm->cached_hole_size = vma->vm_start - addr;
73089
73090 /* try just below the current vma->vm_start */
73091 - addr = vma->vm_start-len;
73092 - } while (len < vma->vm_start);
73093 + addr = skip_heap_stack_gap(vma, len);
73094 + } while (!IS_ERR_VALUE(addr));
73095
73096 bottomup:
73097 /*
73098 @@ -1510,13 +1720,21 @@ bottomup:
73099 * can happen with large stack limits and large mmap()
73100 * allocations.
73101 */
73102 + mm->mmap_base = TASK_UNMAPPED_BASE;
73103 +
73104 +#ifdef CONFIG_PAX_RANDMMAP
73105 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73106 + mm->mmap_base += mm->delta_mmap;
73107 +#endif
73108 +
73109 + mm->free_area_cache = mm->mmap_base;
73110 mm->cached_hole_size = ~0UL;
73111 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73112 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73113 /*
73114 * Restore the topdown base:
73115 */
73116 - mm->free_area_cache = mm->mmap_base;
73117 + mm->mmap_base = base;
73118 + mm->free_area_cache = base;
73119 mm->cached_hole_size = ~0UL;
73120
73121 return addr;
73122 @@ -1525,6 +1743,12 @@ bottomup:
73123
73124 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73125 {
73126 +
73127 +#ifdef CONFIG_PAX_SEGMEXEC
73128 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73129 + return;
73130 +#endif
73131 +
73132 /*
73133 * Is this a new hole at the highest possible address?
73134 */
73135 @@ -1532,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73136 mm->free_area_cache = addr;
73137
73138 /* dont allow allocations above current base */
73139 - if (mm->free_area_cache > mm->mmap_base)
73140 + if (mm->free_area_cache > mm->mmap_base) {
73141 mm->free_area_cache = mm->mmap_base;
73142 + mm->cached_hole_size = ~0UL;
73143 + }
73144 }
73145
73146 unsigned long
73147 @@ -1629,6 +1855,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73148 return vma;
73149 }
73150
73151 +#ifdef CONFIG_PAX_SEGMEXEC
73152 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73153 +{
73154 + struct vm_area_struct *vma_m;
73155 +
73156 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73157 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73158 + BUG_ON(vma->vm_mirror);
73159 + return NULL;
73160 + }
73161 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73162 + vma_m = vma->vm_mirror;
73163 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73164 + BUG_ON(vma->vm_file != vma_m->vm_file);
73165 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73166 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73167 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73168 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73169 + return vma_m;
73170 +}
73171 +#endif
73172 +
73173 /*
73174 * Verify that the stack growth is acceptable and
73175 * update accounting. This is shared with both the
73176 @@ -1645,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73177 return -ENOMEM;
73178
73179 /* Stack limit test */
73180 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73181 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73182 return -ENOMEM;
73183
73184 @@ -1655,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73185 locked = mm->locked_vm + grow;
73186 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73187 limit >>= PAGE_SHIFT;
73188 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73189 if (locked > limit && !capable(CAP_IPC_LOCK))
73190 return -ENOMEM;
73191 }
73192 @@ -1685,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73193 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73194 * vma is the last one with address > vma->vm_end. Have to extend vma.
73195 */
73196 +#ifndef CONFIG_IA64
73197 +static
73198 +#endif
73199 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73200 {
73201 int error;
73202 + bool locknext;
73203
73204 if (!(vma->vm_flags & VM_GROWSUP))
73205 return -EFAULT;
73206
73207 + /* Also guard against wrapping around to address 0. */
73208 + if (address < PAGE_ALIGN(address+1))
73209 + address = PAGE_ALIGN(address+1);
73210 + else
73211 + return -ENOMEM;
73212 +
73213 /*
73214 * We must make sure the anon_vma is allocated
73215 * so that the anon_vma locking is not a noop.
73216 */
73217 if (unlikely(anon_vma_prepare(vma)))
73218 return -ENOMEM;
73219 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73220 + if (locknext && anon_vma_prepare(vma->vm_next))
73221 + return -ENOMEM;
73222 vma_lock_anon_vma(vma);
73223 + if (locknext)
73224 + vma_lock_anon_vma(vma->vm_next);
73225
73226 /*
73227 * vma->vm_start/vm_end cannot change under us because the caller
73228 * is required to hold the mmap_sem in read mode. We need the
73229 - * anon_vma lock to serialize against concurrent expand_stacks.
73230 - * Also guard against wrapping around to address 0.
73231 + * anon_vma locks to serialize against concurrent expand_stacks
73232 + * and expand_upwards.
73233 */
73234 - if (address < PAGE_ALIGN(address+4))
73235 - address = PAGE_ALIGN(address+4);
73236 - else {
73237 - vma_unlock_anon_vma(vma);
73238 - return -ENOMEM;
73239 - }
73240 error = 0;
73241
73242 /* Somebody else might have raced and expanded it already */
73243 - if (address > vma->vm_end) {
73244 + 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)
73245 + error = -ENOMEM;
73246 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73247 unsigned long size, grow;
73248
73249 size = address - vma->vm_start;
73250 @@ -1730,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73251 }
73252 }
73253 }
73254 + if (locknext)
73255 + vma_unlock_anon_vma(vma->vm_next);
73256 vma_unlock_anon_vma(vma);
73257 khugepaged_enter_vma_merge(vma);
73258 return error;
73259 @@ -1743,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
73260 unsigned long address)
73261 {
73262 int error;
73263 + bool lockprev = false;
73264 + struct vm_area_struct *prev;
73265
73266 /*
73267 * We must make sure the anon_vma is allocated
73268 @@ -1756,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
73269 if (error)
73270 return error;
73271
73272 + prev = vma->vm_prev;
73273 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73274 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73275 +#endif
73276 + if (lockprev && anon_vma_prepare(prev))
73277 + return -ENOMEM;
73278 + if (lockprev)
73279 + vma_lock_anon_vma(prev);
73280 +
73281 vma_lock_anon_vma(vma);
73282
73283 /*
73284 @@ -1765,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
73285 */
73286
73287 /* Somebody else might have raced and expanded it already */
73288 - if (address < vma->vm_start) {
73289 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73290 + error = -ENOMEM;
73291 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73292 unsigned long size, grow;
73293
73294 +#ifdef CONFIG_PAX_SEGMEXEC
73295 + struct vm_area_struct *vma_m;
73296 +
73297 + vma_m = pax_find_mirror_vma(vma);
73298 +#endif
73299 +
73300 size = vma->vm_end - address;
73301 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73302
73303 @@ -1777,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
73304 if (!error) {
73305 vma->vm_start = address;
73306 vma->vm_pgoff -= grow;
73307 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73308 +
73309 +#ifdef CONFIG_PAX_SEGMEXEC
73310 + if (vma_m) {
73311 + vma_m->vm_start -= grow << PAGE_SHIFT;
73312 + vma_m->vm_pgoff -= grow;
73313 + }
73314 +#endif
73315 +
73316 perf_event_mmap(vma);
73317 }
73318 }
73319 }
73320 vma_unlock_anon_vma(vma);
73321 + if (lockprev)
73322 + vma_unlock_anon_vma(prev);
73323 khugepaged_enter_vma_merge(vma);
73324 return error;
73325 }
73326 @@ -1851,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73327 do {
73328 long nrpages = vma_pages(vma);
73329
73330 +#ifdef CONFIG_PAX_SEGMEXEC
73331 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73332 + vma = remove_vma(vma);
73333 + continue;
73334 + }
73335 +#endif
73336 +
73337 mm->total_vm -= nrpages;
73338 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73339 vma = remove_vma(vma);
73340 @@ -1896,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73341 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73342 vma->vm_prev = NULL;
73343 do {
73344 +
73345 +#ifdef CONFIG_PAX_SEGMEXEC
73346 + if (vma->vm_mirror) {
73347 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73348 + vma->vm_mirror->vm_mirror = NULL;
73349 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73350 + vma->vm_mirror = NULL;
73351 + }
73352 +#endif
73353 +
73354 rb_erase(&vma->vm_rb, &mm->mm_rb);
73355 mm->map_count--;
73356 tail_vma = vma;
73357 @@ -1924,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73358 struct vm_area_struct *new;
73359 int err = -ENOMEM;
73360
73361 +#ifdef CONFIG_PAX_SEGMEXEC
73362 + struct vm_area_struct *vma_m, *new_m = NULL;
73363 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73364 +#endif
73365 +
73366 if (is_vm_hugetlb_page(vma) && (addr &
73367 ~(huge_page_mask(hstate_vma(vma)))))
73368 return -EINVAL;
73369
73370 +#ifdef CONFIG_PAX_SEGMEXEC
73371 + vma_m = pax_find_mirror_vma(vma);
73372 +#endif
73373 +
73374 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73375 if (!new)
73376 goto out_err;
73377
73378 +#ifdef CONFIG_PAX_SEGMEXEC
73379 + if (vma_m) {
73380 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73381 + if (!new_m) {
73382 + kmem_cache_free(vm_area_cachep, new);
73383 + goto out_err;
73384 + }
73385 + }
73386 +#endif
73387 +
73388 /* most fields are the same, copy all, and then fixup */
73389 *new = *vma;
73390
73391 @@ -1944,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73392 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73393 }
73394
73395 +#ifdef CONFIG_PAX_SEGMEXEC
73396 + if (vma_m) {
73397 + *new_m = *vma_m;
73398 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73399 + new_m->vm_mirror = new;
73400 + new->vm_mirror = new_m;
73401 +
73402 + if (new_below)
73403 + new_m->vm_end = addr_m;
73404 + else {
73405 + new_m->vm_start = addr_m;
73406 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73407 + }
73408 + }
73409 +#endif
73410 +
73411 pol = mpol_dup(vma_policy(vma));
73412 if (IS_ERR(pol)) {
73413 err = PTR_ERR(pol);
73414 @@ -1969,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73415 else
73416 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73417
73418 +#ifdef CONFIG_PAX_SEGMEXEC
73419 + if (!err && vma_m) {
73420 + if (anon_vma_clone(new_m, vma_m))
73421 + goto out_free_mpol;
73422 +
73423 + mpol_get(pol);
73424 + vma_set_policy(new_m, pol);
73425 +
73426 + if (new_m->vm_file) {
73427 + get_file(new_m->vm_file);
73428 + if (vma_m->vm_flags & VM_EXECUTABLE)
73429 + added_exe_file_vma(mm);
73430 + }
73431 +
73432 + if (new_m->vm_ops && new_m->vm_ops->open)
73433 + new_m->vm_ops->open(new_m);
73434 +
73435 + if (new_below)
73436 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73437 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73438 + else
73439 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73440 +
73441 + if (err) {
73442 + if (new_m->vm_ops && new_m->vm_ops->close)
73443 + new_m->vm_ops->close(new_m);
73444 + if (new_m->vm_file) {
73445 + if (vma_m->vm_flags & VM_EXECUTABLE)
73446 + removed_exe_file_vma(mm);
73447 + fput(new_m->vm_file);
73448 + }
73449 + mpol_put(pol);
73450 + }
73451 + }
73452 +#endif
73453 +
73454 /* Success. */
73455 if (!err)
73456 return 0;
73457 @@ -1981,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73458 removed_exe_file_vma(mm);
73459 fput(new->vm_file);
73460 }
73461 - unlink_anon_vmas(new);
73462 out_free_mpol:
73463 mpol_put(pol);
73464 out_free_vma:
73465 +
73466 +#ifdef CONFIG_PAX_SEGMEXEC
73467 + if (new_m) {
73468 + unlink_anon_vmas(new_m);
73469 + kmem_cache_free(vm_area_cachep, new_m);
73470 + }
73471 +#endif
73472 +
73473 + unlink_anon_vmas(new);
73474 kmem_cache_free(vm_area_cachep, new);
73475 out_err:
73476 return err;
73477 @@ -1997,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73478 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73479 unsigned long addr, int new_below)
73480 {
73481 +
73482 +#ifdef CONFIG_PAX_SEGMEXEC
73483 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73484 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73485 + if (mm->map_count >= sysctl_max_map_count-1)
73486 + return -ENOMEM;
73487 + } else
73488 +#endif
73489 +
73490 if (mm->map_count >= sysctl_max_map_count)
73491 return -ENOMEM;
73492
73493 @@ -2008,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73494 * work. This now handles partial unmappings.
73495 * Jeremy Fitzhardinge <jeremy@goop.org>
73496 */
73497 +#ifdef CONFIG_PAX_SEGMEXEC
73498 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73499 {
73500 + int ret = __do_munmap(mm, start, len);
73501 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73502 + return ret;
73503 +
73504 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73505 +}
73506 +
73507 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73508 +#else
73509 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73510 +#endif
73511 +{
73512 unsigned long end;
73513 struct vm_area_struct *vma, *prev, *last;
73514
73515 + /*
73516 + * mm->mmap_sem is required to protect against another thread
73517 + * changing the mappings in case we sleep.
73518 + */
73519 + verify_mm_writelocked(mm);
73520 +
73521 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73522 return -EINVAL;
73523
73524 @@ -2087,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73525 /* Fix up all other VM information */
73526 remove_vma_list(mm, vma);
73527
73528 + track_exec_limit(mm, start, end, 0UL);
73529 +
73530 return 0;
73531 }
73532
73533 @@ -2099,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73534
73535 profile_munmap(addr);
73536
73537 +#ifdef CONFIG_PAX_SEGMEXEC
73538 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73539 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
73540 + return -EINVAL;
73541 +#endif
73542 +
73543 down_write(&mm->mmap_sem);
73544 ret = do_munmap(mm, addr, len);
73545 up_write(&mm->mmap_sem);
73546 return ret;
73547 }
73548
73549 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73550 -{
73551 -#ifdef CONFIG_DEBUG_VM
73552 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73553 - WARN_ON(1);
73554 - up_read(&mm->mmap_sem);
73555 - }
73556 -#endif
73557 -}
73558 -
73559 /*
73560 * this is really a simplified "do_mmap". it only handles
73561 * anonymous maps. eventually we may be able to do some
73562 @@ -2128,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
73563 struct rb_node ** rb_link, * rb_parent;
73564 pgoff_t pgoff = addr >> PAGE_SHIFT;
73565 int error;
73566 + unsigned long charged;
73567
73568 len = PAGE_ALIGN(len);
73569 if (!len)
73570 @@ -2139,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
73571
73572 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73573
73574 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73575 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73576 + flags &= ~VM_EXEC;
73577 +
73578 +#ifdef CONFIG_PAX_MPROTECT
73579 + if (mm->pax_flags & MF_PAX_MPROTECT)
73580 + flags &= ~VM_MAYEXEC;
73581 +#endif
73582 +
73583 + }
73584 +#endif
73585 +
73586 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73587 if (error & ~PAGE_MASK)
73588 return error;
73589
73590 + charged = len >> PAGE_SHIFT;
73591 +
73592 /*
73593 * mlock MCL_FUTURE?
73594 */
73595 if (mm->def_flags & VM_LOCKED) {
73596 unsigned long locked, lock_limit;
73597 - locked = len >> PAGE_SHIFT;
73598 + locked = charged;
73599 locked += mm->locked_vm;
73600 lock_limit = rlimit(RLIMIT_MEMLOCK);
73601 lock_limit >>= PAGE_SHIFT;
73602 @@ -2165,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
73603 /*
73604 * Clear old maps. this also does some error checking for us
73605 */
73606 - munmap_back:
73607 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73608 if (vma && vma->vm_start < addr + len) {
73609 if (do_munmap(mm, addr, len))
73610 return -ENOMEM;
73611 - goto munmap_back;
73612 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73613 + BUG_ON(vma && vma->vm_start < addr + len);
73614 }
73615
73616 /* Check against address space limits *after* clearing old maps... */
73617 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73618 + if (!may_expand_vm(mm, charged))
73619 return -ENOMEM;
73620
73621 if (mm->map_count > sysctl_max_map_count)
73622 return -ENOMEM;
73623
73624 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
73625 + if (security_vm_enough_memory(charged))
73626 return -ENOMEM;
73627
73628 /* Can we just expand an old private anonymous mapping? */
73629 @@ -2194,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
73630 */
73631 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73632 if (!vma) {
73633 - vm_unacct_memory(len >> PAGE_SHIFT);
73634 + vm_unacct_memory(charged);
73635 return -ENOMEM;
73636 }
73637
73638 @@ -2208,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
73639 vma_link(mm, vma, prev, rb_link, rb_parent);
73640 out:
73641 perf_event_mmap(vma);
73642 - mm->total_vm += len >> PAGE_SHIFT;
73643 + mm->total_vm += charged;
73644 if (flags & VM_LOCKED) {
73645 if (!mlock_vma_pages_range(vma, addr, addr + len))
73646 - mm->locked_vm += (len >> PAGE_SHIFT);
73647 + mm->locked_vm += charged;
73648 }
73649 + track_exec_limit(mm, addr, addr + len, flags);
73650 return addr;
73651 }
73652
73653 @@ -2259,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
73654 * Walk the list again, actually closing and freeing it,
73655 * with preemption enabled, without holding any MM locks.
73656 */
73657 - while (vma)
73658 + while (vma) {
73659 + vma->vm_mirror = NULL;
73660 vma = remove_vma(vma);
73661 + }
73662
73663 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
73664 }
73665 @@ -2274,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73666 struct vm_area_struct * __vma, * prev;
73667 struct rb_node ** rb_link, * rb_parent;
73668
73669 +#ifdef CONFIG_PAX_SEGMEXEC
73670 + struct vm_area_struct *vma_m = NULL;
73671 +#endif
73672 +
73673 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
73674 + return -EPERM;
73675 +
73676 /*
73677 * The vm_pgoff of a purely anonymous vma should be irrelevant
73678 * until its first write fault, when page's anon_vma and index
73679 @@ -2296,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73680 if ((vma->vm_flags & VM_ACCOUNT) &&
73681 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73682 return -ENOMEM;
73683 +
73684 +#ifdef CONFIG_PAX_SEGMEXEC
73685 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73686 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73687 + if (!vma_m)
73688 + return -ENOMEM;
73689 + }
73690 +#endif
73691 +
73692 vma_link(mm, vma, prev, rb_link, rb_parent);
73693 +
73694 +#ifdef CONFIG_PAX_SEGMEXEC
73695 + if (vma_m)
73696 + BUG_ON(pax_mirror_vma(vma_m, vma));
73697 +#endif
73698 +
73699 return 0;
73700 }
73701
73702 @@ -2315,6 +2770,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73703 struct mempolicy *pol;
73704 bool faulted_in_anon_vma = true;
73705
73706 + BUG_ON(vma->vm_mirror);
73707 +
73708 /*
73709 * If anonymous vma has not yet been faulted, update new pgoff
73710 * to match new location, to increase its chance of merging.
73711 @@ -2382,6 +2839,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73712 return NULL;
73713 }
73714
73715 +#ifdef CONFIG_PAX_SEGMEXEC
73716 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73717 +{
73718 + struct vm_area_struct *prev_m;
73719 + struct rb_node **rb_link_m, *rb_parent_m;
73720 + struct mempolicy *pol_m;
73721 +
73722 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73723 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73724 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73725 + *vma_m = *vma;
73726 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73727 + if (anon_vma_clone(vma_m, vma))
73728 + return -ENOMEM;
73729 + pol_m = vma_policy(vma_m);
73730 + mpol_get(pol_m);
73731 + vma_set_policy(vma_m, pol_m);
73732 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73733 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73734 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73735 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73736 + if (vma_m->vm_file)
73737 + get_file(vma_m->vm_file);
73738 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73739 + vma_m->vm_ops->open(vma_m);
73740 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73741 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73742 + vma_m->vm_mirror = vma;
73743 + vma->vm_mirror = vma_m;
73744 + return 0;
73745 +}
73746 +#endif
73747 +
73748 /*
73749 * Return true if the calling process may expand its vm space by the passed
73750 * number of pages
73751 @@ -2393,6 +2883,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73752
73753 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73754
73755 +#ifdef CONFIG_PAX_RANDMMAP
73756 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73757 + cur -= mm->brk_gap;
73758 +#endif
73759 +
73760 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73761 if (cur + npages > lim)
73762 return 0;
73763 return 1;
73764 @@ -2463,6 +2959,22 @@ int install_special_mapping(struct mm_struct *mm,
73765 vma->vm_start = addr;
73766 vma->vm_end = addr + len;
73767
73768 +#ifdef CONFIG_PAX_MPROTECT
73769 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73770 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73771 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73772 + return -EPERM;
73773 + if (!(vm_flags & VM_EXEC))
73774 + vm_flags &= ~VM_MAYEXEC;
73775 +#else
73776 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73777 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73778 +#endif
73779 + else
73780 + vm_flags &= ~VM_MAYWRITE;
73781 + }
73782 +#endif
73783 +
73784 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73785 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73786
73787 diff --git a/mm/mprotect.c b/mm/mprotect.c
73788 index f437d05..e3763f6 100644
73789 --- a/mm/mprotect.c
73790 +++ b/mm/mprotect.c
73791 @@ -23,10 +23,16 @@
73792 #include <linux/mmu_notifier.h>
73793 #include <linux/migrate.h>
73794 #include <linux/perf_event.h>
73795 +
73796 +#ifdef CONFIG_PAX_MPROTECT
73797 +#include <linux/elf.h>
73798 +#endif
73799 +
73800 #include <asm/uaccess.h>
73801 #include <asm/pgtable.h>
73802 #include <asm/cacheflush.h>
73803 #include <asm/tlbflush.h>
73804 +#include <asm/mmu_context.h>
73805
73806 #ifndef pgprot_modify
73807 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73808 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
73809 flush_tlb_range(vma, start, end);
73810 }
73811
73812 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73813 +/* called while holding the mmap semaphor for writing except stack expansion */
73814 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73815 +{
73816 + unsigned long oldlimit, newlimit = 0UL;
73817 +
73818 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73819 + return;
73820 +
73821 + spin_lock(&mm->page_table_lock);
73822 + oldlimit = mm->context.user_cs_limit;
73823 + if ((prot & VM_EXEC) && oldlimit < end)
73824 + /* USER_CS limit moved up */
73825 + newlimit = end;
73826 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73827 + /* USER_CS limit moved down */
73828 + newlimit = start;
73829 +
73830 + if (newlimit) {
73831 + mm->context.user_cs_limit = newlimit;
73832 +
73833 +#ifdef CONFIG_SMP
73834 + wmb();
73835 + cpus_clear(mm->context.cpu_user_cs_mask);
73836 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73837 +#endif
73838 +
73839 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73840 + }
73841 + spin_unlock(&mm->page_table_lock);
73842 + if (newlimit == end) {
73843 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73844 +
73845 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73846 + if (is_vm_hugetlb_page(vma))
73847 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73848 + else
73849 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73850 + }
73851 +}
73852 +#endif
73853 +
73854 int
73855 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73856 unsigned long start, unsigned long end, unsigned long newflags)
73857 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73858 int error;
73859 int dirty_accountable = 0;
73860
73861 +#ifdef CONFIG_PAX_SEGMEXEC
73862 + struct vm_area_struct *vma_m = NULL;
73863 + unsigned long start_m, end_m;
73864 +
73865 + start_m = start + SEGMEXEC_TASK_SIZE;
73866 + end_m = end + SEGMEXEC_TASK_SIZE;
73867 +#endif
73868 +
73869 if (newflags == oldflags) {
73870 *pprev = vma;
73871 return 0;
73872 }
73873
73874 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73875 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73876 +
73877 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73878 + return -ENOMEM;
73879 +
73880 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73881 + return -ENOMEM;
73882 + }
73883 +
73884 /*
73885 * If we make a private mapping writable we increase our commit;
73886 * but (without finer accounting) cannot reduce our commit if we
73887 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73888 }
73889 }
73890
73891 +#ifdef CONFIG_PAX_SEGMEXEC
73892 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73893 + if (start != vma->vm_start) {
73894 + error = split_vma(mm, vma, start, 1);
73895 + if (error)
73896 + goto fail;
73897 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73898 + *pprev = (*pprev)->vm_next;
73899 + }
73900 +
73901 + if (end != vma->vm_end) {
73902 + error = split_vma(mm, vma, end, 0);
73903 + if (error)
73904 + goto fail;
73905 + }
73906 +
73907 + if (pax_find_mirror_vma(vma)) {
73908 + error = __do_munmap(mm, start_m, end_m - start_m);
73909 + if (error)
73910 + goto fail;
73911 + } else {
73912 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73913 + if (!vma_m) {
73914 + error = -ENOMEM;
73915 + goto fail;
73916 + }
73917 + vma->vm_flags = newflags;
73918 + error = pax_mirror_vma(vma_m, vma);
73919 + if (error) {
73920 + vma->vm_flags = oldflags;
73921 + goto fail;
73922 + }
73923 + }
73924 + }
73925 +#endif
73926 +
73927 /*
73928 * First try to merge with previous and/or next vma.
73929 */
73930 @@ -204,9 +306,21 @@ success:
73931 * vm_flags and vm_page_prot are protected by the mmap_sem
73932 * held in write mode.
73933 */
73934 +
73935 +#ifdef CONFIG_PAX_SEGMEXEC
73936 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73937 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73938 +#endif
73939 +
73940 vma->vm_flags = newflags;
73941 +
73942 +#ifdef CONFIG_PAX_MPROTECT
73943 + if (mm->binfmt && mm->binfmt->handle_mprotect)
73944 + mm->binfmt->handle_mprotect(vma, newflags);
73945 +#endif
73946 +
73947 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73948 - vm_get_page_prot(newflags));
73949 + vm_get_page_prot(vma->vm_flags));
73950
73951 if (vma_wants_writenotify(vma)) {
73952 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73953 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73954 end = start + len;
73955 if (end <= start)
73956 return -ENOMEM;
73957 +
73958 +#ifdef CONFIG_PAX_SEGMEXEC
73959 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73960 + if (end > SEGMEXEC_TASK_SIZE)
73961 + return -EINVAL;
73962 + } else
73963 +#endif
73964 +
73965 + if (end > TASK_SIZE)
73966 + return -EINVAL;
73967 +
73968 if (!arch_validate_prot(prot))
73969 return -EINVAL;
73970
73971 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73972 /*
73973 * Does the application expect PROT_READ to imply PROT_EXEC:
73974 */
73975 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73976 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73977 prot |= PROT_EXEC;
73978
73979 vm_flags = calc_vm_prot_bits(prot);
73980 @@ -288,6 +413,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73981 if (start > vma->vm_start)
73982 prev = vma;
73983
73984 +#ifdef CONFIG_PAX_MPROTECT
73985 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73986 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
73987 +#endif
73988 +
73989 for (nstart = start ; ; ) {
73990 unsigned long newflags;
73991
73992 @@ -297,6 +427,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73993
73994 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73995 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73996 + if (prot & (PROT_WRITE | PROT_EXEC))
73997 + gr_log_rwxmprotect(vma->vm_file);
73998 +
73999 + error = -EACCES;
74000 + goto out;
74001 + }
74002 +
74003 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74004 error = -EACCES;
74005 goto out;
74006 }
74007 @@ -311,6 +449,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74008 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74009 if (error)
74010 goto out;
74011 +
74012 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74013 +
74014 nstart = tmp;
74015
74016 if (nstart < prev->vm_end)
74017 diff --git a/mm/mremap.c b/mm/mremap.c
74018 index 87bb839..c3bfadb 100644
74019 --- a/mm/mremap.c
74020 +++ b/mm/mremap.c
74021 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74022 continue;
74023 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74024 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74025 +
74026 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74027 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74028 + pte = pte_exprotect(pte);
74029 +#endif
74030 +
74031 set_pte_at(mm, new_addr, new_pte, pte);
74032 }
74033
74034 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74035 if (is_vm_hugetlb_page(vma))
74036 goto Einval;
74037
74038 +#ifdef CONFIG_PAX_SEGMEXEC
74039 + if (pax_find_mirror_vma(vma))
74040 + goto Einval;
74041 +#endif
74042 +
74043 /* We can't remap across vm area boundaries */
74044 if (old_len > vma->vm_end - addr)
74045 goto Efault;
74046 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
74047 unsigned long ret = -EINVAL;
74048 unsigned long charged = 0;
74049 unsigned long map_flags;
74050 + unsigned long pax_task_size = TASK_SIZE;
74051
74052 if (new_addr & ~PAGE_MASK)
74053 goto out;
74054
74055 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74056 +#ifdef CONFIG_PAX_SEGMEXEC
74057 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74058 + pax_task_size = SEGMEXEC_TASK_SIZE;
74059 +#endif
74060 +
74061 + pax_task_size -= PAGE_SIZE;
74062 +
74063 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74064 goto out;
74065
74066 /* Check if the location we're moving into overlaps the
74067 * old location at all, and fail if it does.
74068 */
74069 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74070 - goto out;
74071 -
74072 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74073 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74074 goto out;
74075
74076 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74077 @@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
74078 struct vm_area_struct *vma;
74079 unsigned long ret = -EINVAL;
74080 unsigned long charged = 0;
74081 + unsigned long pax_task_size = TASK_SIZE;
74082
74083 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
74084 goto out;
74085 @@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
74086 if (!new_len)
74087 goto out;
74088
74089 +#ifdef CONFIG_PAX_SEGMEXEC
74090 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74091 + pax_task_size = SEGMEXEC_TASK_SIZE;
74092 +#endif
74093 +
74094 + pax_task_size -= PAGE_SIZE;
74095 +
74096 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74097 + old_len > pax_task_size || addr > pax_task_size-old_len)
74098 + goto out;
74099 +
74100 if (flags & MREMAP_FIXED) {
74101 if (flags & MREMAP_MAYMOVE)
74102 ret = mremap_to(addr, old_len, new_addr, new_len);
74103 @@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
74104 addr + new_len);
74105 }
74106 ret = addr;
74107 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74108 goto out;
74109 }
74110 }
74111 @@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
74112 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
74113 if (ret)
74114 goto out;
74115 +
74116 + map_flags = vma->vm_flags;
74117 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74118 + if (!(ret & ~PAGE_MASK)) {
74119 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74120 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74121 + }
74122 }
74123 out:
74124 if (ret & ~PAGE_MASK)
74125 diff --git a/mm/nommu.c b/mm/nommu.c
74126 index f59e170..34e2a2b 100644
74127 --- a/mm/nommu.c
74128 +++ b/mm/nommu.c
74129 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74130 int sysctl_overcommit_ratio = 50; /* default is 50% */
74131 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74132 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74133 -int heap_stack_gap = 0;
74134
74135 atomic_long_t mmap_pages_allocated;
74136
74137 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74138 EXPORT_SYMBOL(find_vma);
74139
74140 /*
74141 - * find a VMA
74142 - * - we don't extend stack VMAs under NOMMU conditions
74143 - */
74144 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74145 -{
74146 - return find_vma(mm, addr);
74147 -}
74148 -
74149 -/*
74150 * expand a stack to a given address
74151 * - not supported under NOMMU conditions
74152 */
74153 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74154
74155 /* most fields are the same, copy all, and then fixup */
74156 *new = *vma;
74157 + INIT_LIST_HEAD(&new->anon_vma_chain);
74158 *region = *vma->vm_region;
74159 new->vm_region = region;
74160
74161 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74162 index a13ded1..b949d15 100644
74163 --- a/mm/page_alloc.c
74164 +++ b/mm/page_alloc.c
74165 @@ -335,7 +335,7 @@ out:
74166 * This usage means that zero-order pages may not be compound.
74167 */
74168
74169 -static void free_compound_page(struct page *page)
74170 +void free_compound_page(struct page *page)
74171 {
74172 __free_pages_ok(page, compound_order(page));
74173 }
74174 @@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74175 int i;
74176 int bad = 0;
74177
74178 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74179 + unsigned long index = 1UL << order;
74180 +#endif
74181 +
74182 trace_mm_page_free(page, order);
74183 kmemcheck_free_shadow(page, order);
74184
74185 @@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74186 debug_check_no_obj_freed(page_address(page),
74187 PAGE_SIZE << order);
74188 }
74189 +
74190 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74191 + for (; index; --index)
74192 + sanitize_highpage(page + index - 1);
74193 +#endif
74194 +
74195 arch_free_page(page, order);
74196 kernel_map_pages(page, 1 << order, 0);
74197
74198 @@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74199 arch_alloc_page(page, order);
74200 kernel_map_pages(page, 1 << order, 1);
74201
74202 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74203 if (gfp_flags & __GFP_ZERO)
74204 prep_zero_page(page, order, gfp_flags);
74205 +#endif
74206
74207 if (order && (gfp_flags & __GFP_COMP))
74208 prep_compound_page(page, order);
74209 @@ -3468,7 +3480,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74210 unsigned long pfn;
74211
74212 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74213 +#ifdef CONFIG_X86_32
74214 + /* boot failures in VMware 8 on 32bit vanilla since
74215 + this change */
74216 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74217 +#else
74218 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74219 +#endif
74220 return 1;
74221 }
74222 return 0;
74223 diff --git a/mm/percpu.c b/mm/percpu.c
74224 index f47af91..7eeef99 100644
74225 --- a/mm/percpu.c
74226 +++ b/mm/percpu.c
74227 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74228 static unsigned int pcpu_high_unit_cpu __read_mostly;
74229
74230 /* the address of the first chunk which starts with the kernel static area */
74231 -void *pcpu_base_addr __read_mostly;
74232 +void *pcpu_base_addr __read_only;
74233 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74234
74235 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74236 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74237 index c20ff48..137702a 100644
74238 --- a/mm/process_vm_access.c
74239 +++ b/mm/process_vm_access.c
74240 @@ -13,6 +13,7 @@
74241 #include <linux/uio.h>
74242 #include <linux/sched.h>
74243 #include <linux/highmem.h>
74244 +#include <linux/security.h>
74245 #include <linux/ptrace.h>
74246 #include <linux/slab.h>
74247 #include <linux/syscalls.h>
74248 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74249 size_t iov_l_curr_offset = 0;
74250 ssize_t iov_len;
74251
74252 + return -ENOSYS; // PaX: until properly audited
74253 +
74254 /*
74255 * Work out how many pages of struct pages we're going to need
74256 * when eventually calling get_user_pages
74257 */
74258 for (i = 0; i < riovcnt; i++) {
74259 iov_len = rvec[i].iov_len;
74260 - if (iov_len > 0) {
74261 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74262 - + iov_len)
74263 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74264 - / PAGE_SIZE + 1;
74265 - nr_pages = max(nr_pages, nr_pages_iov);
74266 - }
74267 + if (iov_len <= 0)
74268 + continue;
74269 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74270 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74271 + nr_pages = max(nr_pages, nr_pages_iov);
74272 }
74273
74274 if (nr_pages == 0)
74275 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74276 goto free_proc_pages;
74277 }
74278
74279 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74280 + rc = -EPERM;
74281 + goto put_task_struct;
74282 + }
74283 +
74284 mm = mm_access(task, PTRACE_MODE_ATTACH);
74285 if (!mm || IS_ERR(mm)) {
74286 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74287 diff --git a/mm/rmap.c b/mm/rmap.c
74288 index c8454e0..b04f3a2 100644
74289 --- a/mm/rmap.c
74290 +++ b/mm/rmap.c
74291 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74292 struct anon_vma *anon_vma = vma->anon_vma;
74293 struct anon_vma_chain *avc;
74294
74295 +#ifdef CONFIG_PAX_SEGMEXEC
74296 + struct anon_vma_chain *avc_m = NULL;
74297 +#endif
74298 +
74299 might_sleep();
74300 if (unlikely(!anon_vma)) {
74301 struct mm_struct *mm = vma->vm_mm;
74302 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74303 if (!avc)
74304 goto out_enomem;
74305
74306 +#ifdef CONFIG_PAX_SEGMEXEC
74307 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74308 + if (!avc_m)
74309 + goto out_enomem_free_avc;
74310 +#endif
74311 +
74312 anon_vma = find_mergeable_anon_vma(vma);
74313 allocated = NULL;
74314 if (!anon_vma) {
74315 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74316 /* page_table_lock to protect against threads */
74317 spin_lock(&mm->page_table_lock);
74318 if (likely(!vma->anon_vma)) {
74319 +
74320 +#ifdef CONFIG_PAX_SEGMEXEC
74321 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74322 +
74323 + if (vma_m) {
74324 + BUG_ON(vma_m->anon_vma);
74325 + vma_m->anon_vma = anon_vma;
74326 + avc_m->anon_vma = anon_vma;
74327 + avc_m->vma = vma;
74328 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
74329 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
74330 + avc_m = NULL;
74331 + }
74332 +#endif
74333 +
74334 vma->anon_vma = anon_vma;
74335 avc->anon_vma = anon_vma;
74336 avc->vma = vma;
74337 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74338
74339 if (unlikely(allocated))
74340 put_anon_vma(allocated);
74341 +
74342 +#ifdef CONFIG_PAX_SEGMEXEC
74343 + if (unlikely(avc_m))
74344 + anon_vma_chain_free(avc_m);
74345 +#endif
74346 +
74347 if (unlikely(avc))
74348 anon_vma_chain_free(avc);
74349 }
74350 return 0;
74351
74352 out_enomem_free_avc:
74353 +
74354 +#ifdef CONFIG_PAX_SEGMEXEC
74355 + if (avc_m)
74356 + anon_vma_chain_free(avc_m);
74357 +#endif
74358 +
74359 anon_vma_chain_free(avc);
74360 out_enomem:
74361 return -ENOMEM;
74362 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
74363 * Attach the anon_vmas from src to dst.
74364 * Returns 0 on success, -ENOMEM on failure.
74365 */
74366 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74367 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74368 {
74369 struct anon_vma_chain *avc, *pavc;
74370 struct anon_vma *root = NULL;
74371 @@ -321,7 +358,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74372 * the corresponding VMA in the parent process is attached to.
74373 * Returns 0 on success, non-zero on failure.
74374 */
74375 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74376 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74377 {
74378 struct anon_vma_chain *avc;
74379 struct anon_vma *anon_vma;
74380 diff --git a/mm/shmem.c b/mm/shmem.c
74381 index 269d049..a9d2b50 100644
74382 --- a/mm/shmem.c
74383 +++ b/mm/shmem.c
74384 @@ -31,7 +31,7 @@
74385 #include <linux/export.h>
74386 #include <linux/swap.h>
74387
74388 -static struct vfsmount *shm_mnt;
74389 +struct vfsmount *shm_mnt;
74390
74391 #ifdef CONFIG_SHMEM
74392 /*
74393 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
74394 #define BOGO_DIRENT_SIZE 20
74395
74396 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74397 -#define SHORT_SYMLINK_LEN 128
74398 +#define SHORT_SYMLINK_LEN 64
74399
74400 struct shmem_xattr {
74401 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74402 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74403 int err = -ENOMEM;
74404
74405 /* Round up to L1_CACHE_BYTES to resist false sharing */
74406 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74407 - L1_CACHE_BYTES), GFP_KERNEL);
74408 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74409 if (!sbinfo)
74410 return -ENOMEM;
74411
74412 diff --git a/mm/slab.c b/mm/slab.c
74413 index f0bd785..348b96a 100644
74414 --- a/mm/slab.c
74415 +++ b/mm/slab.c
74416 @@ -153,7 +153,7 @@
74417
74418 /* Legal flag mask for kmem_cache_create(). */
74419 #if DEBUG
74420 -# define CREATE_MASK (SLAB_RED_ZONE | \
74421 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74422 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74423 SLAB_CACHE_DMA | \
74424 SLAB_STORE_USER | \
74425 @@ -161,7 +161,7 @@
74426 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74427 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74428 #else
74429 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74430 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74431 SLAB_CACHE_DMA | \
74432 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74433 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74434 @@ -290,7 +290,7 @@ struct kmem_list3 {
74435 * Need this for bootstrapping a per node allocator.
74436 */
74437 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74438 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74439 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74440 #define CACHE_CACHE 0
74441 #define SIZE_AC MAX_NUMNODES
74442 #define SIZE_L3 (2 * MAX_NUMNODES)
74443 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74444 if ((x)->max_freeable < i) \
74445 (x)->max_freeable = i; \
74446 } while (0)
74447 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74448 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74449 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74450 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74451 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74452 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74453 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74454 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74455 #else
74456 #define STATS_INC_ACTIVE(x) do { } while (0)
74457 #define STATS_DEC_ACTIVE(x) do { } while (0)
74458 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74459 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74460 */
74461 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74462 - const struct slab *slab, void *obj)
74463 + const struct slab *slab, const void *obj)
74464 {
74465 u32 offset = (obj - slab->s_mem);
74466 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74467 @@ -568,7 +568,7 @@ struct cache_names {
74468 static struct cache_names __initdata cache_names[] = {
74469 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74470 #include <linux/kmalloc_sizes.h>
74471 - {NULL,}
74472 + {NULL}
74473 #undef CACHE
74474 };
74475
74476 @@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
74477 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74478 sizes[INDEX_AC].cs_size,
74479 ARCH_KMALLOC_MINALIGN,
74480 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74481 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74482 NULL);
74483
74484 if (INDEX_AC != INDEX_L3) {
74485 @@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
74486 kmem_cache_create(names[INDEX_L3].name,
74487 sizes[INDEX_L3].cs_size,
74488 ARCH_KMALLOC_MINALIGN,
74489 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74490 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74491 NULL);
74492 }
74493
74494 @@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
74495 sizes->cs_cachep = kmem_cache_create(names->name,
74496 sizes->cs_size,
74497 ARCH_KMALLOC_MINALIGN,
74498 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74499 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74500 NULL);
74501 }
74502 #ifdef CONFIG_ZONE_DMA
74503 @@ -4339,10 +4339,10 @@ static int s_show(struct seq_file *m, void *p)
74504 }
74505 /* cpu stats */
74506 {
74507 - unsigned long allochit = atomic_read(&cachep->allochit);
74508 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74509 - unsigned long freehit = atomic_read(&cachep->freehit);
74510 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74511 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74512 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74513 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74514 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74515
74516 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74517 allochit, allocmiss, freehit, freemiss);
74518 @@ -4601,13 +4601,62 @@ static int __init slab_proc_init(void)
74519 {
74520 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74521 #ifdef CONFIG_DEBUG_SLAB_LEAK
74522 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74523 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74524 #endif
74525 return 0;
74526 }
74527 module_init(slab_proc_init);
74528 #endif
74529
74530 +void check_object_size(const void *ptr, unsigned long n, bool to)
74531 +{
74532 +
74533 +#ifdef CONFIG_PAX_USERCOPY
74534 + struct page *page;
74535 + struct kmem_cache *cachep = NULL;
74536 + struct slab *slabp;
74537 + unsigned int objnr;
74538 + unsigned long offset;
74539 + const char *type;
74540 +
74541 + if (!n)
74542 + return;
74543 +
74544 + type = "<null>";
74545 + if (ZERO_OR_NULL_PTR(ptr))
74546 + goto report;
74547 +
74548 + if (!virt_addr_valid(ptr))
74549 + return;
74550 +
74551 + page = virt_to_head_page(ptr);
74552 +
74553 + type = "<process stack>";
74554 + if (!PageSlab(page)) {
74555 + if (object_is_on_stack(ptr, n) == -1)
74556 + goto report;
74557 + return;
74558 + }
74559 +
74560 + cachep = page_get_cache(page);
74561 + type = cachep->name;
74562 + if (!(cachep->flags & SLAB_USERCOPY))
74563 + goto report;
74564 +
74565 + slabp = page_get_slab(page);
74566 + objnr = obj_to_index(cachep, slabp, ptr);
74567 + BUG_ON(objnr >= cachep->num);
74568 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74569 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74570 + return;
74571 +
74572 +report:
74573 + pax_report_usercopy(ptr, n, to, type);
74574 +#endif
74575 +
74576 +}
74577 +EXPORT_SYMBOL(check_object_size);
74578 +
74579 /**
74580 * ksize - get the actual amount of memory allocated for a given object
74581 * @objp: Pointer to the object
74582 diff --git a/mm/slob.c b/mm/slob.c
74583 index 8105be4..e045f96 100644
74584 --- a/mm/slob.c
74585 +++ b/mm/slob.c
74586 @@ -29,7 +29,7 @@
74587 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74588 * alloc_pages() directly, allocating compound pages so the page order
74589 * does not have to be separately tracked, and also stores the exact
74590 - * allocation size in page->private so that it can be used to accurately
74591 + * allocation size in slob_page->size so that it can be used to accurately
74592 * provide ksize(). These objects are detected in kfree() because slob_page()
74593 * is false for them.
74594 *
74595 @@ -58,6 +58,7 @@
74596 */
74597
74598 #include <linux/kernel.h>
74599 +#include <linux/sched.h>
74600 #include <linux/slab.h>
74601 #include <linux/mm.h>
74602 #include <linux/swap.h> /* struct reclaim_state */
74603 @@ -102,7 +103,8 @@ struct slob_page {
74604 unsigned long flags; /* mandatory */
74605 atomic_t _count; /* mandatory */
74606 slobidx_t units; /* free units left in page */
74607 - unsigned long pad[2];
74608 + unsigned long pad[1];
74609 + unsigned long size; /* size when >=PAGE_SIZE */
74610 slob_t *free; /* first free slob_t in page */
74611 struct list_head list; /* linked list of free pages */
74612 };
74613 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74614 */
74615 static inline int is_slob_page(struct slob_page *sp)
74616 {
74617 - return PageSlab((struct page *)sp);
74618 + return PageSlab((struct page *)sp) && !sp->size;
74619 }
74620
74621 static inline void set_slob_page(struct slob_page *sp)
74622 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
74623
74624 static inline struct slob_page *slob_page(const void *addr)
74625 {
74626 - return (struct slob_page *)virt_to_page(addr);
74627 + return (struct slob_page *)virt_to_head_page(addr);
74628 }
74629
74630 /*
74631 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74632 /*
74633 * Return the size of a slob block.
74634 */
74635 -static slobidx_t slob_units(slob_t *s)
74636 +static slobidx_t slob_units(const slob_t *s)
74637 {
74638 if (s->units > 0)
74639 return s->units;
74640 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74641 /*
74642 * Return the next free slob block pointer after this one.
74643 */
74644 -static slob_t *slob_next(slob_t *s)
74645 +static slob_t *slob_next(const slob_t *s)
74646 {
74647 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74648 slobidx_t next;
74649 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74650 /*
74651 * Returns true if s is the last free block in its page.
74652 */
74653 -static int slob_last(slob_t *s)
74654 +static int slob_last(const slob_t *s)
74655 {
74656 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74657 }
74658 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74659 if (!page)
74660 return NULL;
74661
74662 + set_slob_page(page);
74663 return page_address(page);
74664 }
74665
74666 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74667 if (!b)
74668 return NULL;
74669 sp = slob_page(b);
74670 - set_slob_page(sp);
74671
74672 spin_lock_irqsave(&slob_lock, flags);
74673 sp->units = SLOB_UNITS(PAGE_SIZE);
74674 sp->free = b;
74675 + sp->size = 0;
74676 INIT_LIST_HEAD(&sp->list);
74677 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74678 set_slob_page_free(sp, slob_list);
74679 @@ -476,10 +479,9 @@ out:
74680 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74681 */
74682
74683 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74684 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74685 {
74686 - unsigned int *m;
74687 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74688 + slob_t *m;
74689 void *ret;
74690
74691 gfp &= gfp_allowed_mask;
74692 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74693
74694 if (!m)
74695 return NULL;
74696 - *m = size;
74697 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74698 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74699 + m[0].units = size;
74700 + m[1].units = align;
74701 ret = (void *)m + align;
74702
74703 trace_kmalloc_node(_RET_IP_, ret,
74704 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74705 gfp |= __GFP_COMP;
74706 ret = slob_new_pages(gfp, order, node);
74707 if (ret) {
74708 - struct page *page;
74709 - page = virt_to_page(ret);
74710 - page->private = size;
74711 + struct slob_page *sp;
74712 + sp = slob_page(ret);
74713 + sp->size = size;
74714 }
74715
74716 trace_kmalloc_node(_RET_IP_, ret,
74717 size, PAGE_SIZE << order, gfp, node);
74718 }
74719
74720 - kmemleak_alloc(ret, size, 1, gfp);
74721 + return ret;
74722 +}
74723 +
74724 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74725 +{
74726 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74727 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74728 +
74729 + if (!ZERO_OR_NULL_PTR(ret))
74730 + kmemleak_alloc(ret, size, 1, gfp);
74731 return ret;
74732 }
74733 EXPORT_SYMBOL(__kmalloc_node);
74734 @@ -533,13 +547,92 @@ void kfree(const void *block)
74735 sp = slob_page(block);
74736 if (is_slob_page(sp)) {
74737 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74738 - unsigned int *m = (unsigned int *)(block - align);
74739 - slob_free(m, *m + align);
74740 - } else
74741 + slob_t *m = (slob_t *)(block - align);
74742 + slob_free(m, m[0].units + align);
74743 + } else {
74744 + clear_slob_page(sp);
74745 + free_slob_page(sp);
74746 + sp->size = 0;
74747 put_page(&sp->page);
74748 + }
74749 }
74750 EXPORT_SYMBOL(kfree);
74751
74752 +void check_object_size(const void *ptr, unsigned long n, bool to)
74753 +{
74754 +
74755 +#ifdef CONFIG_PAX_USERCOPY
74756 + struct slob_page *sp;
74757 + const slob_t *free;
74758 + const void *base;
74759 + unsigned long flags;
74760 + const char *type;
74761 +
74762 + if (!n)
74763 + return;
74764 +
74765 + type = "<null>";
74766 + if (ZERO_OR_NULL_PTR(ptr))
74767 + goto report;
74768 +
74769 + if (!virt_addr_valid(ptr))
74770 + return;
74771 +
74772 + type = "<process stack>";
74773 + sp = slob_page(ptr);
74774 + if (!PageSlab((struct page *)sp)) {
74775 + if (object_is_on_stack(ptr, n) == -1)
74776 + goto report;
74777 + return;
74778 + }
74779 +
74780 + type = "<slob>";
74781 + if (sp->size) {
74782 + base = page_address(&sp->page);
74783 + if (base <= ptr && n <= sp->size - (ptr - base))
74784 + return;
74785 + goto report;
74786 + }
74787 +
74788 + /* some tricky double walking to find the chunk */
74789 + spin_lock_irqsave(&slob_lock, flags);
74790 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74791 + free = sp->free;
74792 +
74793 + while (!slob_last(free) && (void *)free <= ptr) {
74794 + base = free + slob_units(free);
74795 + free = slob_next(free);
74796 + }
74797 +
74798 + while (base < (void *)free) {
74799 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74800 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74801 + int offset;
74802 +
74803 + if (ptr < base + align)
74804 + break;
74805 +
74806 + offset = ptr - base - align;
74807 + if (offset >= m) {
74808 + base += size;
74809 + continue;
74810 + }
74811 +
74812 + if (n > m - offset)
74813 + break;
74814 +
74815 + spin_unlock_irqrestore(&slob_lock, flags);
74816 + return;
74817 + }
74818 +
74819 + spin_unlock_irqrestore(&slob_lock, flags);
74820 +report:
74821 + pax_report_usercopy(ptr, n, to, type);
74822 +#endif
74823 +
74824 +}
74825 +EXPORT_SYMBOL(check_object_size);
74826 +
74827 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74828 size_t ksize(const void *block)
74829 {
74830 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
74831 sp = slob_page(block);
74832 if (is_slob_page(sp)) {
74833 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74834 - unsigned int *m = (unsigned int *)(block - align);
74835 - return SLOB_UNITS(*m) * SLOB_UNIT;
74836 + slob_t *m = (slob_t *)(block - align);
74837 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74838 } else
74839 - return sp->page.private;
74840 + return sp->size;
74841 }
74842 EXPORT_SYMBOL(ksize);
74843
74844 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74845 {
74846 struct kmem_cache *c;
74847
74848 +#ifdef CONFIG_PAX_USERCOPY
74849 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74850 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74851 +#else
74852 c = slob_alloc(sizeof(struct kmem_cache),
74853 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74854 +#endif
74855
74856 if (c) {
74857 c->name = name;
74858 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74859
74860 lockdep_trace_alloc(flags);
74861
74862 +#ifdef CONFIG_PAX_USERCOPY
74863 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74864 +#else
74865 if (c->size < PAGE_SIZE) {
74866 b = slob_alloc(c->size, flags, c->align, node);
74867 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74868 SLOB_UNITS(c->size) * SLOB_UNIT,
74869 flags, node);
74870 } else {
74871 + struct slob_page *sp;
74872 +
74873 b = slob_new_pages(flags, get_order(c->size), node);
74874 + sp = slob_page(b);
74875 + sp->size = c->size;
74876 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74877 PAGE_SIZE << get_order(c->size),
74878 flags, node);
74879 }
74880 +#endif
74881
74882 if (c->ctor)
74883 c->ctor(b);
74884 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74885
74886 static void __kmem_cache_free(void *b, int size)
74887 {
74888 - if (size < PAGE_SIZE)
74889 + struct slob_page *sp = slob_page(b);
74890 +
74891 + if (is_slob_page(sp))
74892 slob_free(b, size);
74893 - else
74894 + else {
74895 + clear_slob_page(sp);
74896 + free_slob_page(sp);
74897 + sp->size = 0;
74898 slob_free_pages(b, get_order(size));
74899 + }
74900 }
74901
74902 static void kmem_rcu_free(struct rcu_head *head)
74903 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74904
74905 void kmem_cache_free(struct kmem_cache *c, void *b)
74906 {
74907 + int size = c->size;
74908 +
74909 +#ifdef CONFIG_PAX_USERCOPY
74910 + if (size + c->align < PAGE_SIZE) {
74911 + size += c->align;
74912 + b -= c->align;
74913 + }
74914 +#endif
74915 +
74916 kmemleak_free_recursive(b, c->flags);
74917 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74918 struct slob_rcu *slob_rcu;
74919 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74920 - slob_rcu->size = c->size;
74921 + slob_rcu = b + (size - sizeof(struct slob_rcu));
74922 + slob_rcu->size = size;
74923 call_rcu(&slob_rcu->head, kmem_rcu_free);
74924 } else {
74925 - __kmem_cache_free(b, c->size);
74926 + __kmem_cache_free(b, size);
74927 }
74928
74929 +#ifdef CONFIG_PAX_USERCOPY
74930 + trace_kfree(_RET_IP_, b);
74931 +#else
74932 trace_kmem_cache_free(_RET_IP_, b);
74933 +#endif
74934 +
74935 }
74936 EXPORT_SYMBOL(kmem_cache_free);
74937
74938 diff --git a/mm/slub.c b/mm/slub.c
74939 index 0342a5d..8180ae9 100644
74940 --- a/mm/slub.c
74941 +++ b/mm/slub.c
74942 @@ -208,7 +208,7 @@ struct track {
74943
74944 enum track_item { TRACK_ALLOC, TRACK_FREE };
74945
74946 -#ifdef CONFIG_SYSFS
74947 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74948 static int sysfs_slab_add(struct kmem_cache *);
74949 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74950 static void sysfs_slab_remove(struct kmem_cache *);
74951 @@ -532,7 +532,7 @@ static void print_track(const char *s, struct track *t)
74952 if (!t->addr)
74953 return;
74954
74955 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74956 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74957 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74958 #ifdef CONFIG_STACKTRACE
74959 {
74960 @@ -2571,6 +2571,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74961
74962 page = virt_to_head_page(x);
74963
74964 + BUG_ON(!PageSlab(page));
74965 +
74966 slab_free(s, page, x, _RET_IP_);
74967
74968 trace_kmem_cache_free(_RET_IP_, x);
74969 @@ -2604,7 +2606,7 @@ static int slub_min_objects;
74970 * Merge control. If this is set then no merging of slab caches will occur.
74971 * (Could be removed. This was introduced to pacify the merge skeptics.)
74972 */
74973 -static int slub_nomerge;
74974 +static int slub_nomerge = 1;
74975
74976 /*
74977 * Calculate the order of allocation given an slab object size.
74978 @@ -3057,7 +3059,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74979 else
74980 s->cpu_partial = 30;
74981
74982 - s->refcount = 1;
74983 + atomic_set(&s->refcount, 1);
74984 #ifdef CONFIG_NUMA
74985 s->remote_node_defrag_ratio = 1000;
74986 #endif
74987 @@ -3161,8 +3163,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74988 void kmem_cache_destroy(struct kmem_cache *s)
74989 {
74990 down_write(&slub_lock);
74991 - s->refcount--;
74992 - if (!s->refcount) {
74993 + if (atomic_dec_and_test(&s->refcount)) {
74994 list_del(&s->list);
74995 up_write(&slub_lock);
74996 if (kmem_cache_close(s)) {
74997 @@ -3373,6 +3374,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74998 EXPORT_SYMBOL(__kmalloc_node);
74999 #endif
75000
75001 +void check_object_size(const void *ptr, unsigned long n, bool to)
75002 +{
75003 +
75004 +#ifdef CONFIG_PAX_USERCOPY
75005 + struct page *page;
75006 + struct kmem_cache *s = NULL;
75007 + unsigned long offset;
75008 + const char *type;
75009 +
75010 + if (!n)
75011 + return;
75012 +
75013 + type = "<null>";
75014 + if (ZERO_OR_NULL_PTR(ptr))
75015 + goto report;
75016 +
75017 + if (!virt_addr_valid(ptr))
75018 + return;
75019 +
75020 + page = virt_to_head_page(ptr);
75021 +
75022 + type = "<process stack>";
75023 + if (!PageSlab(page)) {
75024 + if (object_is_on_stack(ptr, n) == -1)
75025 + goto report;
75026 + return;
75027 + }
75028 +
75029 + s = page->slab;
75030 + type = s->name;
75031 + if (!(s->flags & SLAB_USERCOPY))
75032 + goto report;
75033 +
75034 + offset = (ptr - page_address(page)) % s->size;
75035 + if (offset <= s->objsize && n <= s->objsize - offset)
75036 + return;
75037 +
75038 +report:
75039 + pax_report_usercopy(ptr, n, to, type);
75040 +#endif
75041 +
75042 +}
75043 +EXPORT_SYMBOL(check_object_size);
75044 +
75045 size_t ksize(const void *object)
75046 {
75047 struct page *page;
75048 @@ -3647,7 +3692,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75049 int node;
75050
75051 list_add(&s->list, &slab_caches);
75052 - s->refcount = -1;
75053 + atomic_set(&s->refcount, -1);
75054
75055 for_each_node_state(node, N_NORMAL_MEMORY) {
75056 struct kmem_cache_node *n = get_node(s, node);
75057 @@ -3767,17 +3812,17 @@ void __init kmem_cache_init(void)
75058
75059 /* Caches that are not of the two-to-the-power-of size */
75060 if (KMALLOC_MIN_SIZE <= 32) {
75061 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75062 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75063 caches++;
75064 }
75065
75066 if (KMALLOC_MIN_SIZE <= 64) {
75067 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75068 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75069 caches++;
75070 }
75071
75072 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75073 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75074 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75075 caches++;
75076 }
75077
75078 @@ -3845,7 +3890,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75079 /*
75080 * We may have set a slab to be unmergeable during bootstrap.
75081 */
75082 - if (s->refcount < 0)
75083 + if (atomic_read(&s->refcount) < 0)
75084 return 1;
75085
75086 return 0;
75087 @@ -3904,7 +3949,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
75088 down_write(&slub_lock);
75089 s = find_mergeable(size, align, flags, name, ctor);
75090 if (s) {
75091 - s->refcount++;
75092 + atomic_inc(&s->refcount);
75093 /*
75094 * Adjust the object sizes so that we clear
75095 * the complete object on kzalloc.
75096 @@ -3913,7 +3958,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
75097 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75098
75099 if (sysfs_slab_alias(s, name)) {
75100 - s->refcount--;
75101 + atomic_dec(&s->refcount);
75102 goto err;
75103 }
75104 up_write(&slub_lock);
75105 @@ -4042,7 +4087,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75106 }
75107 #endif
75108
75109 -#ifdef CONFIG_SYSFS
75110 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75111 static int count_inuse(struct page *page)
75112 {
75113 return page->inuse;
75114 @@ -4429,12 +4474,12 @@ static void resiliency_test(void)
75115 validate_slab_cache(kmalloc_caches[9]);
75116 }
75117 #else
75118 -#ifdef CONFIG_SYSFS
75119 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75120 static void resiliency_test(void) {};
75121 #endif
75122 #endif
75123
75124 -#ifdef CONFIG_SYSFS
75125 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75126 enum slab_stat_type {
75127 SL_ALL, /* All slabs */
75128 SL_PARTIAL, /* Only partially allocated slabs */
75129 @@ -4677,7 +4722,7 @@ SLAB_ATTR_RO(ctor);
75130
75131 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75132 {
75133 - return sprintf(buf, "%d\n", s->refcount - 1);
75134 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75135 }
75136 SLAB_ATTR_RO(aliases);
75137
75138 @@ -5244,6 +5289,7 @@ static char *create_unique_id(struct kmem_cache *s)
75139 return name;
75140 }
75141
75142 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75143 static int sysfs_slab_add(struct kmem_cache *s)
75144 {
75145 int err;
75146 @@ -5306,6 +5352,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75147 kobject_del(&s->kobj);
75148 kobject_put(&s->kobj);
75149 }
75150 +#endif
75151
75152 /*
75153 * Need to buffer aliases during bootup until sysfs becomes
75154 @@ -5319,6 +5366,7 @@ struct saved_alias {
75155
75156 static struct saved_alias *alias_list;
75157
75158 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75159 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75160 {
75161 struct saved_alias *al;
75162 @@ -5341,6 +5389,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75163 alias_list = al;
75164 return 0;
75165 }
75166 +#endif
75167
75168 static int __init slab_sysfs_init(void)
75169 {
75170 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75171 index 1b7e22a..3fcd4f3 100644
75172 --- a/mm/sparse-vmemmap.c
75173 +++ b/mm/sparse-vmemmap.c
75174 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75175 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75176 if (!p)
75177 return NULL;
75178 - pud_populate(&init_mm, pud, p);
75179 + pud_populate_kernel(&init_mm, pud, p);
75180 }
75181 return pud;
75182 }
75183 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75184 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75185 if (!p)
75186 return NULL;
75187 - pgd_populate(&init_mm, pgd, p);
75188 + pgd_populate_kernel(&init_mm, pgd, p);
75189 }
75190 return pgd;
75191 }
75192 diff --git a/mm/swap.c b/mm/swap.c
75193 index 14380e9..e244704 100644
75194 --- a/mm/swap.c
75195 +++ b/mm/swap.c
75196 @@ -30,6 +30,7 @@
75197 #include <linux/backing-dev.h>
75198 #include <linux/memcontrol.h>
75199 #include <linux/gfp.h>
75200 +#include <linux/hugetlb.h>
75201
75202 #include "internal.h"
75203
75204 @@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
75205
75206 __page_cache_release(page);
75207 dtor = get_compound_page_dtor(page);
75208 + if (!PageHuge(page))
75209 + BUG_ON(dtor != free_compound_page);
75210 (*dtor)(page);
75211 }
75212
75213 diff --git a/mm/swapfile.c b/mm/swapfile.c
75214 index f31b29d..8bdcae2 100644
75215 --- a/mm/swapfile.c
75216 +++ b/mm/swapfile.c
75217 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
75218
75219 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75220 /* Activity counter to indicate that a swapon or swapoff has occurred */
75221 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75222 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75223
75224 static inline unsigned char swap_count(unsigned char ent)
75225 {
75226 @@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75227 }
75228 filp_close(swap_file, NULL);
75229 err = 0;
75230 - atomic_inc(&proc_poll_event);
75231 + atomic_inc_unchecked(&proc_poll_event);
75232 wake_up_interruptible(&proc_poll_wait);
75233
75234 out_dput:
75235 @@ -1685,8 +1685,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75236
75237 poll_wait(file, &proc_poll_wait, wait);
75238
75239 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75240 - seq->poll_event = atomic_read(&proc_poll_event);
75241 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75242 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75243 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75244 }
75245
75246 @@ -1784,7 +1784,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75247 return ret;
75248
75249 seq = file->private_data;
75250 - seq->poll_event = atomic_read(&proc_poll_event);
75251 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75252 return 0;
75253 }
75254
75255 @@ -2122,7 +2122,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75256 (p->flags & SWP_DISCARDABLE) ? "D" : "");
75257
75258 mutex_unlock(&swapon_mutex);
75259 - atomic_inc(&proc_poll_event);
75260 + atomic_inc_unchecked(&proc_poll_event);
75261 wake_up_interruptible(&proc_poll_wait);
75262
75263 if (S_ISREG(inode->i_mode))
75264 diff --git a/mm/util.c b/mm/util.c
75265 index 136ac4f..f917fa9 100644
75266 --- a/mm/util.c
75267 +++ b/mm/util.c
75268 @@ -243,6 +243,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
75269 void arch_pick_mmap_layout(struct mm_struct *mm)
75270 {
75271 mm->mmap_base = TASK_UNMAPPED_BASE;
75272 +
75273 +#ifdef CONFIG_PAX_RANDMMAP
75274 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75275 + mm->mmap_base += mm->delta_mmap;
75276 +#endif
75277 +
75278 mm->get_unmapped_area = arch_get_unmapped_area;
75279 mm->unmap_area = arch_unmap_area;
75280 }
75281 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75282 index 86ce9a5..e0bd080 100644
75283 --- a/mm/vmalloc.c
75284 +++ b/mm/vmalloc.c
75285 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75286
75287 pte = pte_offset_kernel(pmd, addr);
75288 do {
75289 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75290 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75291 +
75292 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75293 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75294 + BUG_ON(!pte_exec(*pte));
75295 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75296 + continue;
75297 + }
75298 +#endif
75299 +
75300 + {
75301 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75302 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75303 + }
75304 } while (pte++, addr += PAGE_SIZE, addr != end);
75305 }
75306
75307 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75308 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75309 {
75310 pte_t *pte;
75311 + int ret = -ENOMEM;
75312
75313 /*
75314 * nr is a running index into the array which helps higher level
75315 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75316 pte = pte_alloc_kernel(pmd, addr);
75317 if (!pte)
75318 return -ENOMEM;
75319 +
75320 + pax_open_kernel();
75321 do {
75322 struct page *page = pages[*nr];
75323
75324 - if (WARN_ON(!pte_none(*pte)))
75325 - return -EBUSY;
75326 - if (WARN_ON(!page))
75327 - return -ENOMEM;
75328 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75329 + if (pgprot_val(prot) & _PAGE_NX)
75330 +#endif
75331 +
75332 + if (WARN_ON(!pte_none(*pte))) {
75333 + ret = -EBUSY;
75334 + goto out;
75335 + }
75336 + if (WARN_ON(!page)) {
75337 + ret = -ENOMEM;
75338 + goto out;
75339 + }
75340 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75341 (*nr)++;
75342 } while (pte++, addr += PAGE_SIZE, addr != end);
75343 - return 0;
75344 + ret = 0;
75345 +out:
75346 + pax_close_kernel();
75347 + return ret;
75348 }
75349
75350 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75351 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75352 pmd_t *pmd;
75353 unsigned long next;
75354
75355 - pmd = pmd_alloc(&init_mm, pud, addr);
75356 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75357 if (!pmd)
75358 return -ENOMEM;
75359 do {
75360 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75361 pud_t *pud;
75362 unsigned long next;
75363
75364 - pud = pud_alloc(&init_mm, pgd, addr);
75365 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75366 if (!pud)
75367 return -ENOMEM;
75368 do {
75369 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75370 * and fall back on vmalloc() if that fails. Others
75371 * just put it in the vmalloc space.
75372 */
75373 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75374 +#ifdef CONFIG_MODULES
75375 +#ifdef MODULES_VADDR
75376 unsigned long addr = (unsigned long)x;
75377 if (addr >= MODULES_VADDR && addr < MODULES_END)
75378 return 1;
75379 #endif
75380 +
75381 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75382 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75383 + return 1;
75384 +#endif
75385 +
75386 +#endif
75387 +
75388 return is_vmalloc_addr(x);
75389 }
75390
75391 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75392
75393 if (!pgd_none(*pgd)) {
75394 pud_t *pud = pud_offset(pgd, addr);
75395 +#ifdef CONFIG_X86
75396 + if (!pud_large(*pud))
75397 +#endif
75398 if (!pud_none(*pud)) {
75399 pmd_t *pmd = pmd_offset(pud, addr);
75400 +#ifdef CONFIG_X86
75401 + if (!pmd_large(*pmd))
75402 +#endif
75403 if (!pmd_none(*pmd)) {
75404 pte_t *ptep, pte;
75405
75406 @@ -1319,6 +1359,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75407 struct vm_struct *area;
75408
75409 BUG_ON(in_interrupt());
75410 +
75411 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75412 + if (flags & VM_KERNEXEC) {
75413 + if (start != VMALLOC_START || end != VMALLOC_END)
75414 + return NULL;
75415 + start = (unsigned long)MODULES_EXEC_VADDR;
75416 + end = (unsigned long)MODULES_EXEC_END;
75417 + }
75418 +#endif
75419 +
75420 if (flags & VM_IOREMAP) {
75421 int bit = fls(size);
75422
75423 @@ -1551,6 +1601,11 @@ void *vmap(struct page **pages, unsigned int count,
75424 if (count > totalram_pages)
75425 return NULL;
75426
75427 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75428 + if (!(pgprot_val(prot) & _PAGE_NX))
75429 + flags |= VM_KERNEXEC;
75430 +#endif
75431 +
75432 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75433 __builtin_return_address(0));
75434 if (!area)
75435 @@ -1652,6 +1707,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75436 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75437 goto fail;
75438
75439 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75440 + if (!(pgprot_val(prot) & _PAGE_NX))
75441 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75442 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75443 + else
75444 +#endif
75445 +
75446 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75447 start, end, node, gfp_mask, caller);
75448 if (!area)
75449 @@ -1825,10 +1887,9 @@ EXPORT_SYMBOL(vzalloc_node);
75450 * For tight control over page level allocator and protection flags
75451 * use __vmalloc() instead.
75452 */
75453 -
75454 void *vmalloc_exec(unsigned long size)
75455 {
75456 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75457 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75458 -1, __builtin_return_address(0));
75459 }
75460
75461 @@ -2123,6 +2184,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75462 unsigned long uaddr = vma->vm_start;
75463 unsigned long usize = vma->vm_end - vma->vm_start;
75464
75465 + BUG_ON(vma->vm_mirror);
75466 +
75467 if ((PAGE_SIZE-1) & (unsigned long)addr)
75468 return -EINVAL;
75469
75470 diff --git a/mm/vmstat.c b/mm/vmstat.c
75471 index f600557..1459fc8 100644
75472 --- a/mm/vmstat.c
75473 +++ b/mm/vmstat.c
75474 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75475 *
75476 * vm_stat contains the global counters
75477 */
75478 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75479 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75480 EXPORT_SYMBOL(vm_stat);
75481
75482 #ifdef CONFIG_SMP
75483 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75484 v = p->vm_stat_diff[i];
75485 p->vm_stat_diff[i] = 0;
75486 local_irq_restore(flags);
75487 - atomic_long_add(v, &zone->vm_stat[i]);
75488 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75489 global_diff[i] += v;
75490 #ifdef CONFIG_NUMA
75491 /* 3 seconds idle till flush */
75492 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75493
75494 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75495 if (global_diff[i])
75496 - atomic_long_add(global_diff[i], &vm_stat[i]);
75497 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75498 }
75499
75500 #endif
75501 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
75502 start_cpu_timer(cpu);
75503 #endif
75504 #ifdef CONFIG_PROC_FS
75505 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75506 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75507 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75508 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75509 + {
75510 + mode_t gr_mode = S_IRUGO;
75511 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75512 + gr_mode = S_IRUSR;
75513 +#endif
75514 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75515 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75516 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75517 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75518 +#else
75519 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75520 +#endif
75521 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75522 + }
75523 #endif
75524 return 0;
75525 }
75526 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75527 index efea35b..9c8dd0b 100644
75528 --- a/net/8021q/vlan.c
75529 +++ b/net/8021q/vlan.c
75530 @@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75531 err = -EPERM;
75532 if (!capable(CAP_NET_ADMIN))
75533 break;
75534 - if ((args.u.name_type >= 0) &&
75535 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75536 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75537 struct vlan_net *vn;
75538
75539 vn = net_generic(net, vlan_net_id);
75540 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75541 index fccae26..e7ece2f 100644
75542 --- a/net/9p/trans_fd.c
75543 +++ b/net/9p/trans_fd.c
75544 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75545 oldfs = get_fs();
75546 set_fs(get_ds());
75547 /* The cast to a user pointer is valid due to the set_fs() */
75548 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75549 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75550 set_fs(oldfs);
75551
75552 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75553 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75554 index 876fbe8..8bbea9f 100644
75555 --- a/net/atm/atm_misc.c
75556 +++ b/net/atm/atm_misc.c
75557 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75558 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75559 return 1;
75560 atm_return(vcc, truesize);
75561 - atomic_inc(&vcc->stats->rx_drop);
75562 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75563 return 0;
75564 }
75565 EXPORT_SYMBOL(atm_charge);
75566 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75567 }
75568 }
75569 atm_return(vcc, guess);
75570 - atomic_inc(&vcc->stats->rx_drop);
75571 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75572 return NULL;
75573 }
75574 EXPORT_SYMBOL(atm_alloc_charge);
75575 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75576
75577 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75578 {
75579 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75580 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75581 __SONET_ITEMS
75582 #undef __HANDLE_ITEM
75583 }
75584 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75585
75586 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75587 {
75588 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75589 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75590 __SONET_ITEMS
75591 #undef __HANDLE_ITEM
75592 }
75593 diff --git a/net/atm/lec.h b/net/atm/lec.h
75594 index dfc0719..47c5322 100644
75595 --- a/net/atm/lec.h
75596 +++ b/net/atm/lec.h
75597 @@ -48,7 +48,7 @@ struct lane2_ops {
75598 const u8 *tlvs, u32 sizeoftlvs);
75599 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75600 const u8 *tlvs, u32 sizeoftlvs);
75601 -};
75602 +} __no_const;
75603
75604 /*
75605 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75606 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75607 index 0919a88..a23d54e 100644
75608 --- a/net/atm/mpc.h
75609 +++ b/net/atm/mpc.h
75610 @@ -33,7 +33,7 @@ struct mpoa_client {
75611 struct mpc_parameters parameters; /* parameters for this client */
75612
75613 const struct net_device_ops *old_ops;
75614 - struct net_device_ops new_ops;
75615 + net_device_ops_no_const new_ops;
75616 };
75617
75618
75619 diff --git a/net/atm/proc.c b/net/atm/proc.c
75620 index 0d020de..011c7bb 100644
75621 --- a/net/atm/proc.c
75622 +++ b/net/atm/proc.c
75623 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75624 const struct k_atm_aal_stats *stats)
75625 {
75626 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75627 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75628 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75629 - atomic_read(&stats->rx_drop));
75630 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75631 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75632 + atomic_read_unchecked(&stats->rx_drop));
75633 }
75634
75635 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75636 diff --git a/net/atm/resources.c b/net/atm/resources.c
75637 index 23f45ce..c748f1a 100644
75638 --- a/net/atm/resources.c
75639 +++ b/net/atm/resources.c
75640 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75641 static void copy_aal_stats(struct k_atm_aal_stats *from,
75642 struct atm_aal_stats *to)
75643 {
75644 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75645 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75646 __AAL_STAT_ITEMS
75647 #undef __HANDLE_ITEM
75648 }
75649 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75650 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75651 struct atm_aal_stats *to)
75652 {
75653 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75654 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75655 __AAL_STAT_ITEMS
75656 #undef __HANDLE_ITEM
75657 }
75658 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75659 index 3512e25..2b33401 100644
75660 --- a/net/batman-adv/bat_iv_ogm.c
75661 +++ b/net/batman-adv/bat_iv_ogm.c
75662 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
75663
75664 /* change sequence number to network order */
75665 batman_ogm_packet->seqno =
75666 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75667 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75668
75669 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75670 batman_ogm_packet->tt_crc = htons((uint16_t)
75671 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
75672 else
75673 batman_ogm_packet->gw_flags = NO_FLAGS;
75674
75675 - atomic_inc(&hard_iface->seqno);
75676 + atomic_inc_unchecked(&hard_iface->seqno);
75677
75678 slide_own_bcast_window(hard_iface);
75679 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75680 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
75681 return;
75682
75683 /* could be changed by schedule_own_packet() */
75684 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75685 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75686
75687 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75688
75689 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75690 index 7704df4..beb4e16 100644
75691 --- a/net/batman-adv/hard-interface.c
75692 +++ b/net/batman-adv/hard-interface.c
75693 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75694 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75695 dev_add_pack(&hard_iface->batman_adv_ptype);
75696
75697 - atomic_set(&hard_iface->seqno, 1);
75698 - atomic_set(&hard_iface->frag_seqno, 1);
75699 + atomic_set_unchecked(&hard_iface->seqno, 1);
75700 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75701 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75702 hard_iface->net_dev->name);
75703
75704 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75705 index 987c75a..20d6f36 100644
75706 --- a/net/batman-adv/soft-interface.c
75707 +++ b/net/batman-adv/soft-interface.c
75708 @@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75709
75710 /* set broadcast sequence number */
75711 bcast_packet->seqno =
75712 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75713 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75714
75715 add_bcast_packet_to_list(bat_priv, skb, 1);
75716
75717 @@ -843,7 +843,7 @@ struct net_device *softif_create(const char *name)
75718 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75719
75720 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75721 - atomic_set(&bat_priv->bcast_seqno, 1);
75722 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75723 atomic_set(&bat_priv->ttvn, 0);
75724 atomic_set(&bat_priv->tt_local_changes, 0);
75725 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75726 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75727 index e9eb043..d174eeb 100644
75728 --- a/net/batman-adv/types.h
75729 +++ b/net/batman-adv/types.h
75730 @@ -38,8 +38,8 @@ struct hard_iface {
75731 int16_t if_num;
75732 char if_status;
75733 struct net_device *net_dev;
75734 - atomic_t seqno;
75735 - atomic_t frag_seqno;
75736 + atomic_unchecked_t seqno;
75737 + atomic_unchecked_t frag_seqno;
75738 unsigned char *packet_buff;
75739 int packet_len;
75740 struct kobject *hardif_obj;
75741 @@ -154,7 +154,7 @@ struct bat_priv {
75742 atomic_t orig_interval; /* uint */
75743 atomic_t hop_penalty; /* uint */
75744 atomic_t log_level; /* uint */
75745 - atomic_t bcast_seqno;
75746 + atomic_unchecked_t bcast_seqno;
75747 atomic_t bcast_queue_left;
75748 atomic_t batman_queue_left;
75749 atomic_t ttvn; /* translation table version number */
75750 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75751 index 07d1c1d..7e9bea9 100644
75752 --- a/net/batman-adv/unicast.c
75753 +++ b/net/batman-adv/unicast.c
75754 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75755 frag1->flags = UNI_FRAG_HEAD | large_tail;
75756 frag2->flags = large_tail;
75757
75758 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75759 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75760 frag1->seqno = htons(seqno - 1);
75761 frag2->seqno = htons(seqno);
75762
75763 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
75764 index 280953b..cd219bb 100644
75765 --- a/net/bluetooth/hci_conn.c
75766 +++ b/net/bluetooth/hci_conn.c
75767 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
75768 memset(&cp, 0, sizeof(cp));
75769
75770 cp.handle = cpu_to_le16(conn->handle);
75771 - memcpy(cp.ltk, ltk, sizeof(ltk));
75772 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
75773
75774 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
75775 }
75776 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75777 index 32d338c..d24bcdb 100644
75778 --- a/net/bluetooth/l2cap_core.c
75779 +++ b/net/bluetooth/l2cap_core.c
75780 @@ -2418,8 +2418,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75781 break;
75782
75783 case L2CAP_CONF_RFC:
75784 - if (olen == sizeof(rfc))
75785 - memcpy(&rfc, (void *)val, olen);
75786 + if (olen != sizeof(rfc))
75787 + break;
75788 +
75789 + memcpy(&rfc, (void *)val, olen);
75790
75791 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75792 rfc.mode != chan->mode)
75793 @@ -2537,8 +2539,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
75794
75795 switch (type) {
75796 case L2CAP_CONF_RFC:
75797 - if (olen == sizeof(rfc))
75798 - memcpy(&rfc, (void *)val, olen);
75799 + if (olen != sizeof(rfc))
75800 + break;
75801 +
75802 + memcpy(&rfc, (void *)val, olen);
75803 goto done;
75804 }
75805 }
75806 diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
75807 index 5449294..7da9a5f 100644
75808 --- a/net/bridge/netfilter/ebt_ulog.c
75809 +++ b/net/bridge/netfilter/ebt_ulog.c
75810 @@ -96,6 +96,7 @@ static void ulog_timer(unsigned long data)
75811 spin_unlock_bh(&ulog_buffers[data].lock);
75812 }
75813
75814 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
75815 static struct sk_buff *ulog_alloc_skb(unsigned int size)
75816 {
75817 struct sk_buff *skb;
75818 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75819 index 5fe2ff3..10968b5 100644
75820 --- a/net/bridge/netfilter/ebtables.c
75821 +++ b/net/bridge/netfilter/ebtables.c
75822 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75823 tmp.valid_hooks = t->table->valid_hooks;
75824 }
75825 mutex_unlock(&ebt_mutex);
75826 - if (copy_to_user(user, &tmp, *len) != 0){
75827 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75828 BUGPRINT("c2u Didn't work\n");
75829 ret = -EFAULT;
75830 break;
75831 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
75832 index a97d97a..6f679ed 100644
75833 --- a/net/caif/caif_socket.c
75834 +++ b/net/caif/caif_socket.c
75835 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
75836 #ifdef CONFIG_DEBUG_FS
75837 struct debug_fs_counter {
75838 atomic_t caif_nr_socks;
75839 - atomic_t caif_sock_create;
75840 - atomic_t num_connect_req;
75841 - atomic_t num_connect_resp;
75842 - atomic_t num_connect_fail_resp;
75843 - atomic_t num_disconnect;
75844 - atomic_t num_remote_shutdown_ind;
75845 - atomic_t num_tx_flow_off_ind;
75846 - atomic_t num_tx_flow_on_ind;
75847 - atomic_t num_rx_flow_off;
75848 - atomic_t num_rx_flow_on;
75849 + atomic_unchecked_t caif_sock_create;
75850 + atomic_unchecked_t num_connect_req;
75851 + atomic_unchecked_t num_connect_resp;
75852 + atomic_unchecked_t num_connect_fail_resp;
75853 + atomic_unchecked_t num_disconnect;
75854 + atomic_unchecked_t num_remote_shutdown_ind;
75855 + atomic_unchecked_t num_tx_flow_off_ind;
75856 + atomic_unchecked_t num_tx_flow_on_ind;
75857 + atomic_unchecked_t num_rx_flow_off;
75858 + atomic_unchecked_t num_rx_flow_on;
75859 };
75860 static struct debug_fs_counter cnt;
75861 #define dbfs_atomic_inc(v) atomic_inc_return(v)
75862 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
75863 #define dbfs_atomic_dec(v) atomic_dec_return(v)
75864 #else
75865 #define dbfs_atomic_inc(v) 0
75866 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75867 atomic_read(&cf_sk->sk.sk_rmem_alloc),
75868 sk_rcvbuf_lowwater(cf_sk));
75869 set_rx_flow_off(cf_sk);
75870 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75871 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75872 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75873 }
75874
75875 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75876 set_rx_flow_off(cf_sk);
75877 if (net_ratelimit())
75878 pr_debug("sending flow OFF due to rmem_schedule\n");
75879 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
75880 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
75881 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
75882 }
75883 skb->dev = NULL;
75884 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
75885 switch (flow) {
75886 case CAIF_CTRLCMD_FLOW_ON_IND:
75887 /* OK from modem to start sending again */
75888 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
75889 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
75890 set_tx_flow_on(cf_sk);
75891 cf_sk->sk.sk_state_change(&cf_sk->sk);
75892 break;
75893
75894 case CAIF_CTRLCMD_FLOW_OFF_IND:
75895 /* Modem asks us to shut up */
75896 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
75897 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
75898 set_tx_flow_off(cf_sk);
75899 cf_sk->sk.sk_state_change(&cf_sk->sk);
75900 break;
75901 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75902 /* We're now connected */
75903 caif_client_register_refcnt(&cf_sk->layer,
75904 cfsk_hold, cfsk_put);
75905 - dbfs_atomic_inc(&cnt.num_connect_resp);
75906 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
75907 cf_sk->sk.sk_state = CAIF_CONNECTED;
75908 set_tx_flow_on(cf_sk);
75909 cf_sk->sk.sk_state_change(&cf_sk->sk);
75910 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75911
75912 case CAIF_CTRLCMD_INIT_FAIL_RSP:
75913 /* Connect request failed */
75914 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
75915 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
75916 cf_sk->sk.sk_err = ECONNREFUSED;
75917 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
75918 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75919 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
75920
75921 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
75922 /* Modem has closed this connection, or device is down. */
75923 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
75924 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
75925 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
75926 cf_sk->sk.sk_err = ECONNRESET;
75927 set_rx_flow_on(cf_sk);
75928 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
75929 return;
75930
75931 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
75932 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
75933 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
75934 set_rx_flow_on(cf_sk);
75935 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
75936 }
75937 @@ -856,7 +857,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
75938 /*ifindex = id of the interface.*/
75939 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
75940
75941 - dbfs_atomic_inc(&cnt.num_connect_req);
75942 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
75943 cf_sk->layer.receive = caif_sktrecv_cb;
75944
75945 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
75946 @@ -945,7 +946,7 @@ static int caif_release(struct socket *sock)
75947 spin_unlock_bh(&sk->sk_receive_queue.lock);
75948 sock->sk = NULL;
75949
75950 - dbfs_atomic_inc(&cnt.num_disconnect);
75951 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
75952
75953 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
75954 if (cf_sk->debugfs_socket_dir != NULL)
75955 @@ -1124,7 +1125,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
75956 cf_sk->conn_req.protocol = protocol;
75957 /* Increase the number of sockets created. */
75958 dbfs_atomic_inc(&cnt.caif_nr_socks);
75959 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
75960 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
75961 #ifdef CONFIG_DEBUG_FS
75962 if (!IS_ERR(debugfsdir)) {
75963
75964 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75965 index 5cf5222..6f704ad 100644
75966 --- a/net/caif/cfctrl.c
75967 +++ b/net/caif/cfctrl.c
75968 @@ -9,6 +9,7 @@
75969 #include <linux/stddef.h>
75970 #include <linux/spinlock.h>
75971 #include <linux/slab.h>
75972 +#include <linux/sched.h>
75973 #include <net/caif/caif_layer.h>
75974 #include <net/caif/cfpkt.h>
75975 #include <net/caif/cfctrl.h>
75976 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
75977 memset(&dev_info, 0, sizeof(dev_info));
75978 dev_info.id = 0xff;
75979 cfsrvl_init(&this->serv, 0, &dev_info, false);
75980 - atomic_set(&this->req_seq_no, 1);
75981 - atomic_set(&this->rsp_seq_no, 1);
75982 + atomic_set_unchecked(&this->req_seq_no, 1);
75983 + atomic_set_unchecked(&this->rsp_seq_no, 1);
75984 this->serv.layer.receive = cfctrl_recv;
75985 sprintf(this->serv.layer.name, "ctrl");
75986 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75987 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75988 struct cfctrl_request_info *req)
75989 {
75990 spin_lock_bh(&ctrl->info_list_lock);
75991 - atomic_inc(&ctrl->req_seq_no);
75992 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
75993 + atomic_inc_unchecked(&ctrl->req_seq_no);
75994 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75995 list_add_tail(&req->list, &ctrl->list);
75996 spin_unlock_bh(&ctrl->info_list_lock);
75997 }
75998 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75999 if (p != first)
76000 pr_warn("Requests are not received in order\n");
76001
76002 - atomic_set(&ctrl->rsp_seq_no,
76003 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76004 p->sequence_no);
76005 list_del(&p->list);
76006 goto out;
76007 diff --git a/net/can/gw.c b/net/can/gw.c
76008 index 3d79b12..8de85fa 100644
76009 --- a/net/can/gw.c
76010 +++ b/net/can/gw.c
76011 @@ -96,7 +96,7 @@ struct cf_mod {
76012 struct {
76013 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76014 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76015 - } csumfunc;
76016 + } __no_const csumfunc;
76017 };
76018
76019
76020 diff --git a/net/compat.c b/net/compat.c
76021 index 6def90e..c6992fa 100644
76022 --- a/net/compat.c
76023 +++ b/net/compat.c
76024 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76025 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76026 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76027 return -EFAULT;
76028 - kmsg->msg_name = compat_ptr(tmp1);
76029 - kmsg->msg_iov = compat_ptr(tmp2);
76030 - kmsg->msg_control = compat_ptr(tmp3);
76031 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76032 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76033 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76034 return 0;
76035 }
76036
76037 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76038
76039 if (kern_msg->msg_namelen) {
76040 if (mode == VERIFY_READ) {
76041 - int err = move_addr_to_kernel(kern_msg->msg_name,
76042 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76043 kern_msg->msg_namelen,
76044 kern_address);
76045 if (err < 0)
76046 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76047 kern_msg->msg_name = NULL;
76048
76049 tot_len = iov_from_user_compat_to_kern(kern_iov,
76050 - (struct compat_iovec __user *)kern_msg->msg_iov,
76051 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76052 kern_msg->msg_iovlen);
76053 if (tot_len >= 0)
76054 kern_msg->msg_iov = kern_iov;
76055 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76056
76057 #define CMSG_COMPAT_FIRSTHDR(msg) \
76058 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76059 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76060 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76061 (struct compat_cmsghdr __user *)NULL)
76062
76063 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76064 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76065 (ucmlen) <= (unsigned long) \
76066 ((mhdr)->msg_controllen - \
76067 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76068 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76069
76070 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76071 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76072 {
76073 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76074 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76075 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76076 msg->msg_controllen)
76077 return NULL;
76078 return (struct compat_cmsghdr __user *)ptr;
76079 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76080 {
76081 struct compat_timeval ctv;
76082 struct compat_timespec cts[3];
76083 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76084 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76085 struct compat_cmsghdr cmhdr;
76086 int cmlen;
76087
76088 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76089
76090 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76091 {
76092 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76093 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76094 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76095 int fdnum = scm->fp->count;
76096 struct file **fp = scm->fp->fp;
76097 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76098 return -EFAULT;
76099 old_fs = get_fs();
76100 set_fs(KERNEL_DS);
76101 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76102 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76103 set_fs(old_fs);
76104
76105 return err;
76106 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76107 len = sizeof(ktime);
76108 old_fs = get_fs();
76109 set_fs(KERNEL_DS);
76110 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76111 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76112 set_fs(old_fs);
76113
76114 if (!err) {
76115 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76116 case MCAST_JOIN_GROUP:
76117 case MCAST_LEAVE_GROUP:
76118 {
76119 - struct compat_group_req __user *gr32 = (void *)optval;
76120 + struct compat_group_req __user *gr32 = (void __user *)optval;
76121 struct group_req __user *kgr =
76122 compat_alloc_user_space(sizeof(struct group_req));
76123 u32 interface;
76124 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76125 case MCAST_BLOCK_SOURCE:
76126 case MCAST_UNBLOCK_SOURCE:
76127 {
76128 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76129 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76130 struct group_source_req __user *kgsr = compat_alloc_user_space(
76131 sizeof(struct group_source_req));
76132 u32 interface;
76133 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76134 }
76135 case MCAST_MSFILTER:
76136 {
76137 - struct compat_group_filter __user *gf32 = (void *)optval;
76138 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76139 struct group_filter __user *kgf;
76140 u32 interface, fmode, numsrc;
76141
76142 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76143 char __user *optval, int __user *optlen,
76144 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76145 {
76146 - struct compat_group_filter __user *gf32 = (void *)optval;
76147 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76148 struct group_filter __user *kgf;
76149 int __user *koptlen;
76150 u32 interface, fmode, numsrc;
76151 diff --git a/net/core/datagram.c b/net/core/datagram.c
76152 index 68bbf9f..5ef0d12 100644
76153 --- a/net/core/datagram.c
76154 +++ b/net/core/datagram.c
76155 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76156 }
76157
76158 kfree_skb(skb);
76159 - atomic_inc(&sk->sk_drops);
76160 + atomic_inc_unchecked(&sk->sk_drops);
76161 sk_mem_reclaim_partial(sk);
76162
76163 return err;
76164 diff --git a/net/core/dev.c b/net/core/dev.c
76165 index 0336374..659088a 100644
76166 --- a/net/core/dev.c
76167 +++ b/net/core/dev.c
76168 @@ -1138,10 +1138,14 @@ void dev_load(struct net *net, const char *name)
76169 if (no_module && capable(CAP_NET_ADMIN))
76170 no_module = request_module("netdev-%s", name);
76171 if (no_module && capable(CAP_SYS_MODULE)) {
76172 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76173 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76174 +#else
76175 if (!request_module("%s", name))
76176 pr_err("Loading kernel module for a network device "
76177 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
76178 "instead\n", name);
76179 +#endif
76180 }
76181 }
76182 EXPORT_SYMBOL(dev_load);
76183 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76184 {
76185 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76186 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76187 - atomic_long_inc(&dev->rx_dropped);
76188 + atomic_long_inc_unchecked(&dev->rx_dropped);
76189 kfree_skb(skb);
76190 return NET_RX_DROP;
76191 }
76192 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76193 nf_reset(skb);
76194
76195 if (unlikely(!is_skb_forwardable(dev, skb))) {
76196 - atomic_long_inc(&dev->rx_dropped);
76197 + atomic_long_inc_unchecked(&dev->rx_dropped);
76198 kfree_skb(skb);
76199 return NET_RX_DROP;
76200 }
76201 @@ -2077,7 +2081,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76202
76203 struct dev_gso_cb {
76204 void (*destructor)(struct sk_buff *skb);
76205 -};
76206 +} __no_const;
76207
76208 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76209
76210 @@ -2933,7 +2937,7 @@ enqueue:
76211
76212 local_irq_restore(flags);
76213
76214 - atomic_long_inc(&skb->dev->rx_dropped);
76215 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76216 kfree_skb(skb);
76217 return NET_RX_DROP;
76218 }
76219 @@ -3005,7 +3009,7 @@ int netif_rx_ni(struct sk_buff *skb)
76220 }
76221 EXPORT_SYMBOL(netif_rx_ni);
76222
76223 -static void net_tx_action(struct softirq_action *h)
76224 +static void net_tx_action(void)
76225 {
76226 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76227
76228 @@ -3293,7 +3297,7 @@ ncls:
76229 if (pt_prev) {
76230 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76231 } else {
76232 - atomic_long_inc(&skb->dev->rx_dropped);
76233 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76234 kfree_skb(skb);
76235 /* Jamal, now you will not able to escape explaining
76236 * me how you were going to use this. :-)
76237 @@ -3853,7 +3857,7 @@ void netif_napi_del(struct napi_struct *napi)
76238 }
76239 EXPORT_SYMBOL(netif_napi_del);
76240
76241 -static void net_rx_action(struct softirq_action *h)
76242 +static void net_rx_action(void)
76243 {
76244 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76245 unsigned long time_limit = jiffies + 2;
76246 @@ -5878,7 +5882,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76247 } else {
76248 netdev_stats_to_stats64(storage, &dev->stats);
76249 }
76250 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76251 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76252 return storage;
76253 }
76254 EXPORT_SYMBOL(dev_get_stats);
76255 diff --git a/net/core/flow.c b/net/core/flow.c
76256 index e318c7e..168b1d0 100644
76257 --- a/net/core/flow.c
76258 +++ b/net/core/flow.c
76259 @@ -61,7 +61,7 @@ struct flow_cache {
76260 struct timer_list rnd_timer;
76261 };
76262
76263 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76264 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76265 EXPORT_SYMBOL(flow_cache_genid);
76266 static struct flow_cache flow_cache_global;
76267 static struct kmem_cache *flow_cachep __read_mostly;
76268 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76269
76270 static int flow_entry_valid(struct flow_cache_entry *fle)
76271 {
76272 - if (atomic_read(&flow_cache_genid) != fle->genid)
76273 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76274 return 0;
76275 if (fle->object && !fle->object->ops->check(fle->object))
76276 return 0;
76277 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76278 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76279 fcp->hash_count++;
76280 }
76281 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76282 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76283 flo = fle->object;
76284 if (!flo)
76285 goto ret_object;
76286 @@ -280,7 +280,7 @@ nocache:
76287 }
76288 flo = resolver(net, key, family, dir, flo, ctx);
76289 if (fle) {
76290 - fle->genid = atomic_read(&flow_cache_genid);
76291 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76292 if (!IS_ERR(flo))
76293 fle->object = flo;
76294 else
76295 diff --git a/net/core/iovec.c b/net/core/iovec.c
76296 index c40f27e..7f49254 100644
76297 --- a/net/core/iovec.c
76298 +++ b/net/core/iovec.c
76299 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
76300 if (m->msg_namelen) {
76301 if (mode == VERIFY_READ) {
76302 void __user *namep;
76303 - namep = (void __user __force *) m->msg_name;
76304 + namep = (void __force_user *) m->msg_name;
76305 err = move_addr_to_kernel(namep, m->msg_namelen,
76306 address);
76307 if (err < 0)
76308 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
76309 }
76310
76311 size = m->msg_iovlen * sizeof(struct iovec);
76312 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76313 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76314 return -EFAULT;
76315
76316 m->msg_iov = iov;
76317 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76318 index 5c30296..ebe7b61 100644
76319 --- a/net/core/rtnetlink.c
76320 +++ b/net/core/rtnetlink.c
76321 @@ -57,7 +57,7 @@ struct rtnl_link {
76322 rtnl_doit_func doit;
76323 rtnl_dumpit_func dumpit;
76324 rtnl_calcit_func calcit;
76325 -};
76326 +} __no_const;
76327
76328 static DEFINE_MUTEX(rtnl_mutex);
76329
76330 diff --git a/net/core/scm.c b/net/core/scm.c
76331 index ff52ad0..aff1c0f 100644
76332 --- a/net/core/scm.c
76333 +++ b/net/core/scm.c
76334 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
76335 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76336 {
76337 struct cmsghdr __user *cm
76338 - = (__force struct cmsghdr __user *)msg->msg_control;
76339 + = (struct cmsghdr __force_user *)msg->msg_control;
76340 struct cmsghdr cmhdr;
76341 int cmlen = CMSG_LEN(len);
76342 int err;
76343 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76344 err = -EFAULT;
76345 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76346 goto out;
76347 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76348 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76349 goto out;
76350 cmlen = CMSG_SPACE(len);
76351 if (msg->msg_controllen < cmlen)
76352 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
76353 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76354 {
76355 struct cmsghdr __user *cm
76356 - = (__force struct cmsghdr __user*)msg->msg_control;
76357 + = (struct cmsghdr __force_user *)msg->msg_control;
76358
76359 int fdmax = 0;
76360 int fdnum = scm->fp->count;
76361 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76362 if (fdnum < fdmax)
76363 fdmax = fdnum;
76364
76365 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76366 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76367 i++, cmfptr++)
76368 {
76369 int new_fd;
76370 diff --git a/net/core/sock.c b/net/core/sock.c
76371 index 02f8dfe..86dfd4a 100644
76372 --- a/net/core/sock.c
76373 +++ b/net/core/sock.c
76374 @@ -341,7 +341,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76375 struct sk_buff_head *list = &sk->sk_receive_queue;
76376
76377 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76378 - atomic_inc(&sk->sk_drops);
76379 + atomic_inc_unchecked(&sk->sk_drops);
76380 trace_sock_rcvqueue_full(sk, skb);
76381 return -ENOMEM;
76382 }
76383 @@ -351,7 +351,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76384 return err;
76385
76386 if (!sk_rmem_schedule(sk, skb->truesize)) {
76387 - atomic_inc(&sk->sk_drops);
76388 + atomic_inc_unchecked(&sk->sk_drops);
76389 return -ENOBUFS;
76390 }
76391
76392 @@ -371,7 +371,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76393 skb_dst_force(skb);
76394
76395 spin_lock_irqsave(&list->lock, flags);
76396 - skb->dropcount = atomic_read(&sk->sk_drops);
76397 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76398 __skb_queue_tail(list, skb);
76399 spin_unlock_irqrestore(&list->lock, flags);
76400
76401 @@ -391,7 +391,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76402 skb->dev = NULL;
76403
76404 if (sk_rcvqueues_full(sk, skb)) {
76405 - atomic_inc(&sk->sk_drops);
76406 + atomic_inc_unchecked(&sk->sk_drops);
76407 goto discard_and_relse;
76408 }
76409 if (nested)
76410 @@ -409,7 +409,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76411 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76412 } else if (sk_add_backlog(sk, skb)) {
76413 bh_unlock_sock(sk);
76414 - atomic_inc(&sk->sk_drops);
76415 + atomic_inc_unchecked(&sk->sk_drops);
76416 goto discard_and_relse;
76417 }
76418
76419 @@ -974,7 +974,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76420 if (len > sizeof(peercred))
76421 len = sizeof(peercred);
76422 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
76423 - if (copy_to_user(optval, &peercred, len))
76424 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
76425 return -EFAULT;
76426 goto lenout;
76427 }
76428 @@ -987,7 +987,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76429 return -ENOTCONN;
76430 if (lv < len)
76431 return -EINVAL;
76432 - if (copy_to_user(optval, address, len))
76433 + if (len > sizeof(address) || copy_to_user(optval, address, len))
76434 return -EFAULT;
76435 goto lenout;
76436 }
76437 @@ -1024,7 +1024,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76438
76439 if (len > lv)
76440 len = lv;
76441 - if (copy_to_user(optval, &v, len))
76442 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76443 return -EFAULT;
76444 lenout:
76445 if (put_user(len, optlen))
76446 @@ -2108,7 +2108,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76447 */
76448 smp_wmb();
76449 atomic_set(&sk->sk_refcnt, 1);
76450 - atomic_set(&sk->sk_drops, 0);
76451 + atomic_set_unchecked(&sk->sk_drops, 0);
76452 }
76453 EXPORT_SYMBOL(sock_init_data);
76454
76455 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76456 index b9868e1..849f809 100644
76457 --- a/net/core/sock_diag.c
76458 +++ b/net/core/sock_diag.c
76459 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76460
76461 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76462 {
76463 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76464 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76465 cookie[1] != INET_DIAG_NOCOOKIE) &&
76466 ((u32)(unsigned long)sk != cookie[0] ||
76467 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76468 return -ESTALE;
76469 else
76470 +#endif
76471 return 0;
76472 }
76473 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76474
76475 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76476 {
76477 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76478 + cookie[0] = 0;
76479 + cookie[1] = 0;
76480 +#else
76481 cookie[0] = (u32)(unsigned long)sk;
76482 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76483 +#endif
76484 }
76485 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76486
76487 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76488 index 02e75d1..9a57a7c 100644
76489 --- a/net/decnet/sysctl_net_decnet.c
76490 +++ b/net/decnet/sysctl_net_decnet.c
76491 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76492
76493 if (len > *lenp) len = *lenp;
76494
76495 - if (copy_to_user(buffer, addr, len))
76496 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76497 return -EFAULT;
76498
76499 *lenp = len;
76500 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76501
76502 if (len > *lenp) len = *lenp;
76503
76504 - if (copy_to_user(buffer, devname, len))
76505 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76506 return -EFAULT;
76507
76508 *lenp = len;
76509 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
76510 index 39a2d29..f39c0fe 100644
76511 --- a/net/econet/Kconfig
76512 +++ b/net/econet/Kconfig
76513 @@ -4,7 +4,7 @@
76514
76515 config ECONET
76516 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
76517 - depends on EXPERIMENTAL && INET
76518 + depends on EXPERIMENTAL && INET && BROKEN
76519 ---help---
76520 Econet is a fairly old and slow networking protocol mainly used by
76521 Acorn computers to access file and print servers. It uses native
76522 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
76523 index 36d1440..44ff28b 100644
76524 --- a/net/ipv4/ah4.c
76525 +++ b/net/ipv4/ah4.c
76526 @@ -19,6 +19,8 @@ struct ah_skb_cb {
76527 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
76528
76529 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
76530 + unsigned int size) __size_overflow(3);
76531 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
76532 unsigned int size)
76533 {
76534 unsigned int len;
76535 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76536 index 92fc5f6..b790d91 100644
76537 --- a/net/ipv4/fib_frontend.c
76538 +++ b/net/ipv4/fib_frontend.c
76539 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76540 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76541 fib_sync_up(dev);
76542 #endif
76543 - atomic_inc(&net->ipv4.dev_addr_genid);
76544 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76545 rt_cache_flush(dev_net(dev), -1);
76546 break;
76547 case NETDEV_DOWN:
76548 fib_del_ifaddr(ifa, NULL);
76549 - atomic_inc(&net->ipv4.dev_addr_genid);
76550 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76551 if (ifa->ifa_dev->ifa_list == NULL) {
76552 /* Last address was deleted from this interface.
76553 * Disable IP.
76554 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76555 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76556 fib_sync_up(dev);
76557 #endif
76558 - atomic_inc(&net->ipv4.dev_addr_genid);
76559 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76560 rt_cache_flush(dev_net(dev), -1);
76561 break;
76562 case NETDEV_DOWN:
76563 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76564 index 80106d8..232e898 100644
76565 --- a/net/ipv4/fib_semantics.c
76566 +++ b/net/ipv4/fib_semantics.c
76567 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76568 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76569 nh->nh_gw,
76570 nh->nh_parent->fib_scope);
76571 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76572 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76573
76574 return nh->nh_saddr;
76575 }
76576 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76577 index 984ec65..97ac518 100644
76578 --- a/net/ipv4/inet_hashtables.c
76579 +++ b/net/ipv4/inet_hashtables.c
76580 @@ -18,12 +18,15 @@
76581 #include <linux/sched.h>
76582 #include <linux/slab.h>
76583 #include <linux/wait.h>
76584 +#include <linux/security.h>
76585
76586 #include <net/inet_connection_sock.h>
76587 #include <net/inet_hashtables.h>
76588 #include <net/secure_seq.h>
76589 #include <net/ip.h>
76590
76591 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76592 +
76593 /*
76594 * Allocate and initialize a new local port bind bucket.
76595 * The bindhash mutex for snum's hash chain must be held here.
76596 @@ -530,6 +533,8 @@ ok:
76597 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76598 spin_unlock(&head->lock);
76599
76600 + gr_update_task_in_ip_table(current, inet_sk(sk));
76601 +
76602 if (tw) {
76603 inet_twsk_deschedule(tw, death_row);
76604 while (twrefcnt) {
76605 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76606 index d4d61b6..b81aec8 100644
76607 --- a/net/ipv4/inetpeer.c
76608 +++ b/net/ipv4/inetpeer.c
76609 @@ -487,8 +487,8 @@ relookup:
76610 if (p) {
76611 p->daddr = *daddr;
76612 atomic_set(&p->refcnt, 1);
76613 - atomic_set(&p->rid, 0);
76614 - atomic_set(&p->ip_id_count,
76615 + atomic_set_unchecked(&p->rid, 0);
76616 + atomic_set_unchecked(&p->ip_id_count,
76617 (daddr->family == AF_INET) ?
76618 secure_ip_id(daddr->addr.a4) :
76619 secure_ipv6_id(daddr->addr.a6));
76620 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76621 index 1f23a57..7180dfe 100644
76622 --- a/net/ipv4/ip_fragment.c
76623 +++ b/net/ipv4/ip_fragment.c
76624 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76625 return 0;
76626
76627 start = qp->rid;
76628 - end = atomic_inc_return(&peer->rid);
76629 + end = atomic_inc_return_unchecked(&peer->rid);
76630 qp->rid = end;
76631
76632 rc = qp->q.fragments && (end - start) > max;
76633 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76634 index 8aa87c1..35c3248 100644
76635 --- a/net/ipv4/ip_sockglue.c
76636 +++ b/net/ipv4/ip_sockglue.c
76637 @@ -1112,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76638 len = min_t(unsigned int, len, opt->optlen);
76639 if (put_user(len, optlen))
76640 return -EFAULT;
76641 - if (copy_to_user(optval, opt->__data, len))
76642 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76643 + copy_to_user(optval, opt->__data, len))
76644 return -EFAULT;
76645 return 0;
76646 }
76647 @@ -1240,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76648 if (sk->sk_type != SOCK_STREAM)
76649 return -ENOPROTOOPT;
76650
76651 - msg.msg_control = optval;
76652 + msg.msg_control = (void __force_kernel *)optval;
76653 msg.msg_controllen = len;
76654 msg.msg_flags = flags;
76655
76656 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76657 index 6e412a6..6640538 100644
76658 --- a/net/ipv4/ipconfig.c
76659 +++ b/net/ipv4/ipconfig.c
76660 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76661
76662 mm_segment_t oldfs = get_fs();
76663 set_fs(get_ds());
76664 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76665 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76666 set_fs(oldfs);
76667 return res;
76668 }
76669 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76670
76671 mm_segment_t oldfs = get_fs();
76672 set_fs(get_ds());
76673 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76674 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76675 set_fs(oldfs);
76676 return res;
76677 }
76678 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76679
76680 mm_segment_t oldfs = get_fs();
76681 set_fs(get_ds());
76682 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76683 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76684 set_fs(oldfs);
76685 return res;
76686 }
76687 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
76688 index fd7a3f6..a1b1013 100644
76689 --- a/net/ipv4/netfilter/arp_tables.c
76690 +++ b/net/ipv4/netfilter/arp_tables.c
76691 @@ -757,6 +757,9 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
76692
76693 static int copy_entries_to_user(unsigned int total_size,
76694 const struct xt_table *table,
76695 + void __user *userptr) __size_overflow(1);
76696 +static int copy_entries_to_user(unsigned int total_size,
76697 + const struct xt_table *table,
76698 void __user *userptr)
76699 {
76700 unsigned int off, num;
76701 @@ -984,6 +987,11 @@ static int __do_replace(struct net *net, const char *name,
76702 unsigned int valid_hooks,
76703 struct xt_table_info *newinfo,
76704 unsigned int num_counters,
76705 + void __user *counters_ptr) __size_overflow(5);
76706 +static int __do_replace(struct net *net, const char *name,
76707 + unsigned int valid_hooks,
76708 + struct xt_table_info *newinfo,
76709 + unsigned int num_counters,
76710 void __user *counters_ptr)
76711 {
76712 int ret;
76713 @@ -1104,6 +1112,8 @@ static int do_replace(struct net *net, const void __user *user,
76714 }
76715
76716 static int do_add_counters(struct net *net, const void __user *user,
76717 + unsigned int len, int compat) __size_overflow(3);
76718 +static int do_add_counters(struct net *net, const void __user *user,
76719 unsigned int len, int compat)
76720 {
76721 unsigned int i, curcpu;
76722 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
76723 index 24e556e..b073356 100644
76724 --- a/net/ipv4/netfilter/ip_tables.c
76725 +++ b/net/ipv4/netfilter/ip_tables.c
76726 @@ -923,6 +923,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
76727 static int
76728 copy_entries_to_user(unsigned int total_size,
76729 const struct xt_table *table,
76730 + void __user *userptr) __size_overflow(1);
76731 +static int
76732 +copy_entries_to_user(unsigned int total_size,
76733 + const struct xt_table *table,
76734 void __user *userptr)
76735 {
76736 unsigned int off, num;
76737 @@ -1172,6 +1176,10 @@ get_entries(struct net *net, struct ipt_get_entries __user *uptr,
76738 static int
76739 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76740 struct xt_table_info *newinfo, unsigned int num_counters,
76741 + void __user *counters_ptr) __size_overflow(5);
76742 +static int
76743 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
76744 + struct xt_table_info *newinfo, unsigned int num_counters,
76745 void __user *counters_ptr)
76746 {
76747 int ret;
76748 @@ -1293,6 +1301,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
76749
76750 static int
76751 do_add_counters(struct net *net, const void __user *user,
76752 + unsigned int len, int compat) __size_overflow(3);
76753 +static int
76754 +do_add_counters(struct net *net, const void __user *user,
76755 unsigned int len, int compat)
76756 {
76757 unsigned int i, curcpu;
76758 diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
76759 index ba5756d..8d34d74 100644
76760 --- a/net/ipv4/netfilter/ipt_ULOG.c
76761 +++ b/net/ipv4/netfilter/ipt_ULOG.c
76762 @@ -125,6 +125,7 @@ static void ulog_timer(unsigned long data)
76763 spin_unlock_bh(&ulog_lock);
76764 }
76765
76766 +static struct sk_buff *ulog_alloc_skb(unsigned int size) __size_overflow(1);
76767 static struct sk_buff *ulog_alloc_skb(unsigned int size)
76768 {
76769 struct sk_buff *skb;
76770 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
76771 index 2133c30..0e8047e 100644
76772 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
76773 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
76774 @@ -435,6 +435,10 @@ static unsigned char asn1_subid_decode(struct asn1_ctx *ctx,
76775 static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
76776 unsigned char *eoc,
76777 unsigned long **oid,
76778 + unsigned int *len) __size_overflow(2);
76779 +static unsigned char asn1_oid_decode(struct asn1_ctx *ctx,
76780 + unsigned char *eoc,
76781 + unsigned long **oid,
76782 unsigned int *len)
76783 {
76784 unsigned long subid;
76785 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76786 index b072386..abdebcf 100644
76787 --- a/net/ipv4/ping.c
76788 +++ b/net/ipv4/ping.c
76789 @@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76790 sk_rmem_alloc_get(sp),
76791 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76792 atomic_read(&sp->sk_refcnt), sp,
76793 - atomic_read(&sp->sk_drops), len);
76794 + atomic_read_unchecked(&sp->sk_drops), len);
76795 }
76796
76797 static int ping_seq_show(struct seq_file *seq, void *v)
76798 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76799 index 3ccda5a..3c1e61d 100644
76800 --- a/net/ipv4/raw.c
76801 +++ b/net/ipv4/raw.c
76802 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
76803 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76804 {
76805 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76806 - atomic_inc(&sk->sk_drops);
76807 + atomic_inc_unchecked(&sk->sk_drops);
76808 kfree_skb(skb);
76809 return NET_RX_DROP;
76810 }
76811 @@ -742,16 +742,20 @@ static int raw_init(struct sock *sk)
76812
76813 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76814 {
76815 + struct icmp_filter filter;
76816 +
76817 if (optlen > sizeof(struct icmp_filter))
76818 optlen = sizeof(struct icmp_filter);
76819 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76820 + if (copy_from_user(&filter, optval, optlen))
76821 return -EFAULT;
76822 + raw_sk(sk)->filter = filter;
76823 return 0;
76824 }
76825
76826 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76827 {
76828 int len, ret = -EFAULT;
76829 + struct icmp_filter filter;
76830
76831 if (get_user(len, optlen))
76832 goto out;
76833 @@ -761,8 +765,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76834 if (len > sizeof(struct icmp_filter))
76835 len = sizeof(struct icmp_filter);
76836 ret = -EFAULT;
76837 - if (put_user(len, optlen) ||
76838 - copy_to_user(optval, &raw_sk(sk)->filter, len))
76839 + filter = raw_sk(sk)->filter;
76840 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76841 goto out;
76842 ret = 0;
76843 out: return ret;
76844 @@ -990,7 +994,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76845 sk_wmem_alloc_get(sp),
76846 sk_rmem_alloc_get(sp),
76847 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76848 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76849 + atomic_read(&sp->sk_refcnt),
76850 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76851 + NULL,
76852 +#else
76853 + sp,
76854 +#endif
76855 + atomic_read_unchecked(&sp->sk_drops));
76856 }
76857
76858 static int raw_seq_show(struct seq_file *seq, void *v)
76859 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76860 index 0197747..7adb0dc 100644
76861 --- a/net/ipv4/route.c
76862 +++ b/net/ipv4/route.c
76863 @@ -311,7 +311,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76864
76865 static inline int rt_genid(struct net *net)
76866 {
76867 - return atomic_read(&net->ipv4.rt_genid);
76868 + return atomic_read_unchecked(&net->ipv4.rt_genid);
76869 }
76870
76871 #ifdef CONFIG_PROC_FS
76872 @@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
76873 unsigned char shuffle;
76874
76875 get_random_bytes(&shuffle, sizeof(shuffle));
76876 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76877 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76878 inetpeer_invalidate_tree(AF_INET);
76879 }
76880
76881 @@ -3010,7 +3010,7 @@ static int rt_fill_info(struct net *net,
76882 error = rt->dst.error;
76883 if (peer) {
76884 inet_peer_refcheck(rt->peer);
76885 - id = atomic_read(&peer->ip_id_count) & 0xffff;
76886 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76887 if (peer->tcp_ts_stamp) {
76888 ts = peer->tcp_ts;
76889 tsage = get_seconds() - peer->tcp_ts_stamp;
76890 diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
76891 index e2327db..bf29e7c 100644
76892 --- a/net/ipv4/tcp.c
76893 +++ b/net/ipv4/tcp.c
76894 @@ -849,8 +849,7 @@ new_segment:
76895 wait_for_sndbuf:
76896 set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
76897 wait_for_memory:
76898 - if (copied)
76899 - tcp_push(sk, flags & ~MSG_MORE, mss_now, TCP_NAGLE_PUSH);
76900 + tcp_push(sk, flags & ~MSG_MORE, mss_now, TCP_NAGLE_PUSH);
76901
76902 if ((err = sk_stream_wait_memory(sk, &timeo)) != 0)
76903 goto do_error;
76904 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76905 index fd54c5f..96d6407 100644
76906 --- a/net/ipv4/tcp_ipv4.c
76907 +++ b/net/ipv4/tcp_ipv4.c
76908 @@ -88,6 +88,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
76909 int sysctl_tcp_low_latency __read_mostly;
76910 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76911
76912 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76913 +extern int grsec_enable_blackhole;
76914 +#endif
76915
76916 #ifdef CONFIG_TCP_MD5SIG
76917 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
76918 @@ -1638,6 +1641,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76919 return 0;
76920
76921 reset:
76922 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76923 + if (!grsec_enable_blackhole)
76924 +#endif
76925 tcp_v4_send_reset(rsk, skb);
76926 discard:
76927 kfree_skb(skb);
76928 @@ -1700,12 +1706,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76929 TCP_SKB_CB(skb)->sacked = 0;
76930
76931 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76932 - if (!sk)
76933 + if (!sk) {
76934 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76935 + ret = 1;
76936 +#endif
76937 goto no_tcp_socket;
76938 -
76939 + }
76940 process:
76941 - if (sk->sk_state == TCP_TIME_WAIT)
76942 + if (sk->sk_state == TCP_TIME_WAIT) {
76943 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76944 + ret = 2;
76945 +#endif
76946 goto do_time_wait;
76947 + }
76948
76949 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76950 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76951 @@ -1755,6 +1768,10 @@ no_tcp_socket:
76952 bad_packet:
76953 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76954 } else {
76955 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76956 + if (!grsec_enable_blackhole || (ret == 1 &&
76957 + (skb->dev->flags & IFF_LOOPBACK)))
76958 +#endif
76959 tcp_v4_send_reset(NULL, skb);
76960 }
76961
76962 @@ -2417,7 +2434,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76963 0, /* non standard timer */
76964 0, /* open_requests have no inode */
76965 atomic_read(&sk->sk_refcnt),
76966 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76967 + NULL,
76968 +#else
76969 req,
76970 +#endif
76971 len);
76972 }
76973
76974 @@ -2467,7 +2488,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76975 sock_i_uid(sk),
76976 icsk->icsk_probes_out,
76977 sock_i_ino(sk),
76978 - atomic_read(&sk->sk_refcnt), sk,
76979 + atomic_read(&sk->sk_refcnt),
76980 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76981 + NULL,
76982 +#else
76983 + sk,
76984 +#endif
76985 jiffies_to_clock_t(icsk->icsk_rto),
76986 jiffies_to_clock_t(icsk->icsk_ack.ato),
76987 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76988 @@ -2495,7 +2521,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76989 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76990 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76991 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76992 - atomic_read(&tw->tw_refcnt), tw, len);
76993 + atomic_read(&tw->tw_refcnt),
76994 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76995 + NULL,
76996 +#else
76997 + tw,
76998 +#endif
76999 + len);
77000 }
77001
77002 #define TMPSZ 150
77003 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77004 index 550e755..25721b3 100644
77005 --- a/net/ipv4/tcp_minisocks.c
77006 +++ b/net/ipv4/tcp_minisocks.c
77007 @@ -27,6 +27,10 @@
77008 #include <net/inet_common.h>
77009 #include <net/xfrm.h>
77010
77011 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77012 +extern int grsec_enable_blackhole;
77013 +#endif
77014 +
77015 int sysctl_tcp_syncookies __read_mostly = 1;
77016 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77017
77018 @@ -753,6 +757,10 @@ listen_overflow:
77019
77020 embryonic_reset:
77021 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77022 +
77023 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77024 + if (!grsec_enable_blackhole)
77025 +#endif
77026 if (!(flg & TCP_FLAG_RST))
77027 req->rsk_ops->send_reset(sk, skb);
77028
77029 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77030 index 85ee7eb..53277ab 100644
77031 --- a/net/ipv4/tcp_probe.c
77032 +++ b/net/ipv4/tcp_probe.c
77033 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77034 if (cnt + width >= len)
77035 break;
77036
77037 - if (copy_to_user(buf + cnt, tbuf, width))
77038 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77039 return -EFAULT;
77040 cnt += width;
77041 }
77042 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77043 index cd2e072..1fffee2 100644
77044 --- a/net/ipv4/tcp_timer.c
77045 +++ b/net/ipv4/tcp_timer.c
77046 @@ -22,6 +22,10 @@
77047 #include <linux/gfp.h>
77048 #include <net/tcp.h>
77049
77050 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77051 +extern int grsec_lastack_retries;
77052 +#endif
77053 +
77054 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77055 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77056 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77057 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
77058 }
77059 }
77060
77061 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77062 + if ((sk->sk_state == TCP_LAST_ACK) &&
77063 + (grsec_lastack_retries > 0) &&
77064 + (grsec_lastack_retries < retry_until))
77065 + retry_until = grsec_lastack_retries;
77066 +#endif
77067 +
77068 if (retransmits_timed_out(sk, retry_until,
77069 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77070 /* Has it gone just too far? */
77071 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77072 index 5d075b5..d907d5f 100644
77073 --- a/net/ipv4/udp.c
77074 +++ b/net/ipv4/udp.c
77075 @@ -86,6 +86,7 @@
77076 #include <linux/types.h>
77077 #include <linux/fcntl.h>
77078 #include <linux/module.h>
77079 +#include <linux/security.h>
77080 #include <linux/socket.h>
77081 #include <linux/sockios.h>
77082 #include <linux/igmp.h>
77083 @@ -108,6 +109,10 @@
77084 #include <trace/events/udp.h>
77085 #include "udp_impl.h"
77086
77087 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77088 +extern int grsec_enable_blackhole;
77089 +#endif
77090 +
77091 struct udp_table udp_table __read_mostly;
77092 EXPORT_SYMBOL(udp_table);
77093
77094 @@ -566,6 +571,9 @@ found:
77095 return s;
77096 }
77097
77098 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77099 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77100 +
77101 /*
77102 * This routine is called by the ICMP module when it gets some
77103 * sort of error condition. If err < 0 then the socket should
77104 @@ -857,9 +865,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77105 dport = usin->sin_port;
77106 if (dport == 0)
77107 return -EINVAL;
77108 +
77109 + err = gr_search_udp_sendmsg(sk, usin);
77110 + if (err)
77111 + return err;
77112 } else {
77113 if (sk->sk_state != TCP_ESTABLISHED)
77114 return -EDESTADDRREQ;
77115 +
77116 + err = gr_search_udp_sendmsg(sk, NULL);
77117 + if (err)
77118 + return err;
77119 +
77120 daddr = inet->inet_daddr;
77121 dport = inet->inet_dport;
77122 /* Open fast path for connected socket.
77123 @@ -1100,7 +1117,7 @@ static unsigned int first_packet_length(struct sock *sk)
77124 udp_lib_checksum_complete(skb)) {
77125 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77126 IS_UDPLITE(sk));
77127 - atomic_inc(&sk->sk_drops);
77128 + atomic_inc_unchecked(&sk->sk_drops);
77129 __skb_unlink(skb, rcvq);
77130 __skb_queue_tail(&list_kill, skb);
77131 }
77132 @@ -1186,6 +1203,10 @@ try_again:
77133 if (!skb)
77134 goto out;
77135
77136 + err = gr_search_udp_recvmsg(sk, skb);
77137 + if (err)
77138 + goto out_free;
77139 +
77140 ulen = skb->len - sizeof(struct udphdr);
77141 copied = len;
77142 if (copied > ulen)
77143 @@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77144
77145 drop:
77146 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77147 - atomic_inc(&sk->sk_drops);
77148 + atomic_inc_unchecked(&sk->sk_drops);
77149 kfree_skb(skb);
77150 return -1;
77151 }
77152 @@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77153 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77154
77155 if (!skb1) {
77156 - atomic_inc(&sk->sk_drops);
77157 + atomic_inc_unchecked(&sk->sk_drops);
77158 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77159 IS_UDPLITE(sk));
77160 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77161 @@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77162 goto csum_error;
77163
77164 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77165 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77166 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77167 +#endif
77168 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77169
77170 /*
77171 @@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77172 sk_wmem_alloc_get(sp),
77173 sk_rmem_alloc_get(sp),
77174 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77175 - atomic_read(&sp->sk_refcnt), sp,
77176 - atomic_read(&sp->sk_drops), len);
77177 + atomic_read(&sp->sk_refcnt),
77178 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77179 + NULL,
77180 +#else
77181 + sp,
77182 +#endif
77183 + atomic_read_unchecked(&sp->sk_drops), len);
77184 }
77185
77186 int udp4_seq_show(struct seq_file *seq, void *v)
77187 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77188 index 6b8ebc5..1d624f4 100644
77189 --- a/net/ipv6/addrconf.c
77190 +++ b/net/ipv6/addrconf.c
77191 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77192 p.iph.ihl = 5;
77193 p.iph.protocol = IPPROTO_IPV6;
77194 p.iph.ttl = 64;
77195 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77196 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77197
77198 if (ops->ndo_do_ioctl) {
77199 mm_segment_t oldfs = get_fs();
77200 diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c
77201 index 2ae79db..8f101bf 100644
77202 --- a/net/ipv6/ah6.c
77203 +++ b/net/ipv6/ah6.c
77204 @@ -56,6 +56,8 @@ struct ah_skb_cb {
77205 #define AH_SKB_CB(__skb) ((struct ah_skb_cb *)&((__skb)->cb[0]))
77206
77207 static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
77208 + unsigned int size) __size_overflow(3);
77209 +static void *ah_alloc_tmp(struct crypto_ahash *ahash, int nfrags,
77210 unsigned int size)
77211 {
77212 unsigned int len;
77213 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
77214 index 02dd203..e03fcc9 100644
77215 --- a/net/ipv6/inet6_connection_sock.c
77216 +++ b/net/ipv6/inet6_connection_sock.c
77217 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
77218 #ifdef CONFIG_XFRM
77219 {
77220 struct rt6_info *rt = (struct rt6_info *)dst;
77221 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
77222 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
77223 }
77224 #endif
77225 }
77226 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
77227 #ifdef CONFIG_XFRM
77228 if (dst) {
77229 struct rt6_info *rt = (struct rt6_info *)dst;
77230 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
77231 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
77232 __sk_dst_reset(sk);
77233 dst = NULL;
77234 }
77235 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77236 index 18a2719..779f36a 100644
77237 --- a/net/ipv6/ipv6_sockglue.c
77238 +++ b/net/ipv6/ipv6_sockglue.c
77239 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77240 if (sk->sk_type != SOCK_STREAM)
77241 return -ENOPROTOOPT;
77242
77243 - msg.msg_control = optval;
77244 + msg.msg_control = (void __force_kernel *)optval;
77245 msg.msg_controllen = len;
77246 msg.msg_flags = flags;
77247
77248 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77249 index 94874b0..108a94d 100644
77250 --- a/net/ipv6/netfilter/ip6_tables.c
77251 +++ b/net/ipv6/netfilter/ip6_tables.c
77252 @@ -945,6 +945,10 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
77253 static int
77254 copy_entries_to_user(unsigned int total_size,
77255 const struct xt_table *table,
77256 + void __user *userptr) __size_overflow(1);
77257 +static int
77258 +copy_entries_to_user(unsigned int total_size,
77259 + const struct xt_table *table,
77260 void __user *userptr)
77261 {
77262 unsigned int off, num;
77263 @@ -1194,6 +1198,10 @@ get_entries(struct net *net, struct ip6t_get_entries __user *uptr,
77264 static int
77265 __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
77266 struct xt_table_info *newinfo, unsigned int num_counters,
77267 + void __user *counters_ptr) __size_overflow(5);
77268 +static int
77269 +__do_replace(struct net *net, const char *name, unsigned int valid_hooks,
77270 + struct xt_table_info *newinfo, unsigned int num_counters,
77271 void __user *counters_ptr)
77272 {
77273 int ret;
77274 @@ -1315,6 +1323,9 @@ do_replace(struct net *net, const void __user *user, unsigned int len)
77275
77276 static int
77277 do_add_counters(struct net *net, const void __user *user, unsigned int len,
77278 + int compat) __size_overflow(3);
77279 +static int
77280 +do_add_counters(struct net *net, const void __user *user, unsigned int len,
77281 int compat)
77282 {
77283 unsigned int i, curcpu;
77284 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77285 index d02f7e4..2d2a0f1 100644
77286 --- a/net/ipv6/raw.c
77287 +++ b/net/ipv6/raw.c
77288 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77289 {
77290 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77291 skb_checksum_complete(skb)) {
77292 - atomic_inc(&sk->sk_drops);
77293 + atomic_inc_unchecked(&sk->sk_drops);
77294 kfree_skb(skb);
77295 return NET_RX_DROP;
77296 }
77297 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77298 struct raw6_sock *rp = raw6_sk(sk);
77299
77300 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77301 - atomic_inc(&sk->sk_drops);
77302 + atomic_inc_unchecked(&sk->sk_drops);
77303 kfree_skb(skb);
77304 return NET_RX_DROP;
77305 }
77306 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77307
77308 if (inet->hdrincl) {
77309 if (skb_checksum_complete(skb)) {
77310 - atomic_inc(&sk->sk_drops);
77311 + atomic_inc_unchecked(&sk->sk_drops);
77312 kfree_skb(skb);
77313 return NET_RX_DROP;
77314 }
77315 @@ -602,7 +602,7 @@ out:
77316 return err;
77317 }
77318
77319 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77320 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77321 struct flowi6 *fl6, struct dst_entry **dstp,
77322 unsigned int flags)
77323 {
77324 @@ -912,12 +912,15 @@ do_confirm:
77325 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77326 char __user *optval, int optlen)
77327 {
77328 + struct icmp6_filter filter;
77329 +
77330 switch (optname) {
77331 case ICMPV6_FILTER:
77332 if (optlen > sizeof(struct icmp6_filter))
77333 optlen = sizeof(struct icmp6_filter);
77334 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77335 + if (copy_from_user(&filter, optval, optlen))
77336 return -EFAULT;
77337 + raw6_sk(sk)->filter = filter;
77338 return 0;
77339 default:
77340 return -ENOPROTOOPT;
77341 @@ -930,6 +933,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77342 char __user *optval, int __user *optlen)
77343 {
77344 int len;
77345 + struct icmp6_filter filter;
77346
77347 switch (optname) {
77348 case ICMPV6_FILTER:
77349 @@ -941,7 +945,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77350 len = sizeof(struct icmp6_filter);
77351 if (put_user(len, optlen))
77352 return -EFAULT;
77353 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77354 + filter = raw6_sk(sk)->filter;
77355 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77356 return -EFAULT;
77357 return 0;
77358 default:
77359 @@ -1248,7 +1253,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77360 0, 0L, 0,
77361 sock_i_uid(sp), 0,
77362 sock_i_ino(sp),
77363 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77364 + atomic_read(&sp->sk_refcnt),
77365 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77366 + NULL,
77367 +#else
77368 + sp,
77369 +#endif
77370 + atomic_read_unchecked(&sp->sk_drops));
77371 }
77372
77373 static int raw6_seq_show(struct seq_file *seq, void *v)
77374 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77375 index a89ca8d..12e66b0 100644
77376 --- a/net/ipv6/tcp_ipv6.c
77377 +++ b/net/ipv6/tcp_ipv6.c
77378 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
77379 }
77380 #endif
77381
77382 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77383 +extern int grsec_enable_blackhole;
77384 +#endif
77385 +
77386 static void tcp_v6_hash(struct sock *sk)
77387 {
77388 if (sk->sk_state != TCP_CLOSE) {
77389 @@ -1654,6 +1658,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77390 return 0;
77391
77392 reset:
77393 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77394 + if (!grsec_enable_blackhole)
77395 +#endif
77396 tcp_v6_send_reset(sk, skb);
77397 discard:
77398 if (opt_skb)
77399 @@ -1733,12 +1740,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77400 TCP_SKB_CB(skb)->sacked = 0;
77401
77402 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77403 - if (!sk)
77404 + if (!sk) {
77405 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77406 + ret = 1;
77407 +#endif
77408 goto no_tcp_socket;
77409 + }
77410
77411 process:
77412 - if (sk->sk_state == TCP_TIME_WAIT)
77413 + if (sk->sk_state == TCP_TIME_WAIT) {
77414 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77415 + ret = 2;
77416 +#endif
77417 goto do_time_wait;
77418 + }
77419
77420 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77421 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77422 @@ -1786,6 +1801,10 @@ no_tcp_socket:
77423 bad_packet:
77424 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77425 } else {
77426 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77427 + if (!grsec_enable_blackhole || (ret == 1 &&
77428 + (skb->dev->flags & IFF_LOOPBACK)))
77429 +#endif
77430 tcp_v6_send_reset(NULL, skb);
77431 }
77432
77433 @@ -2047,7 +2066,13 @@ static void get_openreq6(struct seq_file *seq,
77434 uid,
77435 0, /* non standard timer */
77436 0, /* open_requests have no inode */
77437 - 0, req);
77438 + 0,
77439 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77440 + NULL
77441 +#else
77442 + req
77443 +#endif
77444 + );
77445 }
77446
77447 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77448 @@ -2097,7 +2122,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77449 sock_i_uid(sp),
77450 icsk->icsk_probes_out,
77451 sock_i_ino(sp),
77452 - atomic_read(&sp->sk_refcnt), sp,
77453 + atomic_read(&sp->sk_refcnt),
77454 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77455 + NULL,
77456 +#else
77457 + sp,
77458 +#endif
77459 jiffies_to_clock_t(icsk->icsk_rto),
77460 jiffies_to_clock_t(icsk->icsk_ack.ato),
77461 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77462 @@ -2132,7 +2162,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77463 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77464 tw->tw_substate, 0, 0,
77465 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77466 - atomic_read(&tw->tw_refcnt), tw);
77467 + atomic_read(&tw->tw_refcnt),
77468 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77469 + NULL
77470 +#else
77471 + tw
77472 +#endif
77473 + );
77474 }
77475
77476 static int tcp6_seq_show(struct seq_file *seq, void *v)
77477 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77478 index 4f96b5c..75543d7 100644
77479 --- a/net/ipv6/udp.c
77480 +++ b/net/ipv6/udp.c
77481 @@ -50,6 +50,10 @@
77482 #include <linux/seq_file.h>
77483 #include "udp_impl.h"
77484
77485 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77486 +extern int grsec_enable_blackhole;
77487 +#endif
77488 +
77489 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77490 {
77491 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77492 @@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
77493
77494 return 0;
77495 drop:
77496 - atomic_inc(&sk->sk_drops);
77497 + atomic_inc_unchecked(&sk->sk_drops);
77498 drop_no_sk_drops_inc:
77499 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77500 kfree_skb(skb);
77501 @@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77502 continue;
77503 }
77504 drop:
77505 - atomic_inc(&sk->sk_drops);
77506 + atomic_inc_unchecked(&sk->sk_drops);
77507 UDP6_INC_STATS_BH(sock_net(sk),
77508 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
77509 UDP6_INC_STATS_BH(sock_net(sk),
77510 @@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77511 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
77512 proto == IPPROTO_UDPLITE);
77513
77514 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77515 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77516 +#endif
77517 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77518
77519 kfree_skb(skb);
77520 @@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77521 if (!sock_owned_by_user(sk))
77522 udpv6_queue_rcv_skb(sk, skb);
77523 else if (sk_add_backlog(sk, skb)) {
77524 - atomic_inc(&sk->sk_drops);
77525 + atomic_inc_unchecked(&sk->sk_drops);
77526 bh_unlock_sock(sk);
77527 sock_put(sk);
77528 goto discard;
77529 @@ -1410,8 +1417,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77530 0, 0L, 0,
77531 sock_i_uid(sp), 0,
77532 sock_i_ino(sp),
77533 - atomic_read(&sp->sk_refcnt), sp,
77534 - atomic_read(&sp->sk_drops));
77535 + atomic_read(&sp->sk_refcnt),
77536 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77537 + NULL,
77538 +#else
77539 + sp,
77540 +#endif
77541 + atomic_read_unchecked(&sp->sk_drops));
77542 }
77543
77544 int udp6_seq_show(struct seq_file *seq, void *v)
77545 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77546 index 253695d..9481ce8 100644
77547 --- a/net/irda/ircomm/ircomm_tty.c
77548 +++ b/net/irda/ircomm/ircomm_tty.c
77549 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77550 add_wait_queue(&self->open_wait, &wait);
77551
77552 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77553 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77554 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77555
77556 /* As far as I can see, we protect open_count - Jean II */
77557 spin_lock_irqsave(&self->spinlock, flags);
77558 if (!tty_hung_up_p(filp)) {
77559 extra_count = 1;
77560 - self->open_count--;
77561 + local_dec(&self->open_count);
77562 }
77563 spin_unlock_irqrestore(&self->spinlock, flags);
77564 - self->blocked_open++;
77565 + local_inc(&self->blocked_open);
77566
77567 while (1) {
77568 if (tty->termios->c_cflag & CBAUD) {
77569 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77570 }
77571
77572 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77573 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77574 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77575
77576 schedule();
77577 }
77578 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77579 if (extra_count) {
77580 /* ++ is not atomic, so this should be protected - Jean II */
77581 spin_lock_irqsave(&self->spinlock, flags);
77582 - self->open_count++;
77583 + local_inc(&self->open_count);
77584 spin_unlock_irqrestore(&self->spinlock, flags);
77585 }
77586 - self->blocked_open--;
77587 + local_dec(&self->blocked_open);
77588
77589 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77590 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77591 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77592
77593 if (!retval)
77594 self->flags |= ASYNC_NORMAL_ACTIVE;
77595 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77596 }
77597 /* ++ is not atomic, so this should be protected - Jean II */
77598 spin_lock_irqsave(&self->spinlock, flags);
77599 - self->open_count++;
77600 + local_inc(&self->open_count);
77601
77602 tty->driver_data = self;
77603 self->tty = tty;
77604 spin_unlock_irqrestore(&self->spinlock, flags);
77605
77606 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77607 - self->line, self->open_count);
77608 + self->line, local_read(&self->open_count));
77609
77610 /* Not really used by us, but lets do it anyway */
77611 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77612 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77613 return;
77614 }
77615
77616 - if ((tty->count == 1) && (self->open_count != 1)) {
77617 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77618 /*
77619 * Uh, oh. tty->count is 1, which means that the tty
77620 * structure will be freed. state->count should always
77621 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77622 */
77623 IRDA_DEBUG(0, "%s(), bad serial port count; "
77624 "tty->count is 1, state->count is %d\n", __func__ ,
77625 - self->open_count);
77626 - self->open_count = 1;
77627 + local_read(&self->open_count));
77628 + local_set(&self->open_count, 1);
77629 }
77630
77631 - if (--self->open_count < 0) {
77632 + if (local_dec_return(&self->open_count) < 0) {
77633 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77634 - __func__, self->line, self->open_count);
77635 - self->open_count = 0;
77636 + __func__, self->line, local_read(&self->open_count));
77637 + local_set(&self->open_count, 0);
77638 }
77639 - if (self->open_count) {
77640 + if (local_read(&self->open_count)) {
77641 spin_unlock_irqrestore(&self->spinlock, flags);
77642
77643 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77644 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77645 tty->closing = 0;
77646 self->tty = NULL;
77647
77648 - if (self->blocked_open) {
77649 + if (local_read(&self->blocked_open)) {
77650 if (self->close_delay)
77651 schedule_timeout_interruptible(self->close_delay);
77652 wake_up_interruptible(&self->open_wait);
77653 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77654 spin_lock_irqsave(&self->spinlock, flags);
77655 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77656 self->tty = NULL;
77657 - self->open_count = 0;
77658 + local_set(&self->open_count, 0);
77659 spin_unlock_irqrestore(&self->spinlock, flags);
77660
77661 wake_up_interruptible(&self->open_wait);
77662 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77663 seq_putc(m, '\n');
77664
77665 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77666 - seq_printf(m, "Open count: %d\n", self->open_count);
77667 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77668 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77669 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77670
77671 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77672 index d5c5b8f..33beff0 100644
77673 --- a/net/iucv/af_iucv.c
77674 +++ b/net/iucv/af_iucv.c
77675 @@ -764,10 +764,10 @@ static int iucv_sock_autobind(struct sock *sk)
77676
77677 write_lock_bh(&iucv_sk_list.lock);
77678
77679 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77680 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77681 while (__iucv_get_sock_by_name(name)) {
77682 sprintf(name, "%08x",
77683 - atomic_inc_return(&iucv_sk_list.autobind_name));
77684 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77685 }
77686
77687 write_unlock_bh(&iucv_sk_list.lock);
77688 diff --git a/net/key/af_key.c b/net/key/af_key.c
77689 index 11dbb22..c20f667 100644
77690 --- a/net/key/af_key.c
77691 +++ b/net/key/af_key.c
77692 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77693 static u32 get_acqseq(void)
77694 {
77695 u32 res;
77696 - static atomic_t acqseq;
77697 + static atomic_unchecked_t acqseq;
77698
77699 do {
77700 - res = atomic_inc_return(&acqseq);
77701 + res = atomic_inc_return_unchecked(&acqseq);
77702 } while (!res);
77703 return res;
77704 }
77705 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77706 index 2f0642d..e5c6fba 100644
77707 --- a/net/mac80211/ieee80211_i.h
77708 +++ b/net/mac80211/ieee80211_i.h
77709 @@ -28,6 +28,7 @@
77710 #include <net/ieee80211_radiotap.h>
77711 #include <net/cfg80211.h>
77712 #include <net/mac80211.h>
77713 +#include <asm/local.h>
77714 #include "key.h"
77715 #include "sta_info.h"
77716
77717 @@ -781,7 +782,7 @@ struct ieee80211_local {
77718 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77719 spinlock_t queue_stop_reason_lock;
77720
77721 - int open_count;
77722 + local_t open_count;
77723 int monitors, cooked_mntrs;
77724 /* number of interfaces with corresponding FIF_ flags */
77725 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77726 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77727 index 8e2137b..2974283 100644
77728 --- a/net/mac80211/iface.c
77729 +++ b/net/mac80211/iface.c
77730 @@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77731 break;
77732 }
77733
77734 - if (local->open_count == 0) {
77735 + if (local_read(&local->open_count) == 0) {
77736 res = drv_start(local);
77737 if (res)
77738 goto err_del_bss;
77739 @@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77740 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
77741
77742 if (!is_valid_ether_addr(dev->dev_addr)) {
77743 - if (!local->open_count)
77744 + if (!local_read(&local->open_count))
77745 drv_stop(local);
77746 return -EADDRNOTAVAIL;
77747 }
77748 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77749 mutex_unlock(&local->mtx);
77750
77751 if (coming_up)
77752 - local->open_count++;
77753 + local_inc(&local->open_count);
77754
77755 if (hw_reconf_flags)
77756 ieee80211_hw_config(local, hw_reconf_flags);
77757 @@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77758 err_del_interface:
77759 drv_remove_interface(local, sdata);
77760 err_stop:
77761 - if (!local->open_count)
77762 + if (!local_read(&local->open_count))
77763 drv_stop(local);
77764 err_del_bss:
77765 sdata->bss = NULL;
77766 @@ -489,7 +489,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77767 }
77768
77769 if (going_down)
77770 - local->open_count--;
77771 + local_dec(&local->open_count);
77772
77773 switch (sdata->vif.type) {
77774 case NL80211_IFTYPE_AP_VLAN:
77775 @@ -548,7 +548,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77776
77777 ieee80211_recalc_ps(local, -1);
77778
77779 - if (local->open_count == 0) {
77780 + if (local_read(&local->open_count) == 0) {
77781 if (local->ops->napi_poll)
77782 napi_disable(&local->napi);
77783 ieee80211_clear_tx_pending(local);
77784 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77785 index b142bd4..a651749 100644
77786 --- a/net/mac80211/main.c
77787 +++ b/net/mac80211/main.c
77788 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77789 local->hw.conf.power_level = power;
77790 }
77791
77792 - if (changed && local->open_count) {
77793 + if (changed && local_read(&local->open_count)) {
77794 ret = drv_config(local, changed);
77795 /*
77796 * Goal:
77797 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77798 index 596efaf..8f1911f 100644
77799 --- a/net/mac80211/pm.c
77800 +++ b/net/mac80211/pm.c
77801 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77802 struct ieee80211_sub_if_data *sdata;
77803 struct sta_info *sta;
77804
77805 - if (!local->open_count)
77806 + if (!local_read(&local->open_count))
77807 goto suspend;
77808
77809 ieee80211_scan_cancel(local);
77810 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77811 cancel_work_sync(&local->dynamic_ps_enable_work);
77812 del_timer_sync(&local->dynamic_ps_timer);
77813
77814 - local->wowlan = wowlan && local->open_count;
77815 + local->wowlan = wowlan && local_read(&local->open_count);
77816 if (local->wowlan) {
77817 int err = drv_suspend(local, wowlan);
77818 if (err < 0) {
77819 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77820 }
77821
77822 /* stop hardware - this must stop RX */
77823 - if (local->open_count)
77824 + if (local_read(&local->open_count))
77825 ieee80211_stop_device(local);
77826
77827 suspend:
77828 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77829 index f9b8e81..bb89b46 100644
77830 --- a/net/mac80211/rate.c
77831 +++ b/net/mac80211/rate.c
77832 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77833
77834 ASSERT_RTNL();
77835
77836 - if (local->open_count)
77837 + if (local_read(&local->open_count))
77838 return -EBUSY;
77839
77840 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77841 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77842 index c97a065..ff61928 100644
77843 --- a/net/mac80211/rc80211_pid_debugfs.c
77844 +++ b/net/mac80211/rc80211_pid_debugfs.c
77845 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77846
77847 spin_unlock_irqrestore(&events->lock, status);
77848
77849 - if (copy_to_user(buf, pb, p))
77850 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77851 return -EFAULT;
77852
77853 return p;
77854 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77855 index 9919892..8c49803 100644
77856 --- a/net/mac80211/util.c
77857 +++ b/net/mac80211/util.c
77858 @@ -1143,7 +1143,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77859 }
77860 #endif
77861 /* everything else happens only if HW was up & running */
77862 - if (!local->open_count)
77863 + if (!local_read(&local->open_count))
77864 goto wake_up;
77865
77866 /*
77867 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77868 index f8ac4ef..b02560b 100644
77869 --- a/net/netfilter/Kconfig
77870 +++ b/net/netfilter/Kconfig
77871 @@ -806,6 +806,16 @@ config NETFILTER_XT_MATCH_ESP
77872
77873 To compile it as a module, choose M here. If unsure, say N.
77874
77875 +config NETFILTER_XT_MATCH_GRADM
77876 + tristate '"gradm" match support'
77877 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77878 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77879 + ---help---
77880 + The gradm match allows to match on grsecurity RBAC being enabled.
77881 + It is useful when iptables rules are applied early on bootup to
77882 + prevent connections to the machine (except from a trusted host)
77883 + while the RBAC system is disabled.
77884 +
77885 config NETFILTER_XT_MATCH_HASHLIMIT
77886 tristate '"hashlimit" match support'
77887 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77888 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77889 index 40f4c3d..0d5dd6b 100644
77890 --- a/net/netfilter/Makefile
77891 +++ b/net/netfilter/Makefile
77892 @@ -83,6 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77893 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77894 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
77895 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77896 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77897 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77898 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77899 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77900 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77901 index 29fa5ba..8debc79 100644
77902 --- a/net/netfilter/ipvs/ip_vs_conn.c
77903 +++ b/net/netfilter/ipvs/ip_vs_conn.c
77904 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77905 /* Increase the refcnt counter of the dest */
77906 atomic_inc(&dest->refcnt);
77907
77908 - conn_flags = atomic_read(&dest->conn_flags);
77909 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
77910 if (cp->protocol != IPPROTO_UDP)
77911 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77912 /* Bind with the destination and its corresponding transmitter */
77913 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77914 atomic_set(&cp->refcnt, 1);
77915
77916 atomic_set(&cp->n_control, 0);
77917 - atomic_set(&cp->in_pkts, 0);
77918 + atomic_set_unchecked(&cp->in_pkts, 0);
77919
77920 atomic_inc(&ipvs->conn_count);
77921 if (flags & IP_VS_CONN_F_NO_CPORT)
77922 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77923
77924 /* Don't drop the entry if its number of incoming packets is not
77925 located in [0, 8] */
77926 - i = atomic_read(&cp->in_pkts);
77927 + i = atomic_read_unchecked(&cp->in_pkts);
77928 if (i > 8 || i < 0) return 0;
77929
77930 if (!todrop_rate[i]) return 0;
77931 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77932 index 2555816..31492d9 100644
77933 --- a/net/netfilter/ipvs/ip_vs_core.c
77934 +++ b/net/netfilter/ipvs/ip_vs_core.c
77935 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77936 ret = cp->packet_xmit(skb, cp, pd->pp);
77937 /* do not touch skb anymore */
77938
77939 - atomic_inc(&cp->in_pkts);
77940 + atomic_inc_unchecked(&cp->in_pkts);
77941 ip_vs_conn_put(cp);
77942 return ret;
77943 }
77944 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77945 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77946 pkts = sysctl_sync_threshold(ipvs);
77947 else
77948 - pkts = atomic_add_return(1, &cp->in_pkts);
77949 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77950
77951 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
77952 cp->protocol == IPPROTO_SCTP) {
77953 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77954 index b3afe18..08ec940 100644
77955 --- a/net/netfilter/ipvs/ip_vs_ctl.c
77956 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
77957 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77958 ip_vs_rs_hash(ipvs, dest);
77959 write_unlock_bh(&ipvs->rs_lock);
77960 }
77961 - atomic_set(&dest->conn_flags, conn_flags);
77962 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
77963
77964 /* bind the service */
77965 if (!dest->svc) {
77966 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77967 " %-7s %-6d %-10d %-10d\n",
77968 &dest->addr.in6,
77969 ntohs(dest->port),
77970 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77971 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77972 atomic_read(&dest->weight),
77973 atomic_read(&dest->activeconns),
77974 atomic_read(&dest->inactconns));
77975 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77976 "%-7s %-6d %-10d %-10d\n",
77977 ntohl(dest->addr.ip),
77978 ntohs(dest->port),
77979 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77980 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77981 atomic_read(&dest->weight),
77982 atomic_read(&dest->activeconns),
77983 atomic_read(&dest->inactconns));
77984 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77985
77986 entry.addr = dest->addr.ip;
77987 entry.port = dest->port;
77988 - entry.conn_flags = atomic_read(&dest->conn_flags);
77989 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77990 entry.weight = atomic_read(&dest->weight);
77991 entry.u_threshold = dest->u_threshold;
77992 entry.l_threshold = dest->l_threshold;
77993 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77994 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
77995
77996 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77997 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77998 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
77999 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
78000 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
78001 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
78002 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78003 index 8a0d6d6..90ec197 100644
78004 --- a/net/netfilter/ipvs/ip_vs_sync.c
78005 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78006 @@ -649,7 +649,7 @@ control:
78007 * i.e only increment in_pkts for Templates.
78008 */
78009 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
78010 - int pkts = atomic_add_return(1, &cp->in_pkts);
78011 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78012
78013 if (pkts % sysctl_sync_period(ipvs) != 1)
78014 return;
78015 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78016
78017 if (opt)
78018 memcpy(&cp->in_seq, opt, sizeof(*opt));
78019 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78020 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78021 cp->state = state;
78022 cp->old_state = cp->state;
78023 /*
78024 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78025 index 7fd66de..e6fb361 100644
78026 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78027 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78028 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78029 else
78030 rc = NF_ACCEPT;
78031 /* do not touch skb anymore */
78032 - atomic_inc(&cp->in_pkts);
78033 + atomic_inc_unchecked(&cp->in_pkts);
78034 goto out;
78035 }
78036
78037 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78038 else
78039 rc = NF_ACCEPT;
78040 /* do not touch skb anymore */
78041 - atomic_inc(&cp->in_pkts);
78042 + atomic_inc_unchecked(&cp->in_pkts);
78043 goto out;
78044 }
78045
78046 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78047 index 66b2c54..c7884e3 100644
78048 --- a/net/netfilter/nfnetlink_log.c
78049 +++ b/net/netfilter/nfnetlink_log.c
78050 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78051 };
78052
78053 static DEFINE_SPINLOCK(instances_lock);
78054 -static atomic_t global_seq;
78055 +static atomic_unchecked_t global_seq;
78056
78057 #define INSTANCE_BUCKETS 16
78058 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78059 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78060 /* global sequence number */
78061 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
78062 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
78063 - htonl(atomic_inc_return(&global_seq)));
78064 + htonl(atomic_inc_return_unchecked(&global_seq)));
78065
78066 if (data_len) {
78067 struct nlattr *nla;
78068 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78069 new file mode 100644
78070 index 0000000..6905327
78071 --- /dev/null
78072 +++ b/net/netfilter/xt_gradm.c
78073 @@ -0,0 +1,51 @@
78074 +/*
78075 + * gradm match for netfilter
78076 + * Copyright © Zbigniew Krzystolik, 2010
78077 + *
78078 + * This program is free software; you can redistribute it and/or modify
78079 + * it under the terms of the GNU General Public License; either version
78080 + * 2 or 3 as published by the Free Software Foundation.
78081 + */
78082 +#include <linux/module.h>
78083 +#include <linux/moduleparam.h>
78084 +#include <linux/skbuff.h>
78085 +#include <linux/netfilter/x_tables.h>
78086 +#include <linux/grsecurity.h>
78087 +#include <linux/netfilter/xt_gradm.h>
78088 +
78089 +static bool
78090 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78091 +{
78092 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78093 + bool retval = false;
78094 + if (gr_acl_is_enabled())
78095 + retval = true;
78096 + return retval ^ info->invflags;
78097 +}
78098 +
78099 +static struct xt_match gradm_mt_reg __read_mostly = {
78100 + .name = "gradm",
78101 + .revision = 0,
78102 + .family = NFPROTO_UNSPEC,
78103 + .match = gradm_mt,
78104 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78105 + .me = THIS_MODULE,
78106 +};
78107 +
78108 +static int __init gradm_mt_init(void)
78109 +{
78110 + return xt_register_match(&gradm_mt_reg);
78111 +}
78112 +
78113 +static void __exit gradm_mt_exit(void)
78114 +{
78115 + xt_unregister_match(&gradm_mt_reg);
78116 +}
78117 +
78118 +module_init(gradm_mt_init);
78119 +module_exit(gradm_mt_exit);
78120 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78121 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78122 +MODULE_LICENSE("GPL");
78123 +MODULE_ALIAS("ipt_gradm");
78124 +MODULE_ALIAS("ip6t_gradm");
78125 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78126 index 4fe4fb4..87a89e5 100644
78127 --- a/net/netfilter/xt_statistic.c
78128 +++ b/net/netfilter/xt_statistic.c
78129 @@ -19,7 +19,7 @@
78130 #include <linux/module.h>
78131
78132 struct xt_statistic_priv {
78133 - atomic_t count;
78134 + atomic_unchecked_t count;
78135 } ____cacheline_aligned_in_smp;
78136
78137 MODULE_LICENSE("GPL");
78138 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78139 break;
78140 case XT_STATISTIC_MODE_NTH:
78141 do {
78142 - oval = atomic_read(&info->master->count);
78143 + oval = atomic_read_unchecked(&info->master->count);
78144 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78145 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78146 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78147 if (nval == 0)
78148 ret = !ret;
78149 break;
78150 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78151 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78152 if (info->master == NULL)
78153 return -ENOMEM;
78154 - atomic_set(&info->master->count, info->u.nth.count);
78155 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78156
78157 return 0;
78158 }
78159 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78160 index 467af9c..8f415cc 100644
78161 --- a/net/netlink/af_netlink.c
78162 +++ b/net/netlink/af_netlink.c
78163 @@ -741,7 +741,7 @@ static void netlink_overrun(struct sock *sk)
78164 sk->sk_error_report(sk);
78165 }
78166 }
78167 - atomic_inc(&sk->sk_drops);
78168 + atomic_inc_unchecked(&sk->sk_drops);
78169 }
78170
78171 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78172 @@ -1997,7 +1997,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78173 sk_wmem_alloc_get(s),
78174 nlk->cb,
78175 atomic_read(&s->sk_refcnt),
78176 - atomic_read(&s->sk_drops),
78177 + atomic_read_unchecked(&s->sk_drops),
78178 sock_i_ino(s)
78179 );
78180
78181 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78182 index 7dab229..212156f 100644
78183 --- a/net/netrom/af_netrom.c
78184 +++ b/net/netrom/af_netrom.c
78185 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78186 struct sock *sk = sock->sk;
78187 struct nr_sock *nr = nr_sk(sk);
78188
78189 + memset(sax, 0, sizeof(*sax));
78190 lock_sock(sk);
78191 if (peer != 0) {
78192 if (sk->sk_state != TCP_ESTABLISHED) {
78193 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78194 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78195 } else {
78196 sax->fsa_ax25.sax25_family = AF_NETROM;
78197 - sax->fsa_ax25.sax25_ndigis = 0;
78198 sax->fsa_ax25.sax25_call = nr->source_addr;
78199 *uaddr_len = sizeof(struct sockaddr_ax25);
78200 }
78201 diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
78202 index 2c03050..5cf68c1 100644
78203 --- a/net/openvswitch/datapath.c
78204 +++ b/net/openvswitch/datapath.c
78205 @@ -322,7 +322,7 @@ static int queue_userspace_packet(int dp_ifindex, struct sk_buff *skb,
78206 return -ENOMEM;
78207
78208 nskb = __vlan_put_tag(nskb, vlan_tx_tag_get(nskb));
78209 - if (!skb)
78210 + if (!nskb)
78211 return -ENOMEM;
78212
78213 nskb->vlan_tci = 0;
78214 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78215 index 2dbb32b..a1b4722 100644
78216 --- a/net/packet/af_packet.c
78217 +++ b/net/packet/af_packet.c
78218 @@ -1676,7 +1676,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78219
78220 spin_lock(&sk->sk_receive_queue.lock);
78221 po->stats.tp_packets++;
78222 - skb->dropcount = atomic_read(&sk->sk_drops);
78223 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78224 __skb_queue_tail(&sk->sk_receive_queue, skb);
78225 spin_unlock(&sk->sk_receive_queue.lock);
78226 sk->sk_data_ready(sk, skb->len);
78227 @@ -1685,7 +1685,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78228 drop_n_acct:
78229 spin_lock(&sk->sk_receive_queue.lock);
78230 po->stats.tp_drops++;
78231 - atomic_inc(&sk->sk_drops);
78232 + atomic_inc_unchecked(&sk->sk_drops);
78233 spin_unlock(&sk->sk_receive_queue.lock);
78234
78235 drop_n_restore:
78236 @@ -3271,7 +3271,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78237 case PACKET_HDRLEN:
78238 if (len > sizeof(int))
78239 len = sizeof(int);
78240 - if (copy_from_user(&val, optval, len))
78241 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78242 return -EFAULT;
78243 switch (val) {
78244 case TPACKET_V1:
78245 @@ -3321,7 +3321,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78246
78247 if (put_user(len, optlen))
78248 return -EFAULT;
78249 - if (copy_to_user(optval, data, len))
78250 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78251 return -EFAULT;
78252 return 0;
78253 }
78254 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78255 index d65f699..05aa6ce 100644
78256 --- a/net/phonet/af_phonet.c
78257 +++ b/net/phonet/af_phonet.c
78258 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78259 {
78260 struct phonet_protocol *pp;
78261
78262 - if (protocol >= PHONET_NPROTO)
78263 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78264 return NULL;
78265
78266 rcu_read_lock();
78267 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78268 {
78269 int err = 0;
78270
78271 - if (protocol >= PHONET_NPROTO)
78272 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78273 return -EINVAL;
78274
78275 err = proto_register(pp->prot, 1);
78276 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78277 index 9726fe6..fc4e3a4 100644
78278 --- a/net/phonet/pep.c
78279 +++ b/net/phonet/pep.c
78280 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78281
78282 case PNS_PEP_CTRL_REQ:
78283 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78284 - atomic_inc(&sk->sk_drops);
78285 + atomic_inc_unchecked(&sk->sk_drops);
78286 break;
78287 }
78288 __skb_pull(skb, 4);
78289 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78290 }
78291
78292 if (pn->rx_credits == 0) {
78293 - atomic_inc(&sk->sk_drops);
78294 + atomic_inc_unchecked(&sk->sk_drops);
78295 err = -ENOBUFS;
78296 break;
78297 }
78298 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78299 }
78300
78301 if (pn->rx_credits == 0) {
78302 - atomic_inc(&sk->sk_drops);
78303 + atomic_inc_unchecked(&sk->sk_drops);
78304 err = NET_RX_DROP;
78305 break;
78306 }
78307 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78308 index 4c7eff3..59c727f 100644
78309 --- a/net/phonet/socket.c
78310 +++ b/net/phonet/socket.c
78311 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78312 pn->resource, sk->sk_state,
78313 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78314 sock_i_uid(sk), sock_i_ino(sk),
78315 - atomic_read(&sk->sk_refcnt), sk,
78316 - atomic_read(&sk->sk_drops), &len);
78317 + atomic_read(&sk->sk_refcnt),
78318 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78319 + NULL,
78320 +#else
78321 + sk,
78322 +#endif
78323 + atomic_read_unchecked(&sk->sk_drops), &len);
78324 }
78325 seq_printf(seq, "%*s\n", 127 - len, "");
78326 return 0;
78327 diff --git a/net/rds/cong.c b/net/rds/cong.c
78328 index e5b65ac..f3b6fb7 100644
78329 --- a/net/rds/cong.c
78330 +++ b/net/rds/cong.c
78331 @@ -78,7 +78,7 @@
78332 * finds that the saved generation number is smaller than the global generation
78333 * number, it wakes up the process.
78334 */
78335 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78336 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78337
78338 /*
78339 * Congestion monitoring
78340 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78341 rdsdebug("waking map %p for %pI4\n",
78342 map, &map->m_addr);
78343 rds_stats_inc(s_cong_update_received);
78344 - atomic_inc(&rds_cong_generation);
78345 + atomic_inc_unchecked(&rds_cong_generation);
78346 if (waitqueue_active(&map->m_waitq))
78347 wake_up(&map->m_waitq);
78348 if (waitqueue_active(&rds_poll_waitq))
78349 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78350
78351 int rds_cong_updated_since(unsigned long *recent)
78352 {
78353 - unsigned long gen = atomic_read(&rds_cong_generation);
78354 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78355
78356 if (likely(*recent == gen))
78357 return 0;
78358 diff --git a/net/rds/ib.h b/net/rds/ib.h
78359 index edfaaaf..8c89879 100644
78360 --- a/net/rds/ib.h
78361 +++ b/net/rds/ib.h
78362 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78363 /* sending acks */
78364 unsigned long i_ack_flags;
78365 #ifdef KERNEL_HAS_ATOMIC64
78366 - atomic64_t i_ack_next; /* next ACK to send */
78367 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78368 #else
78369 spinlock_t i_ack_lock; /* protect i_ack_next */
78370 u64 i_ack_next; /* next ACK to send */
78371 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78372 index 51c8689..36c555f 100644
78373 --- a/net/rds/ib_cm.c
78374 +++ b/net/rds/ib_cm.c
78375 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78376 /* Clear the ACK state */
78377 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78378 #ifdef KERNEL_HAS_ATOMIC64
78379 - atomic64_set(&ic->i_ack_next, 0);
78380 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78381 #else
78382 ic->i_ack_next = 0;
78383 #endif
78384 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78385 index e29e0ca..fa3a6a3 100644
78386 --- a/net/rds/ib_recv.c
78387 +++ b/net/rds/ib_recv.c
78388 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78389 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78390 int ack_required)
78391 {
78392 - atomic64_set(&ic->i_ack_next, seq);
78393 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78394 if (ack_required) {
78395 smp_mb__before_clear_bit();
78396 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78397 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78398 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78399 smp_mb__after_clear_bit();
78400
78401 - return atomic64_read(&ic->i_ack_next);
78402 + return atomic64_read_unchecked(&ic->i_ack_next);
78403 }
78404 #endif
78405
78406 diff --git a/net/rds/iw.h b/net/rds/iw.h
78407 index 04ce3b1..48119a6 100644
78408 --- a/net/rds/iw.h
78409 +++ b/net/rds/iw.h
78410 @@ -134,7 +134,7 @@ struct rds_iw_connection {
78411 /* sending acks */
78412 unsigned long i_ack_flags;
78413 #ifdef KERNEL_HAS_ATOMIC64
78414 - atomic64_t i_ack_next; /* next ACK to send */
78415 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78416 #else
78417 spinlock_t i_ack_lock; /* protect i_ack_next */
78418 u64 i_ack_next; /* next ACK to send */
78419 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
78420 index 9556d28..f046d0e 100644
78421 --- a/net/rds/iw_cm.c
78422 +++ b/net/rds/iw_cm.c
78423 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
78424 /* Clear the ACK state */
78425 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78426 #ifdef KERNEL_HAS_ATOMIC64
78427 - atomic64_set(&ic->i_ack_next, 0);
78428 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78429 #else
78430 ic->i_ack_next = 0;
78431 #endif
78432 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
78433 index 5e57347..3916042 100644
78434 --- a/net/rds/iw_recv.c
78435 +++ b/net/rds/iw_recv.c
78436 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78437 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
78438 int ack_required)
78439 {
78440 - atomic64_set(&ic->i_ack_next, seq);
78441 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78442 if (ack_required) {
78443 smp_mb__before_clear_bit();
78444 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78445 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78446 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78447 smp_mb__after_clear_bit();
78448
78449 - return atomic64_read(&ic->i_ack_next);
78450 + return atomic64_read_unchecked(&ic->i_ack_next);
78451 }
78452 #endif
78453
78454 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
78455 index edac9ef..16bcb98 100644
78456 --- a/net/rds/tcp.c
78457 +++ b/net/rds/tcp.c
78458 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
78459 int val = 1;
78460
78461 set_fs(KERNEL_DS);
78462 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
78463 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
78464 sizeof(val));
78465 set_fs(oldfs);
78466 }
78467 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
78468 index 1b4fd68..2234175 100644
78469 --- a/net/rds/tcp_send.c
78470 +++ b/net/rds/tcp_send.c
78471 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
78472
78473 oldfs = get_fs();
78474 set_fs(KERNEL_DS);
78475 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
78476 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
78477 sizeof(val));
78478 set_fs(oldfs);
78479 }
78480 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
78481 index 74c064c..fdec26f 100644
78482 --- a/net/rxrpc/af_rxrpc.c
78483 +++ b/net/rxrpc/af_rxrpc.c
78484 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
78485 __be32 rxrpc_epoch;
78486
78487 /* current debugging ID */
78488 -atomic_t rxrpc_debug_id;
78489 +atomic_unchecked_t rxrpc_debug_id;
78490
78491 /* count of skbs currently in use */
78492 atomic_t rxrpc_n_skbs;
78493 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
78494 index c3126e8..21facc7 100644
78495 --- a/net/rxrpc/ar-ack.c
78496 +++ b/net/rxrpc/ar-ack.c
78497 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78498
78499 _enter("{%d,%d,%d,%d},",
78500 call->acks_hard, call->acks_unacked,
78501 - atomic_read(&call->sequence),
78502 + atomic_read_unchecked(&call->sequence),
78503 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
78504
78505 stop = 0;
78506 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78507
78508 /* each Tx packet has a new serial number */
78509 sp->hdr.serial =
78510 - htonl(atomic_inc_return(&call->conn->serial));
78511 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
78512
78513 hdr = (struct rxrpc_header *) txb->head;
78514 hdr->serial = sp->hdr.serial;
78515 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
78516 */
78517 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
78518 {
78519 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
78520 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
78521 }
78522
78523 /*
78524 @@ -629,7 +629,7 @@ process_further:
78525
78526 latest = ntohl(sp->hdr.serial);
78527 hard = ntohl(ack.firstPacket);
78528 - tx = atomic_read(&call->sequence);
78529 + tx = atomic_read_unchecked(&call->sequence);
78530
78531 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78532 latest,
78533 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
78534 goto maybe_reschedule;
78535
78536 send_ACK_with_skew:
78537 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
78538 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
78539 ntohl(ack.serial));
78540 send_ACK:
78541 mtu = call->conn->trans->peer->if_mtu;
78542 @@ -1173,7 +1173,7 @@ send_ACK:
78543 ackinfo.rxMTU = htonl(5692);
78544 ackinfo.jumbo_max = htonl(4);
78545
78546 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78547 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78548 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78549 ntohl(hdr.serial),
78550 ntohs(ack.maxSkew),
78551 @@ -1191,7 +1191,7 @@ send_ACK:
78552 send_message:
78553 _debug("send message");
78554
78555 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78556 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78557 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78558 send_message_2:
78559
78560 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
78561 index bf656c2..48f9d27 100644
78562 --- a/net/rxrpc/ar-call.c
78563 +++ b/net/rxrpc/ar-call.c
78564 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
78565 spin_lock_init(&call->lock);
78566 rwlock_init(&call->state_lock);
78567 atomic_set(&call->usage, 1);
78568 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78569 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78570 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78571
78572 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78573 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
78574 index 4106ca9..a338d7a 100644
78575 --- a/net/rxrpc/ar-connection.c
78576 +++ b/net/rxrpc/ar-connection.c
78577 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
78578 rwlock_init(&conn->lock);
78579 spin_lock_init(&conn->state_lock);
78580 atomic_set(&conn->usage, 1);
78581 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78582 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78583 conn->avail_calls = RXRPC_MAXCALLS;
78584 conn->size_align = 4;
78585 conn->header_size = sizeof(struct rxrpc_header);
78586 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
78587 index e7ed43a..6afa140 100644
78588 --- a/net/rxrpc/ar-connevent.c
78589 +++ b/net/rxrpc/ar-connevent.c
78590 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
78591
78592 len = iov[0].iov_len + iov[1].iov_len;
78593
78594 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78595 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78596 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78597
78598 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78599 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
78600 index 1a2b0633..e8d1382 100644
78601 --- a/net/rxrpc/ar-input.c
78602 +++ b/net/rxrpc/ar-input.c
78603 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
78604 /* track the latest serial number on this connection for ACK packet
78605 * information */
78606 serial = ntohl(sp->hdr.serial);
78607 - hi_serial = atomic_read(&call->conn->hi_serial);
78608 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78609 while (serial > hi_serial)
78610 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78611 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78612 serial);
78613
78614 /* request ACK generation for any ACK or DATA packet that requests
78615 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
78616 index 8e22bd3..f66d1c0 100644
78617 --- a/net/rxrpc/ar-internal.h
78618 +++ b/net/rxrpc/ar-internal.h
78619 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78620 int error; /* error code for local abort */
78621 int debug_id; /* debug ID for printks */
78622 unsigned call_counter; /* call ID counter */
78623 - atomic_t serial; /* packet serial number counter */
78624 - atomic_t hi_serial; /* highest serial number received */
78625 + atomic_unchecked_t serial; /* packet serial number counter */
78626 + atomic_unchecked_t hi_serial; /* highest serial number received */
78627 u8 avail_calls; /* number of calls available */
78628 u8 size_align; /* data size alignment (for security) */
78629 u8 header_size; /* rxrpc + security header size */
78630 @@ -346,7 +346,7 @@ struct rxrpc_call {
78631 spinlock_t lock;
78632 rwlock_t state_lock; /* lock for state transition */
78633 atomic_t usage;
78634 - atomic_t sequence; /* Tx data packet sequence counter */
78635 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78636 u32 abort_code; /* local/remote abort code */
78637 enum { /* current state of call */
78638 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78639 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
78640 */
78641 extern atomic_t rxrpc_n_skbs;
78642 extern __be32 rxrpc_epoch;
78643 -extern atomic_t rxrpc_debug_id;
78644 +extern atomic_unchecked_t rxrpc_debug_id;
78645 extern struct workqueue_struct *rxrpc_workqueue;
78646
78647 /*
78648 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
78649 index 87f7135..74d3703 100644
78650 --- a/net/rxrpc/ar-local.c
78651 +++ b/net/rxrpc/ar-local.c
78652 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
78653 spin_lock_init(&local->lock);
78654 rwlock_init(&local->services_lock);
78655 atomic_set(&local->usage, 1);
78656 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78657 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78658 memcpy(&local->srx, srx, sizeof(*srx));
78659 }
78660
78661 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
78662 index 16ae887..d24f12b 100644
78663 --- a/net/rxrpc/ar-output.c
78664 +++ b/net/rxrpc/ar-output.c
78665 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
78666 sp->hdr.cid = call->cid;
78667 sp->hdr.callNumber = call->call_id;
78668 sp->hdr.seq =
78669 - htonl(atomic_inc_return(&call->sequence));
78670 + htonl(atomic_inc_return_unchecked(&call->sequence));
78671 sp->hdr.serial =
78672 - htonl(atomic_inc_return(&conn->serial));
78673 + htonl(atomic_inc_return_unchecked(&conn->serial));
78674 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78675 sp->hdr.userStatus = 0;
78676 sp->hdr.securityIndex = conn->security_ix;
78677 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
78678 index 2754f09..b20e38f 100644
78679 --- a/net/rxrpc/ar-peer.c
78680 +++ b/net/rxrpc/ar-peer.c
78681 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
78682 INIT_LIST_HEAD(&peer->error_targets);
78683 spin_lock_init(&peer->lock);
78684 atomic_set(&peer->usage, 1);
78685 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78686 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78687 memcpy(&peer->srx, srx, sizeof(*srx));
78688
78689 rxrpc_assess_MTU_size(peer);
78690 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
78691 index 38047f7..9f48511 100644
78692 --- a/net/rxrpc/ar-proc.c
78693 +++ b/net/rxrpc/ar-proc.c
78694 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
78695 atomic_read(&conn->usage),
78696 rxrpc_conn_states[conn->state],
78697 key_serial(conn->key),
78698 - atomic_read(&conn->serial),
78699 - atomic_read(&conn->hi_serial));
78700 + atomic_read_unchecked(&conn->serial),
78701 + atomic_read_unchecked(&conn->hi_serial));
78702
78703 return 0;
78704 }
78705 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
78706 index 92df566..87ec1bf 100644
78707 --- a/net/rxrpc/ar-transport.c
78708 +++ b/net/rxrpc/ar-transport.c
78709 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
78710 spin_lock_init(&trans->client_lock);
78711 rwlock_init(&trans->conn_lock);
78712 atomic_set(&trans->usage, 1);
78713 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78714 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78715
78716 if (peer->srx.transport.family == AF_INET) {
78717 switch (peer->srx.transport_type) {
78718 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
78719 index 7635107..4670276 100644
78720 --- a/net/rxrpc/rxkad.c
78721 +++ b/net/rxrpc/rxkad.c
78722 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
78723
78724 len = iov[0].iov_len + iov[1].iov_len;
78725
78726 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78727 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78728 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78729
78730 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78731 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
78732
78733 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78734
78735 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78736 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78737 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78738
78739 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78740 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
78741 index 1e2eee8..ce3967e 100644
78742 --- a/net/sctp/proc.c
78743 +++ b/net/sctp/proc.c
78744 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
78745 seq_printf(seq,
78746 "%8pK %8pK %-3d %-3d %-2d %-4d "
78747 "%4d %8d %8d %7d %5lu %-5d %5d ",
78748 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78749 + assoc, sk,
78750 + sctp_sk(sk)->type, sk->sk_state,
78751 assoc->state, hash,
78752 assoc->assoc_id,
78753 assoc->sndbuf_used,
78754 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
78755 index d043722..6903416 100644
78756 --- a/net/sctp/socket.c
78757 +++ b/net/sctp/socket.c
78758 @@ -4575,7 +4575,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
78759 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
78760 if (space_left < addrlen)
78761 return -ENOMEM;
78762 - if (copy_to_user(to, &temp, addrlen))
78763 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
78764 return -EFAULT;
78765 to += addrlen;
78766 cnt++;
78767 diff --git a/net/socket.c b/net/socket.c
78768 index 0de4131..7e7ddab 100644
78769 --- a/net/socket.c
78770 +++ b/net/socket.c
78771 @@ -88,6 +88,7 @@
78772 #include <linux/nsproxy.h>
78773 #include <linux/magic.h>
78774 #include <linux/slab.h>
78775 +#include <linux/in.h>
78776
78777 #include <asm/uaccess.h>
78778 #include <asm/unistd.h>
78779 @@ -105,6 +106,8 @@
78780 #include <linux/sockios.h>
78781 #include <linux/atalk.h>
78782
78783 +#include <linux/grsock.h>
78784 +
78785 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
78786 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
78787 unsigned long nr_segs, loff_t pos);
78788 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
78789 &sockfs_dentry_operations, SOCKFS_MAGIC);
78790 }
78791
78792 -static struct vfsmount *sock_mnt __read_mostly;
78793 +struct vfsmount *sock_mnt __read_mostly;
78794
78795 static struct file_system_type sock_fs_type = {
78796 .name = "sockfs",
78797 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
78798 return -EAFNOSUPPORT;
78799 if (type < 0 || type >= SOCK_MAX)
78800 return -EINVAL;
78801 + if (protocol < 0)
78802 + return -EINVAL;
78803
78804 /* Compatibility.
78805
78806 @@ -1339,6 +1344,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
78807 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
78808 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
78809
78810 + if(!gr_search_socket(family, type, protocol)) {
78811 + retval = -EACCES;
78812 + goto out;
78813 + }
78814 +
78815 + if (gr_handle_sock_all(family, type, protocol)) {
78816 + retval = -EACCES;
78817 + goto out;
78818 + }
78819 +
78820 retval = sock_create(family, type, protocol, &sock);
78821 if (retval < 0)
78822 goto out;
78823 @@ -1451,6 +1466,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78824 if (sock) {
78825 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
78826 if (err >= 0) {
78827 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
78828 + err = -EACCES;
78829 + goto error;
78830 + }
78831 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
78832 + if (err)
78833 + goto error;
78834 +
78835 err = security_socket_bind(sock,
78836 (struct sockaddr *)&address,
78837 addrlen);
78838 @@ -1459,6 +1482,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
78839 (struct sockaddr *)
78840 &address, addrlen);
78841 }
78842 +error:
78843 fput_light(sock->file, fput_needed);
78844 }
78845 return err;
78846 @@ -1482,10 +1506,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
78847 if ((unsigned)backlog > somaxconn)
78848 backlog = somaxconn;
78849
78850 + if (gr_handle_sock_server_other(sock->sk)) {
78851 + err = -EPERM;
78852 + goto error;
78853 + }
78854 +
78855 + err = gr_search_listen(sock);
78856 + if (err)
78857 + goto error;
78858 +
78859 err = security_socket_listen(sock, backlog);
78860 if (!err)
78861 err = sock->ops->listen(sock, backlog);
78862
78863 +error:
78864 fput_light(sock->file, fput_needed);
78865 }
78866 return err;
78867 @@ -1529,6 +1563,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78868 newsock->type = sock->type;
78869 newsock->ops = sock->ops;
78870
78871 + if (gr_handle_sock_server_other(sock->sk)) {
78872 + err = -EPERM;
78873 + sock_release(newsock);
78874 + goto out_put;
78875 + }
78876 +
78877 + err = gr_search_accept(sock);
78878 + if (err) {
78879 + sock_release(newsock);
78880 + goto out_put;
78881 + }
78882 +
78883 /*
78884 * We don't need try_module_get here, as the listening socket (sock)
78885 * has the protocol module (sock->ops->owner) held.
78886 @@ -1567,6 +1613,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
78887 fd_install(newfd, newfile);
78888 err = newfd;
78889
78890 + gr_attach_curr_ip(newsock->sk);
78891 +
78892 out_put:
78893 fput_light(sock->file, fput_needed);
78894 out:
78895 @@ -1599,6 +1647,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78896 int, addrlen)
78897 {
78898 struct socket *sock;
78899 + struct sockaddr *sck;
78900 struct sockaddr_storage address;
78901 int err, fput_needed;
78902
78903 @@ -1609,6 +1658,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
78904 if (err < 0)
78905 goto out_put;
78906
78907 + sck = (struct sockaddr *)&address;
78908 +
78909 + if (gr_handle_sock_client(sck)) {
78910 + err = -EACCES;
78911 + goto out_put;
78912 + }
78913 +
78914 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
78915 + if (err)
78916 + goto out_put;
78917 +
78918 err =
78919 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
78920 if (err)
78921 @@ -1970,7 +2030,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
78922 * checking falls down on this.
78923 */
78924 if (copy_from_user(ctl_buf,
78925 - (void __user __force *)msg_sys->msg_control,
78926 + (void __force_user *)msg_sys->msg_control,
78927 ctl_len))
78928 goto out_freectl;
78929 msg_sys->msg_control = ctl_buf;
78930 @@ -2140,7 +2200,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
78931 * kernel msghdr to use the kernel address space)
78932 */
78933
78934 - uaddr = (__force void __user *)msg_sys->msg_name;
78935 + uaddr = (void __force_user *)msg_sys->msg_name;
78936 uaddr_len = COMPAT_NAMELEN(msg);
78937 if (MSG_CMSG_COMPAT & flags) {
78938 err = verify_compat_iovec(msg_sys, iov,
78939 @@ -2768,7 +2828,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78940 }
78941
78942 ifr = compat_alloc_user_space(buf_size);
78943 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
78944 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
78945
78946 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
78947 return -EFAULT;
78948 @@ -2792,12 +2852,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78949 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
78950
78951 if (copy_in_user(rxnfc, compat_rxnfc,
78952 - (void *)(&rxnfc->fs.m_ext + 1) -
78953 - (void *)rxnfc) ||
78954 + (void __user *)(&rxnfc->fs.m_ext + 1) -
78955 + (void __user *)rxnfc) ||
78956 copy_in_user(&rxnfc->fs.ring_cookie,
78957 &compat_rxnfc->fs.ring_cookie,
78958 - (void *)(&rxnfc->fs.location + 1) -
78959 - (void *)&rxnfc->fs.ring_cookie) ||
78960 + (void __user *)(&rxnfc->fs.location + 1) -
78961 + (void __user *)&rxnfc->fs.ring_cookie) ||
78962 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
78963 sizeof(rxnfc->rule_cnt)))
78964 return -EFAULT;
78965 @@ -2809,12 +2869,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
78966
78967 if (convert_out) {
78968 if (copy_in_user(compat_rxnfc, rxnfc,
78969 - (const void *)(&rxnfc->fs.m_ext + 1) -
78970 - (const void *)rxnfc) ||
78971 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
78972 + (const void __user *)rxnfc) ||
78973 copy_in_user(&compat_rxnfc->fs.ring_cookie,
78974 &rxnfc->fs.ring_cookie,
78975 - (const void *)(&rxnfc->fs.location + 1) -
78976 - (const void *)&rxnfc->fs.ring_cookie) ||
78977 + (const void __user *)(&rxnfc->fs.location + 1) -
78978 + (const void __user *)&rxnfc->fs.ring_cookie) ||
78979 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
78980 sizeof(rxnfc->rule_cnt)))
78981 return -EFAULT;
78982 @@ -2884,7 +2944,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
78983 old_fs = get_fs();
78984 set_fs(KERNEL_DS);
78985 err = dev_ioctl(net, cmd,
78986 - (struct ifreq __user __force *) &kifr);
78987 + (struct ifreq __force_user *) &kifr);
78988 set_fs(old_fs);
78989
78990 return err;
78991 @@ -2993,7 +3053,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
78992
78993 old_fs = get_fs();
78994 set_fs(KERNEL_DS);
78995 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
78996 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
78997 set_fs(old_fs);
78998
78999 if (cmd == SIOCGIFMAP && !err) {
79000 @@ -3098,7 +3158,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79001 ret |= __get_user(rtdev, &(ur4->rt_dev));
79002 if (rtdev) {
79003 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79004 - r4.rt_dev = (char __user __force *)devname;
79005 + r4.rt_dev = (char __force_user *)devname;
79006 devname[15] = 0;
79007 } else
79008 r4.rt_dev = NULL;
79009 @@ -3324,8 +3384,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79010 int __user *uoptlen;
79011 int err;
79012
79013 - uoptval = (char __user __force *) optval;
79014 - uoptlen = (int __user __force *) optlen;
79015 + uoptval = (char __force_user *) optval;
79016 + uoptlen = (int __force_user *) optlen;
79017
79018 set_fs(KERNEL_DS);
79019 if (level == SOL_SOCKET)
79020 @@ -3345,7 +3405,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79021 char __user *uoptval;
79022 int err;
79023
79024 - uoptval = (char __user __force *) optval;
79025 + uoptval = (char __force_user *) optval;
79026
79027 set_fs(KERNEL_DS);
79028 if (level == SOL_SOCKET)
79029 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79030 index 8efd96c..b492ab2 100644
79031 --- a/net/sunrpc/sched.c
79032 +++ b/net/sunrpc/sched.c
79033 @@ -239,9 +239,9 @@ static int rpc_wait_bit_killable(void *word)
79034 #ifdef RPC_DEBUG
79035 static void rpc_task_set_debuginfo(struct rpc_task *task)
79036 {
79037 - static atomic_t rpc_pid;
79038 + static atomic_unchecked_t rpc_pid;
79039
79040 - task->tk_pid = atomic_inc_return(&rpc_pid);
79041 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79042 }
79043 #else
79044 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79045 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
79046 index 4645709..d41d668 100644
79047 --- a/net/sunrpc/svcsock.c
79048 +++ b/net/sunrpc/svcsock.c
79049 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
79050 int buflen, unsigned int base)
79051 {
79052 size_t save_iovlen;
79053 - void __user *save_iovbase;
79054 + void *save_iovbase;
79055 unsigned int i;
79056 int ret;
79057
79058 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79059 index 09af4fa..77110a9 100644
79060 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79061 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79062 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79063 static unsigned int min_max_inline = 4096;
79064 static unsigned int max_max_inline = 65536;
79065
79066 -atomic_t rdma_stat_recv;
79067 -atomic_t rdma_stat_read;
79068 -atomic_t rdma_stat_write;
79069 -atomic_t rdma_stat_sq_starve;
79070 -atomic_t rdma_stat_rq_starve;
79071 -atomic_t rdma_stat_rq_poll;
79072 -atomic_t rdma_stat_rq_prod;
79073 -atomic_t rdma_stat_sq_poll;
79074 -atomic_t rdma_stat_sq_prod;
79075 +atomic_unchecked_t rdma_stat_recv;
79076 +atomic_unchecked_t rdma_stat_read;
79077 +atomic_unchecked_t rdma_stat_write;
79078 +atomic_unchecked_t rdma_stat_sq_starve;
79079 +atomic_unchecked_t rdma_stat_rq_starve;
79080 +atomic_unchecked_t rdma_stat_rq_poll;
79081 +atomic_unchecked_t rdma_stat_rq_prod;
79082 +atomic_unchecked_t rdma_stat_sq_poll;
79083 +atomic_unchecked_t rdma_stat_sq_prod;
79084
79085 /* Temporary NFS request map and context caches */
79086 struct kmem_cache *svc_rdma_map_cachep;
79087 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
79088 len -= *ppos;
79089 if (len > *lenp)
79090 len = *lenp;
79091 - if (len && copy_to_user(buffer, str_buf, len))
79092 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79093 return -EFAULT;
79094 *lenp = len;
79095 *ppos += len;
79096 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
79097 {
79098 .procname = "rdma_stat_read",
79099 .data = &rdma_stat_read,
79100 - .maxlen = sizeof(atomic_t),
79101 + .maxlen = sizeof(atomic_unchecked_t),
79102 .mode = 0644,
79103 .proc_handler = read_reset_stat,
79104 },
79105 {
79106 .procname = "rdma_stat_recv",
79107 .data = &rdma_stat_recv,
79108 - .maxlen = sizeof(atomic_t),
79109 + .maxlen = sizeof(atomic_unchecked_t),
79110 .mode = 0644,
79111 .proc_handler = read_reset_stat,
79112 },
79113 {
79114 .procname = "rdma_stat_write",
79115 .data = &rdma_stat_write,
79116 - .maxlen = sizeof(atomic_t),
79117 + .maxlen = sizeof(atomic_unchecked_t),
79118 .mode = 0644,
79119 .proc_handler = read_reset_stat,
79120 },
79121 {
79122 .procname = "rdma_stat_sq_starve",
79123 .data = &rdma_stat_sq_starve,
79124 - .maxlen = sizeof(atomic_t),
79125 + .maxlen = sizeof(atomic_unchecked_t),
79126 .mode = 0644,
79127 .proc_handler = read_reset_stat,
79128 },
79129 {
79130 .procname = "rdma_stat_rq_starve",
79131 .data = &rdma_stat_rq_starve,
79132 - .maxlen = sizeof(atomic_t),
79133 + .maxlen = sizeof(atomic_unchecked_t),
79134 .mode = 0644,
79135 .proc_handler = read_reset_stat,
79136 },
79137 {
79138 .procname = "rdma_stat_rq_poll",
79139 .data = &rdma_stat_rq_poll,
79140 - .maxlen = sizeof(atomic_t),
79141 + .maxlen = sizeof(atomic_unchecked_t),
79142 .mode = 0644,
79143 .proc_handler = read_reset_stat,
79144 },
79145 {
79146 .procname = "rdma_stat_rq_prod",
79147 .data = &rdma_stat_rq_prod,
79148 - .maxlen = sizeof(atomic_t),
79149 + .maxlen = sizeof(atomic_unchecked_t),
79150 .mode = 0644,
79151 .proc_handler = read_reset_stat,
79152 },
79153 {
79154 .procname = "rdma_stat_sq_poll",
79155 .data = &rdma_stat_sq_poll,
79156 - .maxlen = sizeof(atomic_t),
79157 + .maxlen = sizeof(atomic_unchecked_t),
79158 .mode = 0644,
79159 .proc_handler = read_reset_stat,
79160 },
79161 {
79162 .procname = "rdma_stat_sq_prod",
79163 .data = &rdma_stat_sq_prod,
79164 - .maxlen = sizeof(atomic_t),
79165 + .maxlen = sizeof(atomic_unchecked_t),
79166 .mode = 0644,
79167 .proc_handler = read_reset_stat,
79168 },
79169 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79170 index df67211..c354b13 100644
79171 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79172 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79173 @@ -499,7 +499,7 @@ next_sge:
79174 svc_rdma_put_context(ctxt, 0);
79175 goto out;
79176 }
79177 - atomic_inc(&rdma_stat_read);
79178 + atomic_inc_unchecked(&rdma_stat_read);
79179
79180 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79181 chl_map->ch[ch_no].count -= read_wr.num_sge;
79182 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79183 dto_q);
79184 list_del_init(&ctxt->dto_q);
79185 } else {
79186 - atomic_inc(&rdma_stat_rq_starve);
79187 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79188 clear_bit(XPT_DATA, &xprt->xpt_flags);
79189 ctxt = NULL;
79190 }
79191 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79192 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79193 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79194 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79195 - atomic_inc(&rdma_stat_recv);
79196 + atomic_inc_unchecked(&rdma_stat_recv);
79197
79198 /* Build up the XDR from the receive buffers. */
79199 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79200 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79201 index 249a835..fb2794b 100644
79202 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79203 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79204 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79205 write_wr.wr.rdma.remote_addr = to;
79206
79207 /* Post It */
79208 - atomic_inc(&rdma_stat_write);
79209 + atomic_inc_unchecked(&rdma_stat_write);
79210 if (svc_rdma_send(xprt, &write_wr))
79211 goto err;
79212 return 0;
79213 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79214 index 894cb42..cf5bafb 100644
79215 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79216 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79217 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79218 return;
79219
79220 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79221 - atomic_inc(&rdma_stat_rq_poll);
79222 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79223
79224 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79225 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79226 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79227 }
79228
79229 if (ctxt)
79230 - atomic_inc(&rdma_stat_rq_prod);
79231 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79232
79233 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79234 /*
79235 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79236 return;
79237
79238 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79239 - atomic_inc(&rdma_stat_sq_poll);
79240 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79241 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79242 if (wc.status != IB_WC_SUCCESS)
79243 /* Close the transport */
79244 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79245 }
79246
79247 if (ctxt)
79248 - atomic_inc(&rdma_stat_sq_prod);
79249 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79250 }
79251
79252 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79253 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79254 spin_lock_bh(&xprt->sc_lock);
79255 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79256 spin_unlock_bh(&xprt->sc_lock);
79257 - atomic_inc(&rdma_stat_sq_starve);
79258 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79259
79260 /* See if we can opportunistically reap SQ WR to make room */
79261 sq_cq_reap(xprt);
79262 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79263 index e758139..d29ea47 100644
79264 --- a/net/sysctl_net.c
79265 +++ b/net/sysctl_net.c
79266 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79267 struct ctl_table *table)
79268 {
79269 /* Allow network administrator to have same access as root. */
79270 - if (capable(CAP_NET_ADMIN)) {
79271 + if (capable_nolog(CAP_NET_ADMIN)) {
79272 int mode = (table->mode >> 6) & 7;
79273 return (mode << 6) | (mode << 3) | mode;
79274 }
79275 diff --git a/net/tipc/link.c b/net/tipc/link.c
79276 index ac1832a..533ed97 100644
79277 --- a/net/tipc/link.c
79278 +++ b/net/tipc/link.c
79279 @@ -1205,7 +1205,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79280 struct tipc_msg fragm_hdr;
79281 struct sk_buff *buf, *buf_chain, *prev;
79282 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79283 - const unchar *sect_crs;
79284 + const unchar __user *sect_crs;
79285 int curr_sect;
79286 u32 fragm_no;
79287
79288 @@ -1249,7 +1249,7 @@ again:
79289
79290 if (!sect_rest) {
79291 sect_rest = msg_sect[++curr_sect].iov_len;
79292 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79293 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79294 }
79295
79296 if (sect_rest < fragm_rest)
79297 @@ -1268,7 +1268,7 @@ error:
79298 }
79299 } else
79300 skb_copy_to_linear_data_offset(buf, fragm_crs,
79301 - sect_crs, sz);
79302 + (const void __force_kernel *)sect_crs, sz);
79303 sect_crs += sz;
79304 sect_rest -= sz;
79305 fragm_crs += sz;
79306 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79307 index 3e4d3e2..27b55dc 100644
79308 --- a/net/tipc/msg.c
79309 +++ b/net/tipc/msg.c
79310 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79311 msg_sect[cnt].iov_len);
79312 else
79313 skb_copy_to_linear_data_offset(*buf, pos,
79314 - msg_sect[cnt].iov_base,
79315 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79316 msg_sect[cnt].iov_len);
79317 pos += msg_sect[cnt].iov_len;
79318 }
79319 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79320 index 8c49566..14510cb 100644
79321 --- a/net/tipc/subscr.c
79322 +++ b/net/tipc/subscr.c
79323 @@ -101,7 +101,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79324 {
79325 struct iovec msg_sect;
79326
79327 - msg_sect.iov_base = (void *)&sub->evt;
79328 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79329 msg_sect.iov_len = sizeof(struct tipc_event);
79330
79331 sub->evt.event = htohl(event, sub->swap);
79332 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79333 index 85d3bb7..79f4487 100644
79334 --- a/net/unix/af_unix.c
79335 +++ b/net/unix/af_unix.c
79336 @@ -770,6 +770,12 @@ static struct sock *unix_find_other(struct net *net,
79337 err = -ECONNREFUSED;
79338 if (!S_ISSOCK(inode->i_mode))
79339 goto put_fail;
79340 +
79341 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79342 + err = -EACCES;
79343 + goto put_fail;
79344 + }
79345 +
79346 u = unix_find_socket_byinode(inode);
79347 if (!u)
79348 goto put_fail;
79349 @@ -790,6 +796,13 @@ static struct sock *unix_find_other(struct net *net,
79350 if (u) {
79351 struct dentry *dentry;
79352 dentry = unix_sk(u)->dentry;
79353 +
79354 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79355 + err = -EPERM;
79356 + sock_put(u);
79357 + goto fail;
79358 + }
79359 +
79360 if (dentry)
79361 touch_atime(unix_sk(u)->mnt, dentry);
79362 } else
79363 @@ -872,11 +885,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
79364 err = security_path_mknod(&path, dentry, mode, 0);
79365 if (err)
79366 goto out_mknod_drop_write;
79367 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79368 + err = -EACCES;
79369 + goto out_mknod_drop_write;
79370 + }
79371 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79372 out_mknod_drop_write:
79373 mnt_drop_write(path.mnt);
79374 if (err)
79375 goto out_mknod_dput;
79376 +
79377 + gr_handle_create(dentry, path.mnt);
79378 +
79379 mutex_unlock(&path.dentry->d_inode->i_mutex);
79380 dput(path.dentry);
79381 path.dentry = dentry;
79382 diff --git a/net/wireless/core.h b/net/wireless/core.h
79383 index 43ad9c8..ab5127c 100644
79384 --- a/net/wireless/core.h
79385 +++ b/net/wireless/core.h
79386 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
79387 struct mutex mtx;
79388
79389 /* rfkill support */
79390 - struct rfkill_ops rfkill_ops;
79391 + rfkill_ops_no_const rfkill_ops;
79392 struct rfkill *rfkill;
79393 struct work_struct rfkill_sync;
79394
79395 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
79396 index 0af7f54..c916d2f 100644
79397 --- a/net/wireless/wext-core.c
79398 +++ b/net/wireless/wext-core.c
79399 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79400 */
79401
79402 /* Support for very large requests */
79403 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79404 - (user_length > descr->max_tokens)) {
79405 + if (user_length > descr->max_tokens) {
79406 /* Allow userspace to GET more than max so
79407 * we can support any size GET requests.
79408 * There is still a limit : -ENOMEM.
79409 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79410 }
79411 }
79412
79413 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79414 - /*
79415 - * If this is a GET, but not NOMAX, it means that the extra
79416 - * data is not bounded by userspace, but by max_tokens. Thus
79417 - * set the length to max_tokens. This matches the extra data
79418 - * allocation.
79419 - * The driver should fill it with the number of tokens it
79420 - * provided, and it may check iwp->length rather than having
79421 - * knowledge of max_tokens. If the driver doesn't change the
79422 - * iwp->length, this ioctl just copies back max_token tokens
79423 - * filled with zeroes. Hopefully the driver isn't claiming
79424 - * them to be valid data.
79425 - */
79426 - iwp->length = descr->max_tokens;
79427 - }
79428 -
79429 err = handler(dev, info, (union iwreq_data *) iwp, extra);
79430
79431 iwp->length += essid_compat;
79432 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
79433 index 7661576..80f7627 100644
79434 --- a/net/xfrm/xfrm_policy.c
79435 +++ b/net/xfrm/xfrm_policy.c
79436 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
79437 {
79438 policy->walk.dead = 1;
79439
79440 - atomic_inc(&policy->genid);
79441 + atomic_inc_unchecked(&policy->genid);
79442
79443 if (del_timer(&policy->timer))
79444 xfrm_pol_put(policy);
79445 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
79446 hlist_add_head(&policy->bydst, chain);
79447 xfrm_pol_hold(policy);
79448 net->xfrm.policy_count[dir]++;
79449 - atomic_inc(&flow_cache_genid);
79450 + atomic_inc_unchecked(&flow_cache_genid);
79451 if (delpol)
79452 __xfrm_policy_unlink(delpol, dir);
79453 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
79454 @@ -1530,7 +1530,7 @@ free_dst:
79455 goto out;
79456 }
79457
79458 -static int inline
79459 +static inline int
79460 xfrm_dst_alloc_copy(void **target, const void *src, int size)
79461 {
79462 if (!*target) {
79463 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
79464 return 0;
79465 }
79466
79467 -static int inline
79468 +static inline int
79469 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79470 {
79471 #ifdef CONFIG_XFRM_SUB_POLICY
79472 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79473 #endif
79474 }
79475
79476 -static int inline
79477 +static inline int
79478 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
79479 {
79480 #ifdef CONFIG_XFRM_SUB_POLICY
79481 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
79482
79483 xdst->num_pols = num_pols;
79484 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
79485 - xdst->policy_genid = atomic_read(&pols[0]->genid);
79486 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
79487
79488 return xdst;
79489 }
79490 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
79491 if (xdst->xfrm_genid != dst->xfrm->genid)
79492 return 0;
79493 if (xdst->num_pols > 0 &&
79494 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
79495 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
79496 return 0;
79497
79498 mtu = dst_mtu(dst->child);
79499 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
79500 sizeof(pol->xfrm_vec[i].saddr));
79501 pol->xfrm_vec[i].encap_family = mp->new_family;
79502 /* flush bundles */
79503 - atomic_inc(&pol->genid);
79504 + atomic_inc_unchecked(&pol->genid);
79505 }
79506 }
79507
79508 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
79509 index d2b366c..51ff91ebc 100644
79510 --- a/scripts/Makefile.build
79511 +++ b/scripts/Makefile.build
79512 @@ -109,7 +109,7 @@ endif
79513 endif
79514
79515 # Do not include host rules unless needed
79516 -ifneq ($(hostprogs-y)$(hostprogs-m),)
79517 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
79518 include scripts/Makefile.host
79519 endif
79520
79521 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
79522 index 686cb0d..9d653bf 100644
79523 --- a/scripts/Makefile.clean
79524 +++ b/scripts/Makefile.clean
79525 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
79526 __clean-files := $(extra-y) $(always) \
79527 $(targets) $(clean-files) \
79528 $(host-progs) \
79529 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79530 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79531 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79532
79533 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
79534
79535 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
79536 index 1ac414f..a1c1451 100644
79537 --- a/scripts/Makefile.host
79538 +++ b/scripts/Makefile.host
79539 @@ -31,6 +31,7 @@
79540 # Note: Shared libraries consisting of C++ files are not supported
79541
79542 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79543 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79544
79545 # C code
79546 # Executables compiled from a single .c file
79547 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
79548 # Shared libaries (only .c supported)
79549 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79550 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79551 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79552 # Remove .so files from "xxx-objs"
79553 host-cobjs := $(filter-out %.so,$(host-cobjs))
79554
79555 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
79556 index cb1f50c..cef2a7c 100644
79557 --- a/scripts/basic/fixdep.c
79558 +++ b/scripts/basic/fixdep.c
79559 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
79560 /*
79561 * Lookup a value in the configuration string.
79562 */
79563 -static int is_defined_config(const char *name, int len, unsigned int hash)
79564 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
79565 {
79566 struct item *aux;
79567
79568 @@ -211,10 +211,10 @@ static void clear_config(void)
79569 /*
79570 * Record the use of a CONFIG_* word.
79571 */
79572 -static void use_config(const char *m, int slen)
79573 +static void use_config(const char *m, unsigned int slen)
79574 {
79575 unsigned int hash = strhash(m, slen);
79576 - int c, i;
79577 + unsigned int c, i;
79578
79579 if (is_defined_config(m, slen, hash))
79580 return;
79581 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
79582
79583 static void parse_config_file(const char *map, size_t len)
79584 {
79585 - const int *end = (const int *) (map + len);
79586 + const unsigned int *end = (const unsigned int *) (map + len);
79587 /* start at +1, so that p can never be < map */
79588 - const int *m = (const int *) map + 1;
79589 + const unsigned int *m = (const unsigned int *) map + 1;
79590 const char *p, *q;
79591
79592 for (; m < end; m++) {
79593 @@ -406,7 +406,7 @@ static void print_deps(void)
79594 static void traps(void)
79595 {
79596 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
79597 - int *p = (int *)test;
79598 + unsigned int *p = (unsigned int *)test;
79599
79600 if (*p != INT_CONF) {
79601 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
79602 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
79603 new file mode 100644
79604 index 0000000..8729101
79605 --- /dev/null
79606 +++ b/scripts/gcc-plugin.sh
79607 @@ -0,0 +1,2 @@
79608 +#!/bin/sh
79609 +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"
79610 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
79611 index e047e17..ea646ec 100644
79612 --- a/scripts/mod/file2alias.c
79613 +++ b/scripts/mod/file2alias.c
79614 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
79615 unsigned long size, unsigned long id_size,
79616 void *symval)
79617 {
79618 - int i;
79619 + unsigned int i;
79620
79621 if (size % id_size || size < id_size) {
79622 if (cross_build != 0)
79623 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
79624 /* USB is special because the bcdDevice can be matched against a numeric range */
79625 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
79626 static void do_usb_entry(struct usb_device_id *id,
79627 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79628 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79629 unsigned char range_lo, unsigned char range_hi,
79630 unsigned char max, struct module *mod)
79631 {
79632 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
79633 {
79634 unsigned int devlo, devhi;
79635 unsigned char chi, clo, max;
79636 - int ndigits;
79637 + unsigned int ndigits;
79638
79639 id->match_flags = TO_NATIVE(id->match_flags);
79640 id->idVendor = TO_NATIVE(id->idVendor);
79641 @@ -501,7 +501,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
79642 for (i = 0; i < count; i++) {
79643 const char *id = (char *)devs[i].id;
79644 char acpi_id[sizeof(devs[0].id)];
79645 - int j;
79646 + unsigned int j;
79647
79648 buf_printf(&mod->dev_table_buf,
79649 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79650 @@ -531,7 +531,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79651
79652 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79653 const char *id = (char *)card->devs[j].id;
79654 - int i2, j2;
79655 + unsigned int i2, j2;
79656 int dup = 0;
79657
79658 if (!id[0])
79659 @@ -557,7 +557,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79660 /* add an individual alias for every device entry */
79661 if (!dup) {
79662 char acpi_id[sizeof(card->devs[0].id)];
79663 - int k;
79664 + unsigned int k;
79665
79666 buf_printf(&mod->dev_table_buf,
79667 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79668 @@ -882,7 +882,7 @@ static void dmi_ascii_filter(char *d, const char *s)
79669 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79670 char *alias)
79671 {
79672 - int i, j;
79673 + unsigned int i, j;
79674
79675 sprintf(alias, "dmi*");
79676
79677 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
79678 index c4e7d15..4241aef 100644
79679 --- a/scripts/mod/modpost.c
79680 +++ b/scripts/mod/modpost.c
79681 @@ -922,6 +922,7 @@ enum mismatch {
79682 ANY_INIT_TO_ANY_EXIT,
79683 ANY_EXIT_TO_ANY_INIT,
79684 EXPORT_TO_INIT_EXIT,
79685 + DATA_TO_TEXT
79686 };
79687
79688 struct sectioncheck {
79689 @@ -1030,6 +1031,12 @@ const struct sectioncheck sectioncheck[] = {
79690 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79691 .mismatch = EXPORT_TO_INIT_EXIT,
79692 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
79693 +},
79694 +/* Do not reference code from writable data */
79695 +{
79696 + .fromsec = { DATA_SECTIONS, NULL },
79697 + .tosec = { TEXT_SECTIONS, NULL },
79698 + .mismatch = DATA_TO_TEXT
79699 }
79700 };
79701
79702 @@ -1152,10 +1159,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
79703 continue;
79704 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
79705 continue;
79706 - if (sym->st_value == addr)
79707 - return sym;
79708 /* Find a symbol nearby - addr are maybe negative */
79709 d = sym->st_value - addr;
79710 + if (d == 0)
79711 + return sym;
79712 if (d < 0)
79713 d = addr - sym->st_value;
79714 if (d < distance) {
79715 @@ -1434,6 +1441,14 @@ static void report_sec_mismatch(const char *modname,
79716 tosym, prl_to, prl_to, tosym);
79717 free(prl_to);
79718 break;
79719 + case DATA_TO_TEXT:
79720 +/*
79721 + fprintf(stderr,
79722 + "The variable %s references\n"
79723 + "the %s %s%s%s\n",
79724 + fromsym, to, sec2annotation(tosec), tosym, to_p);
79725 +*/
79726 + break;
79727 }
79728 fprintf(stderr, "\n");
79729 }
79730 @@ -1668,7 +1683,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
79731 static void check_sec_ref(struct module *mod, const char *modname,
79732 struct elf_info *elf)
79733 {
79734 - int i;
79735 + unsigned int i;
79736 Elf_Shdr *sechdrs = elf->sechdrs;
79737
79738 /* Walk through all sections */
79739 @@ -1766,7 +1781,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
79740 va_end(ap);
79741 }
79742
79743 -void buf_write(struct buffer *buf, const char *s, int len)
79744 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
79745 {
79746 if (buf->size - buf->pos < len) {
79747 buf->size += len + SZ;
79748 @@ -1984,7 +1999,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
79749 if (fstat(fileno(file), &st) < 0)
79750 goto close_write;
79751
79752 - if (st.st_size != b->pos)
79753 + if (st.st_size != (off_t)b->pos)
79754 goto close_write;
79755
79756 tmp = NOFAIL(malloc(b->pos));
79757 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
79758 index 51207e4..f7d603d 100644
79759 --- a/scripts/mod/modpost.h
79760 +++ b/scripts/mod/modpost.h
79761 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
79762
79763 struct buffer {
79764 char *p;
79765 - int pos;
79766 - int size;
79767 + unsigned int pos;
79768 + unsigned int size;
79769 };
79770
79771 void __attribute__((format(printf, 2, 3)))
79772 buf_printf(struct buffer *buf, const char *fmt, ...);
79773
79774 void
79775 -buf_write(struct buffer *buf, const char *s, int len);
79776 +buf_write(struct buffer *buf, const char *s, unsigned int len);
79777
79778 struct module {
79779 struct module *next;
79780 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
79781 index 9dfcd6d..099068e 100644
79782 --- a/scripts/mod/sumversion.c
79783 +++ b/scripts/mod/sumversion.c
79784 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
79785 goto out;
79786 }
79787
79788 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
79789 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
79790 warn("writing sum in %s failed: %s\n",
79791 filename, strerror(errno));
79792 goto out;
79793 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
79794 index 5c11312..72742b5 100644
79795 --- a/scripts/pnmtologo.c
79796 +++ b/scripts/pnmtologo.c
79797 @@ -237,14 +237,14 @@ static void write_header(void)
79798 fprintf(out, " * Linux logo %s\n", logoname);
79799 fputs(" */\n\n", out);
79800 fputs("#include <linux/linux_logo.h>\n\n", out);
79801 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
79802 + fprintf(out, "static unsigned char %s_data[] = {\n",
79803 logoname);
79804 }
79805
79806 static void write_footer(void)
79807 {
79808 fputs("\n};\n\n", out);
79809 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
79810 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
79811 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
79812 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
79813 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
79814 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
79815 fputs("\n};\n\n", out);
79816
79817 /* write logo clut */
79818 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
79819 + fprintf(out, "static unsigned char %s_clut[] = {\n",
79820 logoname);
79821 write_hex_cnt = 0;
79822 for (i = 0; i < logo_clutsize; i++) {
79823 diff --git a/scripts/tags.sh b/scripts/tags.sh
79824 index 833813a..0bc8588 100755
79825 --- a/scripts/tags.sh
79826 +++ b/scripts/tags.sh
79827 @@ -116,7 +116,7 @@ docscope()
79828
79829 dogtags()
79830 {
79831 - all_sources | gtags -f -
79832 + all_sources | gtags -i -f -
79833 }
79834
79835 exuberant()
79836 diff --git a/security/Kconfig b/security/Kconfig
79837 index 51bd5a0..c37f5e6 100644
79838 --- a/security/Kconfig
79839 +++ b/security/Kconfig
79840 @@ -4,6 +4,640 @@
79841
79842 menu "Security options"
79843
79844 +source grsecurity/Kconfig
79845 +
79846 +menu "PaX"
79847 +
79848 + config ARCH_TRACK_EXEC_LIMIT
79849 + bool
79850 +
79851 + config PAX_KERNEXEC_PLUGIN
79852 + bool
79853 +
79854 + config PAX_PER_CPU_PGD
79855 + bool
79856 +
79857 + config TASK_SIZE_MAX_SHIFT
79858 + int
79859 + depends on X86_64
79860 + default 47 if !PAX_PER_CPU_PGD
79861 + default 42 if PAX_PER_CPU_PGD
79862 +
79863 + config PAX_ENABLE_PAE
79864 + bool
79865 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
79866 +
79867 +config PAX
79868 + bool "Enable various PaX features"
79869 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
79870 + help
79871 + This allows you to enable various PaX features. PaX adds
79872 + intrusion prevention mechanisms to the kernel that reduce
79873 + the risks posed by exploitable memory corruption bugs.
79874 +
79875 +menu "PaX Control"
79876 + depends on PAX
79877 +
79878 +config PAX_SOFTMODE
79879 + bool 'Support soft mode'
79880 + help
79881 + Enabling this option will allow you to run PaX in soft mode, that
79882 + is, PaX features will not be enforced by default, only on executables
79883 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
79884 + support as they are the only way to mark executables for soft mode use.
79885 +
79886 + Soft mode can be activated by using the "pax_softmode=1" kernel command
79887 + line option on boot. Furthermore you can control various PaX features
79888 + at runtime via the entries in /proc/sys/kernel/pax.
79889 +
79890 +config PAX_EI_PAX
79891 + bool 'Use legacy ELF header marking'
79892 + help
79893 + Enabling this option will allow you to control PaX features on
79894 + a per executable basis via the 'chpax' utility available at
79895 + http://pax.grsecurity.net/. The control flags will be read from
79896 + an otherwise reserved part of the ELF header. This marking has
79897 + numerous drawbacks (no support for soft-mode, toolchain does not
79898 + know about the non-standard use of the ELF header) therefore it
79899 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
79900 + support.
79901 +
79902 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79903 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
79904 + option otherwise they will not get any protection.
79905 +
79906 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
79907 + support as well, they will override the legacy EI_PAX marks.
79908 +
79909 +config PAX_PT_PAX_FLAGS
79910 + bool 'Use ELF program header marking'
79911 + help
79912 + Enabling this option will allow you to control PaX features on
79913 + a per executable basis via the 'paxctl' utility available at
79914 + http://pax.grsecurity.net/. The control flags will be read from
79915 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
79916 + has the benefits of supporting both soft mode and being fully
79917 + integrated into the toolchain (the binutils patch is available
79918 + from http://pax.grsecurity.net).
79919 +
79920 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79921 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
79922 + support otherwise they will not get any protection.
79923 +
79924 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79925 + must make sure that the marks are the same if a binary has both marks.
79926 +
79927 + Note that if you enable the legacy EI_PAX marking support as well,
79928 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
79929 +
79930 +config PAX_XATTR_PAX_FLAGS
79931 + bool 'Use filesystem extended attributes marking'
79932 + select CIFS_XATTR if CIFS
79933 + select EXT2_FS_XATTR if EXT2_FS
79934 + select EXT3_FS_XATTR if EXT3_FS
79935 + select EXT4_FS_XATTR if EXT4_FS
79936 + select JFFS2_FS_XATTR if JFFS2_FS
79937 + select REISERFS_FS_XATTR if REISERFS_FS
79938 + select SQUASHFS_XATTR if SQUASHFS
79939 + select TMPFS_XATTR if TMPFS
79940 + select UBIFS_FS_XATTR if UBIFS_FS
79941 + help
79942 + Enabling this option will allow you to control PaX features on
79943 + a per executable basis via the 'setfattr' utility. The control
79944 + flags will be read from the user.pax.flags extended attribute of
79945 + the file. This marking has the benefit of supporting binary-only
79946 + applications that self-check themselves (e.g., skype) and would
79947 + not tolerate chpax/paxctl changes. The main drawback is that
79948 + extended attributes are not supported by some filesystems (e.g.,
79949 + isofs, udf, vfat) so copying files through such filesystems will
79950 + lose the extended attributes and these PaX markings.
79951 +
79952 + If you have applications not marked by the PT_PAX_FLAGS ELF program
79953 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
79954 + support otherwise they will not get any protection.
79955 +
79956 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
79957 + must make sure that the marks are the same if a binary has both marks.
79958 +
79959 + Note that if you enable the legacy EI_PAX marking support as well,
79960 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
79961 +
79962 +choice
79963 + prompt 'MAC system integration'
79964 + default PAX_HAVE_ACL_FLAGS
79965 + help
79966 + Mandatory Access Control systems have the option of controlling
79967 + PaX flags on a per executable basis, choose the method supported
79968 + by your particular system.
79969 +
79970 + - "none": if your MAC system does not interact with PaX,
79971 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
79972 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
79973 +
79974 + NOTE: this option is for developers/integrators only.
79975 +
79976 + config PAX_NO_ACL_FLAGS
79977 + bool 'none'
79978 +
79979 + config PAX_HAVE_ACL_FLAGS
79980 + bool 'direct'
79981 +
79982 + config PAX_HOOK_ACL_FLAGS
79983 + bool 'hook'
79984 +endchoice
79985 +
79986 +endmenu
79987 +
79988 +menu "Non-executable pages"
79989 + depends on PAX
79990 +
79991 +config PAX_NOEXEC
79992 + bool "Enforce non-executable pages"
79993 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
79994 + help
79995 + By design some architectures do not allow for protecting memory
79996 + pages against execution or even if they do, Linux does not make
79997 + use of this feature. In practice this means that if a page is
79998 + readable (such as the stack or heap) it is also executable.
79999 +
80000 + There is a well known exploit technique that makes use of this
80001 + fact and a common programming mistake where an attacker can
80002 + introduce code of his choice somewhere in the attacked program's
80003 + memory (typically the stack or the heap) and then execute it.
80004 +
80005 + If the attacked program was running with different (typically
80006 + higher) privileges than that of the attacker, then he can elevate
80007 + his own privilege level (e.g. get a root shell, write to files for
80008 + which he does not have write access to, etc).
80009 +
80010 + Enabling this option will let you choose from various features
80011 + that prevent the injection and execution of 'foreign' code in
80012 + a program.
80013 +
80014 + This will also break programs that rely on the old behaviour and
80015 + expect that dynamically allocated memory via the malloc() family
80016 + of functions is executable (which it is not). Notable examples
80017 + are the XFree86 4.x server, the java runtime and wine.
80018 +
80019 +config PAX_PAGEEXEC
80020 + bool "Paging based non-executable pages"
80021 + 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)
80022 + select S390_SWITCH_AMODE if S390
80023 + select S390_EXEC_PROTECT if S390
80024 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80025 + help
80026 + This implementation is based on the paging feature of the CPU.
80027 + On i386 without hardware non-executable bit support there is a
80028 + variable but usually low performance impact, however on Intel's
80029 + P4 core based CPUs it is very high so you should not enable this
80030 + for kernels meant to be used on such CPUs.
80031 +
80032 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80033 + with hardware non-executable bit support there is no performance
80034 + impact, on ppc the impact is negligible.
80035 +
80036 + Note that several architectures require various emulations due to
80037 + badly designed userland ABIs, this will cause a performance impact
80038 + but will disappear as soon as userland is fixed. For example, ppc
80039 + userland MUST have been built with secure-plt by a recent toolchain.
80040 +
80041 +config PAX_SEGMEXEC
80042 + bool "Segmentation based non-executable pages"
80043 + depends on PAX_NOEXEC && X86_32
80044 + help
80045 + This implementation is based on the segmentation feature of the
80046 + CPU and has a very small performance impact, however applications
80047 + will be limited to a 1.5 GB address space instead of the normal
80048 + 3 GB.
80049 +
80050 +config PAX_EMUTRAMP
80051 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80052 + default y if PARISC
80053 + help
80054 + There are some programs and libraries that for one reason or
80055 + another attempt to execute special small code snippets from
80056 + non-executable memory pages. Most notable examples are the
80057 + signal handler return code generated by the kernel itself and
80058 + the GCC trampolines.
80059 +
80060 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80061 + such programs will no longer work under your kernel.
80062 +
80063 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80064 + utilities to enable trampoline emulation for the affected programs
80065 + yet still have the protection provided by the non-executable pages.
80066 +
80067 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80068 + your system will not even boot.
80069 +
80070 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80071 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80072 + for the affected files.
80073 +
80074 + NOTE: enabling this feature *may* open up a loophole in the
80075 + protection provided by non-executable pages that an attacker
80076 + could abuse. Therefore the best solution is to not have any
80077 + files on your system that would require this option. This can
80078 + be achieved by not using libc5 (which relies on the kernel
80079 + signal handler return code) and not using or rewriting programs
80080 + that make use of the nested function implementation of GCC.
80081 + Skilled users can just fix GCC itself so that it implements
80082 + nested function calls in a way that does not interfere with PaX.
80083 +
80084 +config PAX_EMUSIGRT
80085 + bool "Automatically emulate sigreturn trampolines"
80086 + depends on PAX_EMUTRAMP && PARISC
80087 + default y
80088 + help
80089 + Enabling this option will have the kernel automatically detect
80090 + and emulate signal return trampolines executing on the stack
80091 + that would otherwise lead to task termination.
80092 +
80093 + This solution is intended as a temporary one for users with
80094 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80095 + Modula-3 runtime, etc) or executables linked to such, basically
80096 + everything that does not specify its own SA_RESTORER function in
80097 + normal executable memory like glibc 2.1+ does.
80098 +
80099 + On parisc you MUST enable this option, otherwise your system will
80100 + not even boot.
80101 +
80102 + NOTE: this feature cannot be disabled on a per executable basis
80103 + and since it *does* open up a loophole in the protection provided
80104 + by non-executable pages, the best solution is to not have any
80105 + files on your system that would require this option.
80106 +
80107 +config PAX_MPROTECT
80108 + bool "Restrict mprotect()"
80109 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
80110 + help
80111 + Enabling this option will prevent programs from
80112 + - changing the executable status of memory pages that were
80113 + not originally created as executable,
80114 + - making read-only executable pages writable again,
80115 + - creating executable pages from anonymous memory,
80116 + - making read-only-after-relocations (RELRO) data pages writable again.
80117 +
80118 + You should say Y here to complete the protection provided by
80119 + the enforcement of non-executable pages.
80120 +
80121 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80122 + this feature on a per file basis.
80123 +
80124 +config PAX_MPROTECT_COMPAT
80125 + bool "Use legacy/compat protection demoting (read help)"
80126 + depends on PAX_MPROTECT
80127 + default n
80128 + help
80129 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
80130 + by sending the proper error code to the application. For some broken
80131 + userland, this can cause problems with Python or other applications. The
80132 + current implementation however allows for applications like clamav to
80133 + detect if JIT compilation/execution is allowed and to fall back gracefully
80134 + to an interpreter-based mode if it does not. While we encourage everyone
80135 + to use the current implementation as-is and push upstream to fix broken
80136 + userland (note that the RWX logging option can assist with this), in some
80137 + environments this may not be possible. Having to disable MPROTECT
80138 + completely on certain binaries reduces the security benefit of PaX,
80139 + so this option is provided for those environments to revert to the old
80140 + behavior.
80141 +
80142 +config PAX_ELFRELOCS
80143 + bool "Allow ELF text relocations (read help)"
80144 + depends on PAX_MPROTECT
80145 + default n
80146 + help
80147 + Non-executable pages and mprotect() restrictions are effective
80148 + in preventing the introduction of new executable code into an
80149 + attacked task's address space. There remain only two venues
80150 + for this kind of attack: if the attacker can execute already
80151 + existing code in the attacked task then he can either have it
80152 + create and mmap() a file containing his code or have it mmap()
80153 + an already existing ELF library that does not have position
80154 + independent code in it and use mprotect() on it to make it
80155 + writable and copy his code there. While protecting against
80156 + the former approach is beyond PaX, the latter can be prevented
80157 + by having only PIC ELF libraries on one's system (which do not
80158 + need to relocate their code). If you are sure this is your case,
80159 + as is the case with all modern Linux distributions, then leave
80160 + this option disabled. You should say 'n' here.
80161 +
80162 +config PAX_ETEXECRELOCS
80163 + bool "Allow ELF ET_EXEC text relocations"
80164 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
80165 + select PAX_ELFRELOCS
80166 + default y
80167 + help
80168 + On some architectures there are incorrectly created applications
80169 + that require text relocations and would not work without enabling
80170 + this option. If you are an alpha, ia64 or parisc user, you should
80171 + enable this option and disable it once you have made sure that
80172 + none of your applications need it.
80173 +
80174 +config PAX_EMUPLT
80175 + bool "Automatically emulate ELF PLT"
80176 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
80177 + default y
80178 + help
80179 + Enabling this option will have the kernel automatically detect
80180 + and emulate the Procedure Linkage Table entries in ELF files.
80181 + On some architectures such entries are in writable memory, and
80182 + become non-executable leading to task termination. Therefore
80183 + it is mandatory that you enable this option on alpha, parisc,
80184 + sparc and sparc64, otherwise your system would not even boot.
80185 +
80186 + NOTE: this feature *does* open up a loophole in the protection
80187 + provided by the non-executable pages, therefore the proper
80188 + solution is to modify the toolchain to produce a PLT that does
80189 + not need to be writable.
80190 +
80191 +config PAX_DLRESOLVE
80192 + bool 'Emulate old glibc resolver stub'
80193 + depends on PAX_EMUPLT && SPARC
80194 + default n
80195 + help
80196 + This option is needed if userland has an old glibc (before 2.4)
80197 + that puts a 'save' instruction into the runtime generated resolver
80198 + stub that needs special emulation.
80199 +
80200 +config PAX_KERNEXEC
80201 + bool "Enforce non-executable kernel pages"
80202 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
80203 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
80204 + select PAX_KERNEXEC_PLUGIN if X86_64
80205 + help
80206 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
80207 + that is, enabling this option will make it harder to inject
80208 + and execute 'foreign' code in kernel memory itself.
80209 +
80210 + Note that on x86_64 kernels there is a known regression when
80211 + this feature and KVM/VMX are both enabled in the host kernel.
80212 +
80213 +choice
80214 + prompt "Return Address Instrumentation Method"
80215 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
80216 + depends on PAX_KERNEXEC_PLUGIN
80217 + help
80218 + Select the method used to instrument function pointer dereferences.
80219 + Note that binary modules cannot be instrumented by this approach.
80220 +
80221 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
80222 + bool "bts"
80223 + help
80224 + This method is compatible with binary only modules but has
80225 + a higher runtime overhead.
80226 +
80227 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
80228 + bool "or"
80229 + depends on !PARAVIRT
80230 + help
80231 + This method is incompatible with binary only modules but has
80232 + a lower runtime overhead.
80233 +endchoice
80234 +
80235 +config PAX_KERNEXEC_PLUGIN_METHOD
80236 + string
80237 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
80238 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
80239 + default ""
80240 +
80241 +config PAX_KERNEXEC_MODULE_TEXT
80242 + int "Minimum amount of memory reserved for module code"
80243 + default "4"
80244 + depends on PAX_KERNEXEC && X86_32 && MODULES
80245 + help
80246 + Due to implementation details the kernel must reserve a fixed
80247 + amount of memory for module code at compile time that cannot be
80248 + changed at runtime. Here you can specify the minimum amount
80249 + in MB that will be reserved. Due to the same implementation
80250 + details this size will always be rounded up to the next 2/4 MB
80251 + boundary (depends on PAE) so the actually available memory for
80252 + module code will usually be more than this minimum.
80253 +
80254 + The default 4 MB should be enough for most users but if you have
80255 + an excessive number of modules (e.g., most distribution configs
80256 + compile many drivers as modules) or use huge modules such as
80257 + nvidia's kernel driver, you will need to adjust this amount.
80258 + A good rule of thumb is to look at your currently loaded kernel
80259 + modules and add up their sizes.
80260 +
80261 +endmenu
80262 +
80263 +menu "Address Space Layout Randomization"
80264 + depends on PAX
80265 +
80266 +config PAX_ASLR
80267 + bool "Address Space Layout Randomization"
80268 + help
80269 + Many if not most exploit techniques rely on the knowledge of
80270 + certain addresses in the attacked program. The following options
80271 + will allow the kernel to apply a certain amount of randomization
80272 + to specific parts of the program thereby forcing an attacker to
80273 + guess them in most cases. Any failed guess will most likely crash
80274 + the attacked program which allows the kernel to detect such attempts
80275 + and react on them. PaX itself provides no reaction mechanisms,
80276 + instead it is strongly encouraged that you make use of Nergal's
80277 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
80278 + (http://www.grsecurity.net/) built-in crash detection features or
80279 + develop one yourself.
80280 +
80281 + By saying Y here you can choose to randomize the following areas:
80282 + - top of the task's kernel stack
80283 + - top of the task's userland stack
80284 + - base address for mmap() requests that do not specify one
80285 + (this includes all libraries)
80286 + - base address of the main executable
80287 +
80288 + It is strongly recommended to say Y here as address space layout
80289 + randomization has negligible impact on performance yet it provides
80290 + a very effective protection.
80291 +
80292 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80293 + this feature on a per file basis.
80294 +
80295 +config PAX_RANDKSTACK
80296 + bool "Randomize kernel stack base"
80297 + depends on X86_TSC && X86
80298 + help
80299 + By saying Y here the kernel will randomize every task's kernel
80300 + stack on every system call. This will not only force an attacker
80301 + to guess it but also prevent him from making use of possible
80302 + leaked information about it.
80303 +
80304 + Since the kernel stack is a rather scarce resource, randomization
80305 + may cause unexpected stack overflows, therefore you should very
80306 + carefully test your system. Note that once enabled in the kernel
80307 + configuration, this feature cannot be disabled on a per file basis.
80308 +
80309 +config PAX_RANDUSTACK
80310 + bool "Randomize user stack base"
80311 + depends on PAX_ASLR
80312 + help
80313 + By saying Y here the kernel will randomize every task's userland
80314 + stack. The randomization is done in two steps where the second
80315 + one may apply a big amount of shift to the top of the stack and
80316 + cause problems for programs that want to use lots of memory (more
80317 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
80318 + For this reason the second step can be controlled by 'chpax' or
80319 + 'paxctl' on a per file basis.
80320 +
80321 +config PAX_RANDMMAP
80322 + bool "Randomize mmap() base"
80323 + depends on PAX_ASLR
80324 + help
80325 + By saying Y here the kernel will use a randomized base address for
80326 + mmap() requests that do not specify one themselves. As a result
80327 + all dynamically loaded libraries will appear at random addresses
80328 + and therefore be harder to exploit by a technique where an attacker
80329 + attempts to execute library code for his purposes (e.g. spawn a
80330 + shell from an exploited program that is running at an elevated
80331 + privilege level).
80332 +
80333 + Furthermore, if a program is relinked as a dynamic ELF file, its
80334 + base address will be randomized as well, completing the full
80335 + randomization of the address space layout. Attacking such programs
80336 + becomes a guess game. You can find an example of doing this at
80337 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
80338 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
80339 +
80340 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
80341 + feature on a per file basis.
80342 +
80343 +endmenu
80344 +
80345 +menu "Miscellaneous hardening features"
80346 +
80347 +config PAX_MEMORY_SANITIZE
80348 + bool "Sanitize all freed memory"
80349 + depends on !HIBERNATION
80350 + help
80351 + By saying Y here the kernel will erase memory pages as soon as they
80352 + are freed. This in turn reduces the lifetime of data stored in the
80353 + pages, making it less likely that sensitive information such as
80354 + passwords, cryptographic secrets, etc stay in memory for too long.
80355 +
80356 + This is especially useful for programs whose runtime is short, long
80357 + lived processes and the kernel itself benefit from this as long as
80358 + they operate on whole memory pages and ensure timely freeing of pages
80359 + that may hold sensitive information.
80360 +
80361 + The tradeoff is performance impact, on a single CPU system kernel
80362 + compilation sees a 3% slowdown, other systems and workloads may vary
80363 + and you are advised to test this feature on your expected workload
80364 + before deploying it.
80365 +
80366 + Note that this feature does not protect data stored in live pages,
80367 + e.g., process memory swapped to disk may stay there for a long time.
80368 +
80369 +config PAX_MEMORY_STACKLEAK
80370 + bool "Sanitize kernel stack"
80371 + depends on X86
80372 + help
80373 + By saying Y here the kernel will erase the kernel stack before it
80374 + returns from a system call. This in turn reduces the information
80375 + that a kernel stack leak bug can reveal.
80376 +
80377 + Note that such a bug can still leak information that was put on
80378 + the stack by the current system call (the one eventually triggering
80379 + the bug) but traces of earlier system calls on the kernel stack
80380 + cannot leak anymore.
80381 +
80382 + The tradeoff is performance impact: on a single CPU system kernel
80383 + compilation sees a 1% slowdown, other systems and workloads may vary
80384 + and you are advised to test this feature on your expected workload
80385 + before deploying it.
80386 +
80387 + Note: full support for this feature requires gcc with plugin support
80388 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
80389 + versions means that functions with large enough stack frames may
80390 + leave uninitialized memory behind that may be exposed to a later
80391 + syscall leaking the stack.
80392 +
80393 +config PAX_MEMORY_UDEREF
80394 + bool "Prevent invalid userland pointer dereference"
80395 + depends on X86 && !UML_X86 && !XEN
80396 + select PAX_PER_CPU_PGD if X86_64
80397 + help
80398 + By saying Y here the kernel will be prevented from dereferencing
80399 + userland pointers in contexts where the kernel expects only kernel
80400 + pointers. This is both a useful runtime debugging feature and a
80401 + security measure that prevents exploiting a class of kernel bugs.
80402 +
80403 + The tradeoff is that some virtualization solutions may experience
80404 + a huge slowdown and therefore you should not enable this feature
80405 + for kernels meant to run in such environments. Whether a given VM
80406 + solution is affected or not is best determined by simply trying it
80407 + out, the performance impact will be obvious right on boot as this
80408 + mechanism engages from very early on. A good rule of thumb is that
80409 + VMs running on CPUs without hardware virtualization support (i.e.,
80410 + the majority of IA-32 CPUs) will likely experience the slowdown.
80411 +
80412 +config PAX_REFCOUNT
80413 + bool "Prevent various kernel object reference counter overflows"
80414 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
80415 + help
80416 + By saying Y here the kernel will detect and prevent overflowing
80417 + various (but not all) kinds of object reference counters. Such
80418 + overflows can normally occur due to bugs only and are often, if
80419 + not always, exploitable.
80420 +
80421 + The tradeoff is that data structures protected by an overflowed
80422 + refcount will never be freed and therefore will leak memory. Note
80423 + that this leak also happens even without this protection but in
80424 + that case the overflow can eventually trigger the freeing of the
80425 + data structure while it is still being used elsewhere, resulting
80426 + in the exploitable situation that this feature prevents.
80427 +
80428 + Since this has a negligible performance impact, you should enable
80429 + this feature.
80430 +
80431 +config PAX_USERCOPY
80432 + bool "Harden heap object copies between kernel and userland"
80433 + depends on X86 || PPC || SPARC || ARM
80434 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
80435 + help
80436 + By saying Y here the kernel will enforce the size of heap objects
80437 + when they are copied in either direction between the kernel and
80438 + userland, even if only a part of the heap object is copied.
80439 +
80440 + Specifically, this checking prevents information leaking from the
80441 + kernel heap during kernel to userland copies (if the kernel heap
80442 + object is otherwise fully initialized) and prevents kernel heap
80443 + overflows during userland to kernel copies.
80444 +
80445 + Note that the current implementation provides the strictest bounds
80446 + checks for the SLUB allocator.
80447 +
80448 + Enabling this option also enables per-slab cache protection against
80449 + data in a given cache being copied into/out of via userland
80450 + accessors. Though the whitelist of regions will be reduced over
80451 + time, it notably protects important data structures like task structs.
80452 +
80453 + If frame pointers are enabled on x86, this option will also restrict
80454 + copies into and out of the kernel stack to local variables within a
80455 + single frame.
80456 +
80457 + Since this has a negligible performance impact, you should enable
80458 + this feature.
80459 +
80460 +config PAX_SIZE_OVERFLOW
80461 + bool "Prevent various integer overflows in function size parameters"
80462 + depends on X86
80463 + help
80464 + By saying Y here the kernel recomputes expressions of function
80465 + arguments marked by a size_overflow attribute with double integer
80466 + precision (DImode/TImode for 32/64 bit integer types).
80467 +
80468 + The recomputed argument is checked against INT_MAX and an event
80469 + is logged on overflow and the triggering process is killed.
80470 +
80471 + Homepage:
80472 + http://www.grsecurity.net/~ephox/overflow_plugin/
80473 +
80474 +endmenu
80475 +
80476 +endmenu
80477 +
80478 config KEYS
80479 bool "Enable access key retention support"
80480 help
80481 @@ -169,7 +803,7 @@ config INTEL_TXT
80482 config LSM_MMAP_MIN_ADDR
80483 int "Low address space for LSM to protect from user allocation"
80484 depends on SECURITY && SECURITY_SELINUX
80485 - default 32768 if ARM
80486 + default 32768 if ALPHA || ARM || PARISC || SPARC32
80487 default 65536
80488 help
80489 This is the portion of low virtual memory which should be protected
80490 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
80491 index 97ce8fa..23dad96 100644
80492 --- a/security/apparmor/lsm.c
80493 +++ b/security/apparmor/lsm.c
80494 @@ -620,7 +620,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
80495 return error;
80496 }
80497
80498 -static struct security_operations apparmor_ops = {
80499 +static struct security_operations apparmor_ops __read_only = {
80500 .name = "apparmor",
80501
80502 .ptrace_access_check = apparmor_ptrace_access_check,
80503 diff --git a/security/commoncap.c b/security/commoncap.c
80504 index b8d2bb9..980069e 100644
80505 --- a/security/commoncap.c
80506 +++ b/security/commoncap.c
80507 @@ -29,6 +29,7 @@
80508 #include <linux/securebits.h>
80509 #include <linux/user_namespace.h>
80510 #include <linux/personality.h>
80511 +#include <net/sock.h>
80512
80513 /*
80514 * If a non-root user executes a setuid-root binary in
80515 @@ -575,6 +576,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
80516 {
80517 const struct cred *cred = current_cred();
80518
80519 + if (gr_acl_enable_at_secure())
80520 + return 1;
80521 +
80522 if (cred->uid != 0) {
80523 if (bprm->cap_effective)
80524 return 1;
80525 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
80526 index 3ccf7ac..d73ad64 100644
80527 --- a/security/integrity/ima/ima.h
80528 +++ b/security/integrity/ima/ima.h
80529 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80530 extern spinlock_t ima_queue_lock;
80531
80532 struct ima_h_table {
80533 - atomic_long_t len; /* number of stored measurements in the list */
80534 - atomic_long_t violations;
80535 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
80536 + atomic_long_unchecked_t violations;
80537 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
80538 };
80539 extern struct ima_h_table ima_htable;
80540 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
80541 index 88a2788..581ab92 100644
80542 --- a/security/integrity/ima/ima_api.c
80543 +++ b/security/integrity/ima/ima_api.c
80544 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
80545 int result;
80546
80547 /* can overflow, only indicator */
80548 - atomic_long_inc(&ima_htable.violations);
80549 + atomic_long_inc_unchecked(&ima_htable.violations);
80550
80551 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
80552 if (!entry) {
80553 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
80554 index e1aa2b4..52027bf 100644
80555 --- a/security/integrity/ima/ima_fs.c
80556 +++ b/security/integrity/ima/ima_fs.c
80557 @@ -28,12 +28,12 @@
80558 static int valid_policy = 1;
80559 #define TMPBUFLEN 12
80560 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
80561 - loff_t *ppos, atomic_long_t *val)
80562 + loff_t *ppos, atomic_long_unchecked_t *val)
80563 {
80564 char tmpbuf[TMPBUFLEN];
80565 ssize_t len;
80566
80567 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
80568 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
80569 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
80570 }
80571
80572 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
80573 index 55a6271..ad829c3 100644
80574 --- a/security/integrity/ima/ima_queue.c
80575 +++ b/security/integrity/ima/ima_queue.c
80576 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
80577 INIT_LIST_HEAD(&qe->later);
80578 list_add_tail_rcu(&qe->later, &ima_measurements);
80579
80580 - atomic_long_inc(&ima_htable.len);
80581 + atomic_long_inc_unchecked(&ima_htable.len);
80582 key = ima_hash_key(entry->digest);
80583 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
80584 return 0;
80585 diff --git a/security/keys/compat.c b/security/keys/compat.c
80586 index 4c48e13..7abdac9 100644
80587 --- a/security/keys/compat.c
80588 +++ b/security/keys/compat.c
80589 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
80590 if (ret == 0)
80591 goto no_payload_free;
80592
80593 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80594 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80595
80596 if (iov != iovstack)
80597 kfree(iov);
80598 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
80599 index 0b3f5d7..892c8a6 100644
80600 --- a/security/keys/keyctl.c
80601 +++ b/security/keys/keyctl.c
80602 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
80603 /*
80604 * Copy the iovec data from userspace
80605 */
80606 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80607 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
80608 unsigned ioc)
80609 {
80610 for (; ioc > 0; ioc--) {
80611 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
80612 * If successful, 0 will be returned.
80613 */
80614 long keyctl_instantiate_key_common(key_serial_t id,
80615 - const struct iovec *payload_iov,
80616 + const struct iovec __user *payload_iov,
80617 unsigned ioc,
80618 size_t plen,
80619 key_serial_t ringid)
80620 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
80621 [0].iov_len = plen
80622 };
80623
80624 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
80625 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
80626 }
80627
80628 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
80629 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
80630 if (ret == 0)
80631 goto no_payload_free;
80632
80633 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
80634 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
80635
80636 if (iov != iovstack)
80637 kfree(iov);
80638 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
80639 index d605f75..2bc6be9 100644
80640 --- a/security/keys/keyring.c
80641 +++ b/security/keys/keyring.c
80642 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
80643 ret = -EFAULT;
80644
80645 for (loop = 0; loop < klist->nkeys; loop++) {
80646 + key_serial_t serial;
80647 key = klist->keys[loop];
80648 + serial = key->serial;
80649
80650 tmp = sizeof(key_serial_t);
80651 if (tmp > buflen)
80652 tmp = buflen;
80653
80654 - if (copy_to_user(buffer,
80655 - &key->serial,
80656 - tmp) != 0)
80657 + if (copy_to_user(buffer, &serial, tmp))
80658 goto error;
80659
80660 buflen -= tmp;
80661 diff --git a/security/min_addr.c b/security/min_addr.c
80662 index f728728..6457a0c 100644
80663 --- a/security/min_addr.c
80664 +++ b/security/min_addr.c
80665 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
80666 */
80667 static void update_mmap_min_addr(void)
80668 {
80669 +#ifndef SPARC
80670 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
80671 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
80672 mmap_min_addr = dac_mmap_min_addr;
80673 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
80674 #else
80675 mmap_min_addr = dac_mmap_min_addr;
80676 #endif
80677 +#endif
80678 }
80679
80680 /*
80681 diff --git a/security/security.c b/security/security.c
80682 index d754249..8bf426e 100644
80683 --- a/security/security.c
80684 +++ b/security/security.c
80685 @@ -26,8 +26,8 @@
80686 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
80687 CONFIG_DEFAULT_SECURITY;
80688
80689 -static struct security_operations *security_ops;
80690 -static struct security_operations default_security_ops = {
80691 +static struct security_operations *security_ops __read_only;
80692 +static struct security_operations default_security_ops __read_only = {
80693 .name = "default",
80694 };
80695
80696 @@ -68,7 +68,9 @@ int __init security_init(void)
80697
80698 void reset_security_ops(void)
80699 {
80700 + pax_open_kernel();
80701 security_ops = &default_security_ops;
80702 + pax_close_kernel();
80703 }
80704
80705 /* Save user chosen LSM */
80706 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
80707 index 6a3683e..f52f4c0 100644
80708 --- a/security/selinux/hooks.c
80709 +++ b/security/selinux/hooks.c
80710 @@ -94,8 +94,6 @@
80711
80712 #define NUM_SEL_MNT_OPTS 5
80713
80714 -extern struct security_operations *security_ops;
80715 -
80716 /* SECMARK reference count */
80717 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
80718
80719 @@ -5429,7 +5427,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
80720
80721 #endif
80722
80723 -static struct security_operations selinux_ops = {
80724 +static struct security_operations selinux_ops __read_only = {
80725 .name = "selinux",
80726
80727 .ptrace_access_check = selinux_ptrace_access_check,
80728 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
80729 index b43813c..74be837 100644
80730 --- a/security/selinux/include/xfrm.h
80731 +++ b/security/selinux/include/xfrm.h
80732 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
80733
80734 static inline void selinux_xfrm_notify_policyload(void)
80735 {
80736 - atomic_inc(&flow_cache_genid);
80737 + atomic_inc_unchecked(&flow_cache_genid);
80738 }
80739 #else
80740 static inline int selinux_xfrm_enabled(void)
80741 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
80742 index e8af5b0b..78527ef 100644
80743 --- a/security/smack/smack_lsm.c
80744 +++ b/security/smack/smack_lsm.c
80745 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
80746 return 0;
80747 }
80748
80749 -struct security_operations smack_ops = {
80750 +struct security_operations smack_ops __read_only = {
80751 .name = "smack",
80752
80753 .ptrace_access_check = smack_ptrace_access_check,
80754 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
80755 index 620d37c..e2ad89b 100644
80756 --- a/security/tomoyo/tomoyo.c
80757 +++ b/security/tomoyo/tomoyo.c
80758 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
80759 * tomoyo_security_ops is a "struct security_operations" which is used for
80760 * registering TOMOYO.
80761 */
80762 -static struct security_operations tomoyo_security_ops = {
80763 +static struct security_operations tomoyo_security_ops __read_only = {
80764 .name = "tomoyo",
80765 .cred_alloc_blank = tomoyo_cred_alloc_blank,
80766 .cred_prepare = tomoyo_cred_prepare,
80767 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
80768 index 762af68..7103453 100644
80769 --- a/sound/aoa/codecs/onyx.c
80770 +++ b/sound/aoa/codecs/onyx.c
80771 @@ -54,7 +54,7 @@ struct onyx {
80772 spdif_locked:1,
80773 analog_locked:1,
80774 original_mute:2;
80775 - int open_count;
80776 + local_t open_count;
80777 struct codec_info *codec_info;
80778
80779 /* mutex serializes concurrent access to the device
80780 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
80781 struct onyx *onyx = cii->codec_data;
80782
80783 mutex_lock(&onyx->mutex);
80784 - onyx->open_count++;
80785 + local_inc(&onyx->open_count);
80786 mutex_unlock(&onyx->mutex);
80787
80788 return 0;
80789 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
80790 struct onyx *onyx = cii->codec_data;
80791
80792 mutex_lock(&onyx->mutex);
80793 - onyx->open_count--;
80794 - if (!onyx->open_count)
80795 + if (local_dec_and_test(&onyx->open_count))
80796 onyx->spdif_locked = onyx->analog_locked = 0;
80797 mutex_unlock(&onyx->mutex);
80798
80799 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
80800 index ffd2025..df062c9 100644
80801 --- a/sound/aoa/codecs/onyx.h
80802 +++ b/sound/aoa/codecs/onyx.h
80803 @@ -11,6 +11,7 @@
80804 #include <linux/i2c.h>
80805 #include <asm/pmac_low_i2c.h>
80806 #include <asm/prom.h>
80807 +#include <asm/local.h>
80808
80809 /* PCM3052 register definitions */
80810
80811 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
80812 index 08fde00..0bf641a 100644
80813 --- a/sound/core/oss/pcm_oss.c
80814 +++ b/sound/core/oss/pcm_oss.c
80815 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
80816 if (in_kernel) {
80817 mm_segment_t fs;
80818 fs = snd_enter_user();
80819 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80820 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80821 snd_leave_user(fs);
80822 } else {
80823 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
80824 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
80825 }
80826 if (ret != -EPIPE && ret != -ESTRPIPE)
80827 break;
80828 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
80829 if (in_kernel) {
80830 mm_segment_t fs;
80831 fs = snd_enter_user();
80832 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80833 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80834 snd_leave_user(fs);
80835 } else {
80836 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
80837 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
80838 }
80839 if (ret == -EPIPE) {
80840 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
80841 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
80842 struct snd_pcm_plugin_channel *channels;
80843 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
80844 if (!in_kernel) {
80845 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
80846 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
80847 return -EFAULT;
80848 buf = runtime->oss.buffer;
80849 }
80850 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
80851 }
80852 } else {
80853 tmp = snd_pcm_oss_write2(substream,
80854 - (const char __force *)buf,
80855 + (const char __force_kernel *)buf,
80856 runtime->oss.period_bytes, 0);
80857 if (tmp <= 0)
80858 goto err;
80859 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
80860 struct snd_pcm_runtime *runtime = substream->runtime;
80861 snd_pcm_sframes_t frames, frames1;
80862 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
80863 - char __user *final_dst = (char __force __user *)buf;
80864 + char __user *final_dst = (char __force_user *)buf;
80865 if (runtime->oss.plugin_first) {
80866 struct snd_pcm_plugin_channel *channels;
80867 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
80868 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
80869 xfer += tmp;
80870 runtime->oss.buffer_used -= tmp;
80871 } else {
80872 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
80873 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
80874 runtime->oss.period_bytes, 0);
80875 if (tmp <= 0)
80876 goto err;
80877 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
80878 size1);
80879 size1 /= runtime->channels; /* frames */
80880 fs = snd_enter_user();
80881 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
80882 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
80883 snd_leave_user(fs);
80884 }
80885 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
80886 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
80887 index 91cdf94..4085161 100644
80888 --- a/sound/core/pcm_compat.c
80889 +++ b/sound/core/pcm_compat.c
80890 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
80891 int err;
80892
80893 fs = snd_enter_user();
80894 - err = snd_pcm_delay(substream, &delay);
80895 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
80896 snd_leave_user(fs);
80897 if (err < 0)
80898 return err;
80899 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
80900 index 25ed9fe..24c46e9 100644
80901 --- a/sound/core/pcm_native.c
80902 +++ b/sound/core/pcm_native.c
80903 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
80904 switch (substream->stream) {
80905 case SNDRV_PCM_STREAM_PLAYBACK:
80906 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
80907 - (void __user *)arg);
80908 + (void __force_user *)arg);
80909 break;
80910 case SNDRV_PCM_STREAM_CAPTURE:
80911 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
80912 - (void __user *)arg);
80913 + (void __force_user *)arg);
80914 break;
80915 default:
80916 result = -EINVAL;
80917 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
80918 index 5cf8d65..912a79c 100644
80919 --- a/sound/core/seq/seq_device.c
80920 +++ b/sound/core/seq/seq_device.c
80921 @@ -64,7 +64,7 @@ struct ops_list {
80922 int argsize; /* argument size */
80923
80924 /* operators */
80925 - struct snd_seq_dev_ops ops;
80926 + struct snd_seq_dev_ops *ops;
80927
80928 /* registred devices */
80929 struct list_head dev_list; /* list of devices */
80930 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
80931
80932 mutex_lock(&ops->reg_mutex);
80933 /* copy driver operators */
80934 - ops->ops = *entry;
80935 + ops->ops = entry;
80936 ops->driver |= DRIVER_LOADED;
80937 ops->argsize = argsize;
80938
80939 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
80940 dev->name, ops->id, ops->argsize, dev->argsize);
80941 return -EINVAL;
80942 }
80943 - if (ops->ops.init_device(dev) >= 0) {
80944 + if (ops->ops->init_device(dev) >= 0) {
80945 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
80946 ops->num_init_devices++;
80947 } else {
80948 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
80949 dev->name, ops->id, ops->argsize, dev->argsize);
80950 return -EINVAL;
80951 }
80952 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
80953 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
80954 dev->status = SNDRV_SEQ_DEVICE_FREE;
80955 dev->driver_data = NULL;
80956 ops->num_init_devices--;
80957 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
80958 index 621e60e..f4543f5 100644
80959 --- a/sound/drivers/mts64.c
80960 +++ b/sound/drivers/mts64.c
80961 @@ -29,6 +29,7 @@
80962 #include <sound/initval.h>
80963 #include <sound/rawmidi.h>
80964 #include <sound/control.h>
80965 +#include <asm/local.h>
80966
80967 #define CARD_NAME "Miditerminal 4140"
80968 #define DRIVER_NAME "MTS64"
80969 @@ -67,7 +68,7 @@ struct mts64 {
80970 struct pardevice *pardev;
80971 int pardev_claimed;
80972
80973 - int open_count;
80974 + local_t open_count;
80975 int current_midi_output_port;
80976 int current_midi_input_port;
80977 u8 mode[MTS64_NUM_INPUT_PORTS];
80978 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80979 {
80980 struct mts64 *mts = substream->rmidi->private_data;
80981
80982 - if (mts->open_count == 0) {
80983 + if (local_read(&mts->open_count) == 0) {
80984 /* We don't need a spinlock here, because this is just called
80985 if the device has not been opened before.
80986 So there aren't any IRQs from the device */
80987 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
80988
80989 msleep(50);
80990 }
80991 - ++(mts->open_count);
80992 + local_inc(&mts->open_count);
80993
80994 return 0;
80995 }
80996 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
80997 struct mts64 *mts = substream->rmidi->private_data;
80998 unsigned long flags;
80999
81000 - --(mts->open_count);
81001 - if (mts->open_count == 0) {
81002 + if (local_dec_return(&mts->open_count) == 0) {
81003 /* We need the spinlock_irqsave here because we can still
81004 have IRQs at this point */
81005 spin_lock_irqsave(&mts->lock, flags);
81006 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81007
81008 msleep(500);
81009
81010 - } else if (mts->open_count < 0)
81011 - mts->open_count = 0;
81012 + } else if (local_read(&mts->open_count) < 0)
81013 + local_set(&mts->open_count, 0);
81014
81015 return 0;
81016 }
81017 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
81018 index b953fb4..1999c01 100644
81019 --- a/sound/drivers/opl4/opl4_lib.c
81020 +++ b/sound/drivers/opl4/opl4_lib.c
81021 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
81022 MODULE_DESCRIPTION("OPL4 driver");
81023 MODULE_LICENSE("GPL");
81024
81025 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
81026 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
81027 {
81028 int timeout = 10;
81029 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
81030 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
81031 index 3e32bd3..46fc152 100644
81032 --- a/sound/drivers/portman2x4.c
81033 +++ b/sound/drivers/portman2x4.c
81034 @@ -48,6 +48,7 @@
81035 #include <sound/initval.h>
81036 #include <sound/rawmidi.h>
81037 #include <sound/control.h>
81038 +#include <asm/local.h>
81039
81040 #define CARD_NAME "Portman 2x4"
81041 #define DRIVER_NAME "portman"
81042 @@ -85,7 +86,7 @@ struct portman {
81043 struct pardevice *pardev;
81044 int pardev_claimed;
81045
81046 - int open_count;
81047 + local_t open_count;
81048 int mode[PORTMAN_NUM_INPUT_PORTS];
81049 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
81050 };
81051 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
81052 index 87657dd..a8268d4 100644
81053 --- a/sound/firewire/amdtp.c
81054 +++ b/sound/firewire/amdtp.c
81055 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
81056 ptr = s->pcm_buffer_pointer + data_blocks;
81057 if (ptr >= pcm->runtime->buffer_size)
81058 ptr -= pcm->runtime->buffer_size;
81059 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
81060 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
81061
81062 s->pcm_period_pointer += data_blocks;
81063 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
81064 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
81065 */
81066 void amdtp_out_stream_update(struct amdtp_out_stream *s)
81067 {
81068 - ACCESS_ONCE(s->source_node_id_field) =
81069 + ACCESS_ONCE_RW(s->source_node_id_field) =
81070 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
81071 }
81072 EXPORT_SYMBOL(amdtp_out_stream_update);
81073 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
81074 index 537a9cb..8e8c8e9 100644
81075 --- a/sound/firewire/amdtp.h
81076 +++ b/sound/firewire/amdtp.h
81077 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
81078 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
81079 struct snd_pcm_substream *pcm)
81080 {
81081 - ACCESS_ONCE(s->pcm) = pcm;
81082 + ACCESS_ONCE_RW(s->pcm) = pcm;
81083 }
81084
81085 /**
81086 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
81087 index cd094ec..eca1277 100644
81088 --- a/sound/firewire/isight.c
81089 +++ b/sound/firewire/isight.c
81090 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
81091 ptr += count;
81092 if (ptr >= runtime->buffer_size)
81093 ptr -= runtime->buffer_size;
81094 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
81095 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
81096
81097 isight->period_counter += count;
81098 if (isight->period_counter >= runtime->period_size) {
81099 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
81100 if (err < 0)
81101 return err;
81102
81103 - ACCESS_ONCE(isight->pcm_active) = true;
81104 + ACCESS_ONCE_RW(isight->pcm_active) = true;
81105
81106 return 0;
81107 }
81108 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
81109 {
81110 struct isight *isight = substream->private_data;
81111
81112 - ACCESS_ONCE(isight->pcm_active) = false;
81113 + ACCESS_ONCE_RW(isight->pcm_active) = false;
81114
81115 mutex_lock(&isight->mutex);
81116 isight_stop_streaming(isight);
81117 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
81118
81119 switch (cmd) {
81120 case SNDRV_PCM_TRIGGER_START:
81121 - ACCESS_ONCE(isight->pcm_running) = true;
81122 + ACCESS_ONCE_RW(isight->pcm_running) = true;
81123 break;
81124 case SNDRV_PCM_TRIGGER_STOP:
81125 - ACCESS_ONCE(isight->pcm_running) = false;
81126 + ACCESS_ONCE_RW(isight->pcm_running) = false;
81127 break;
81128 default:
81129 return -EINVAL;
81130 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
81131 index 7bd5e33..1fcab12 100644
81132 --- a/sound/isa/cmi8330.c
81133 +++ b/sound/isa/cmi8330.c
81134 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
81135
81136 struct snd_pcm *pcm;
81137 struct snd_cmi8330_stream {
81138 - struct snd_pcm_ops ops;
81139 + snd_pcm_ops_no_const ops;
81140 snd_pcm_open_callback_t open;
81141 void *private_data; /* sb or wss */
81142 } streams[2];
81143 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
81144 index 733b014..56ce96f 100644
81145 --- a/sound/oss/sb_audio.c
81146 +++ b/sound/oss/sb_audio.c
81147 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
81148 buf16 = (signed short *)(localbuf + localoffs);
81149 while (c)
81150 {
81151 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81152 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81153 if (copy_from_user(lbuf8,
81154 userbuf+useroffs + p,
81155 locallen))
81156 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
81157 index 09d4648..cf234c7 100644
81158 --- a/sound/oss/swarm_cs4297a.c
81159 +++ b/sound/oss/swarm_cs4297a.c
81160 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
81161 {
81162 struct cs4297a_state *s;
81163 u32 pwr, id;
81164 - mm_segment_t fs;
81165 int rval;
81166 #ifndef CONFIG_BCM_CS4297A_CSWARM
81167 u64 cfg;
81168 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
81169 if (!rval) {
81170 char *sb1250_duart_present;
81171
81172 +#if 0
81173 + mm_segment_t fs;
81174 fs = get_fs();
81175 set_fs(KERNEL_DS);
81176 -#if 0
81177 val = SOUND_MASK_LINE;
81178 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
81179 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
81180 val = initvol[i].vol;
81181 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
81182 }
81183 + set_fs(fs);
81184 // cs4297a_write_ac97(s, 0x18, 0x0808);
81185 #else
81186 // cs4297a_write_ac97(s, 0x5e, 0x180);
81187 cs4297a_write_ac97(s, 0x02, 0x0808);
81188 cs4297a_write_ac97(s, 0x18, 0x0808);
81189 #endif
81190 - set_fs(fs);
81191
81192 list_add(&s->list, &cs4297a_devs);
81193
81194 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
81195 index f0f1943..8e1f96c 100644
81196 --- a/sound/pci/hda/hda_codec.h
81197 +++ b/sound/pci/hda/hda_codec.h
81198 @@ -611,7 +611,7 @@ struct hda_bus_ops {
81199 /* notify power-up/down from codec to controller */
81200 void (*pm_notify)(struct hda_bus *bus);
81201 #endif
81202 -};
81203 +} __no_const;
81204
81205 /* template to pass to the bus constructor */
81206 struct hda_bus_template {
81207 @@ -713,6 +713,7 @@ struct hda_codec_ops {
81208 #endif
81209 void (*reboot_notify)(struct hda_codec *codec);
81210 };
81211 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
81212
81213 /* record for amp information cache */
81214 struct hda_cache_head {
81215 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
81216 struct snd_pcm_substream *substream);
81217 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
81218 struct snd_pcm_substream *substream);
81219 -};
81220 +} __no_const;
81221
81222 /* PCM information for each substream */
81223 struct hda_pcm_stream {
81224 @@ -801,7 +802,7 @@ struct hda_codec {
81225 const char *modelname; /* model name for preset */
81226
81227 /* set by patch */
81228 - struct hda_codec_ops patch_ops;
81229 + hda_codec_ops_no_const patch_ops;
81230
81231 /* PCM to create, set by patch_ops.build_pcms callback */
81232 unsigned int num_pcms;
81233 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
81234 index 0da778a..bc38b84 100644
81235 --- a/sound/pci/ice1712/ice1712.h
81236 +++ b/sound/pci/ice1712/ice1712.h
81237 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
81238 unsigned int mask_flags; /* total mask bits */
81239 struct snd_akm4xxx_ops {
81240 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
81241 - } ops;
81242 + } __no_const ops;
81243 };
81244
81245 struct snd_ice1712_spdif {
81246 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
81247 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81248 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81249 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81250 - } ops;
81251 + } __no_const ops;
81252 };
81253
81254
81255 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
81256 index 12a9a2b..2b6138f 100644
81257 --- a/sound/pci/ymfpci/ymfpci_main.c
81258 +++ b/sound/pci/ymfpci/ymfpci_main.c
81259 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
81260 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
81261 break;
81262 }
81263 - if (atomic_read(&chip->interrupt_sleep_count)) {
81264 - atomic_set(&chip->interrupt_sleep_count, 0);
81265 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81266 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81267 wake_up(&chip->interrupt_sleep);
81268 }
81269 __end:
81270 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
81271 continue;
81272 init_waitqueue_entry(&wait, current);
81273 add_wait_queue(&chip->interrupt_sleep, &wait);
81274 - atomic_inc(&chip->interrupt_sleep_count);
81275 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
81276 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
81277 remove_wait_queue(&chip->interrupt_sleep, &wait);
81278 }
81279 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
81280 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
81281 spin_unlock(&chip->reg_lock);
81282
81283 - if (atomic_read(&chip->interrupt_sleep_count)) {
81284 - atomic_set(&chip->interrupt_sleep_count, 0);
81285 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81286 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81287 wake_up(&chip->interrupt_sleep);
81288 }
81289 }
81290 @@ -2389,7 +2389,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
81291 spin_lock_init(&chip->reg_lock);
81292 spin_lock_init(&chip->voice_lock);
81293 init_waitqueue_head(&chip->interrupt_sleep);
81294 - atomic_set(&chip->interrupt_sleep_count, 0);
81295 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81296 chip->card = card;
81297 chip->pci = pci;
81298 chip->irq = -1;
81299 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
81300 index cdc860a..db34a93 100644
81301 --- a/sound/soc/soc-pcm.c
81302 +++ b/sound/soc/soc-pcm.c
81303 @@ -605,7 +605,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
81304 struct snd_soc_platform *platform = rtd->platform;
81305 struct snd_soc_dai *codec_dai = rtd->codec_dai;
81306 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
81307 - struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
81308 + snd_pcm_ops_no_const *soc_pcm_ops = &rtd->ops;
81309 struct snd_pcm *pcm;
81310 char new_name[64];
81311 int ret = 0, playback = 0, capture = 0;
81312 diff --git a/sound/usb/card.h b/sound/usb/card.h
81313 index da5fa1a..113cd02 100644
81314 --- a/sound/usb/card.h
81315 +++ b/sound/usb/card.h
81316 @@ -45,6 +45,7 @@ struct snd_urb_ops {
81317 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
81318 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
81319 };
81320 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
81321
81322 struct snd_usb_substream {
81323 struct snd_usb_stream *stream;
81324 @@ -94,7 +95,7 @@ struct snd_usb_substream {
81325 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
81326 spinlock_t lock;
81327
81328 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
81329 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
81330 int last_frame_number; /* stored frame number */
81331 int last_delay; /* stored delay */
81332 };
81333 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
81334 new file mode 100644
81335 index 0000000..ca64170
81336 --- /dev/null
81337 +++ b/tools/gcc/Makefile
81338 @@ -0,0 +1,26 @@
81339 +#CC := gcc
81340 +#PLUGIN_SOURCE_FILES := pax_plugin.c
81341 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
81342 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
81343 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
81344 +
81345 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
81346 +CFLAGS_size_overflow_plugin.o := -Wno-missing-initializer
81347 +
81348 +hostlibs-y := constify_plugin.so
81349 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
81350 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
81351 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
81352 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
81353 +hostlibs-y += colorize_plugin.so
81354 +hostlibs-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
81355 +
81356 +always := $(hostlibs-y)
81357 +
81358 +constify_plugin-objs := constify_plugin.o
81359 +stackleak_plugin-objs := stackleak_plugin.o
81360 +kallocstat_plugin-objs := kallocstat_plugin.o
81361 +kernexec_plugin-objs := kernexec_plugin.o
81362 +checker_plugin-objs := checker_plugin.o
81363 +colorize_plugin-objs := colorize_plugin.o
81364 +size_overflow_plugin-objs := size_overflow_plugin.o
81365 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
81366 new file mode 100644
81367 index 0000000..d41b5af
81368 --- /dev/null
81369 +++ b/tools/gcc/checker_plugin.c
81370 @@ -0,0 +1,171 @@
81371 +/*
81372 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81373 + * Licensed under the GPL v2
81374 + *
81375 + * Note: the choice of the license means that the compilation process is
81376 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81377 + * but for the kernel it doesn't matter since it doesn't link against
81378 + * any of the gcc libraries
81379 + *
81380 + * gcc plugin to implement various sparse (source code checker) features
81381 + *
81382 + * TODO:
81383 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
81384 + *
81385 + * BUGS:
81386 + * - none known
81387 + */
81388 +#include "gcc-plugin.h"
81389 +#include "config.h"
81390 +#include "system.h"
81391 +#include "coretypes.h"
81392 +#include "tree.h"
81393 +#include "tree-pass.h"
81394 +#include "flags.h"
81395 +#include "intl.h"
81396 +#include "toplev.h"
81397 +#include "plugin.h"
81398 +//#include "expr.h" where are you...
81399 +#include "diagnostic.h"
81400 +#include "plugin-version.h"
81401 +#include "tm.h"
81402 +#include "function.h"
81403 +#include "basic-block.h"
81404 +#include "gimple.h"
81405 +#include "rtl.h"
81406 +#include "emit-rtl.h"
81407 +#include "tree-flow.h"
81408 +#include "target.h"
81409 +
81410 +extern void c_register_addr_space (const char *str, addr_space_t as);
81411 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
81412 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
81413 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
81414 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
81415 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
81416 +
81417 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81418 +extern rtx emit_move_insn(rtx x, rtx y);
81419 +
81420 +int plugin_is_GPL_compatible;
81421 +
81422 +static struct plugin_info checker_plugin_info = {
81423 + .version = "201111150100",
81424 +};
81425 +
81426 +#define ADDR_SPACE_KERNEL 0
81427 +#define ADDR_SPACE_FORCE_KERNEL 1
81428 +#define ADDR_SPACE_USER 2
81429 +#define ADDR_SPACE_FORCE_USER 3
81430 +#define ADDR_SPACE_IOMEM 0
81431 +#define ADDR_SPACE_FORCE_IOMEM 0
81432 +#define ADDR_SPACE_PERCPU 0
81433 +#define ADDR_SPACE_FORCE_PERCPU 0
81434 +#define ADDR_SPACE_RCU 0
81435 +#define ADDR_SPACE_FORCE_RCU 0
81436 +
81437 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
81438 +{
81439 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
81440 +}
81441 +
81442 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
81443 +{
81444 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
81445 +}
81446 +
81447 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
81448 +{
81449 + return default_addr_space_valid_pointer_mode(mode, as);
81450 +}
81451 +
81452 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
81453 +{
81454 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
81455 +}
81456 +
81457 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
81458 +{
81459 + return default_addr_space_legitimize_address(x, oldx, mode, as);
81460 +}
81461 +
81462 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
81463 +{
81464 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
81465 + return true;
81466 +
81467 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
81468 + return true;
81469 +
81470 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
81471 + return true;
81472 +
81473 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
81474 + return true;
81475 +
81476 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
81477 + return true;
81478 +
81479 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
81480 + return true;
81481 +
81482 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
81483 + return true;
81484 +
81485 + return subset == superset;
81486 +}
81487 +
81488 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
81489 +{
81490 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
81491 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
81492 +
81493 + return op;
81494 +}
81495 +
81496 +static void register_checker_address_spaces(void *event_data, void *data)
81497 +{
81498 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
81499 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
81500 + c_register_addr_space("__user", ADDR_SPACE_USER);
81501 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
81502 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
81503 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
81504 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
81505 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
81506 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
81507 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
81508 +
81509 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
81510 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
81511 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
81512 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
81513 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
81514 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
81515 + targetm.addr_space.convert = checker_addr_space_convert;
81516 +}
81517 +
81518 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81519 +{
81520 + const char * const plugin_name = plugin_info->base_name;
81521 + const int argc = plugin_info->argc;
81522 + const struct plugin_argument * const argv = plugin_info->argv;
81523 + int i;
81524 +
81525 + if (!plugin_default_version_check(version, &gcc_version)) {
81526 + error(G_("incompatible gcc/plugin versions"));
81527 + return 1;
81528 + }
81529 +
81530 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
81531 +
81532 + for (i = 0; i < argc; ++i)
81533 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81534 +
81535 + if (TARGET_64BIT == 0)
81536 + return 0;
81537 +
81538 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
81539 +
81540 + return 0;
81541 +}
81542 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
81543 new file mode 100644
81544 index 0000000..ee950d0
81545 --- /dev/null
81546 +++ b/tools/gcc/colorize_plugin.c
81547 @@ -0,0 +1,147 @@
81548 +/*
81549 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
81550 + * Licensed under the GPL v2
81551 + *
81552 + * Note: the choice of the license means that the compilation process is
81553 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81554 + * but for the kernel it doesn't matter since it doesn't link against
81555 + * any of the gcc libraries
81556 + *
81557 + * gcc plugin to colorize diagnostic output
81558 + *
81559 + */
81560 +
81561 +#include "gcc-plugin.h"
81562 +#include "config.h"
81563 +#include "system.h"
81564 +#include "coretypes.h"
81565 +#include "tree.h"
81566 +#include "tree-pass.h"
81567 +#include "flags.h"
81568 +#include "intl.h"
81569 +#include "toplev.h"
81570 +#include "plugin.h"
81571 +#include "diagnostic.h"
81572 +#include "plugin-version.h"
81573 +#include "tm.h"
81574 +
81575 +int plugin_is_GPL_compatible;
81576 +
81577 +static struct plugin_info colorize_plugin_info = {
81578 + .version = "201203092200",
81579 +};
81580 +
81581 +#define GREEN "\033[32m\033[2m"
81582 +#define LIGHTGREEN "\033[32m\033[1m"
81583 +#define YELLOW "\033[33m\033[2m"
81584 +#define LIGHTYELLOW "\033[33m\033[1m"
81585 +#define RED "\033[31m\033[2m"
81586 +#define LIGHTRED "\033[31m\033[1m"
81587 +#define BLUE "\033[34m\033[2m"
81588 +#define LIGHTBLUE "\033[34m\033[1m"
81589 +#define BRIGHT "\033[m\033[1m"
81590 +#define NORMAL "\033[m"
81591 +
81592 +static diagnostic_starter_fn old_starter;
81593 +static diagnostic_finalizer_fn old_finalizer;
81594 +
81595 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81596 +{
81597 + const char *color;
81598 + char *newprefix;
81599 +
81600 + switch (diagnostic->kind) {
81601 + case DK_NOTE:
81602 + color = LIGHTBLUE;
81603 + break;
81604 +
81605 + case DK_PEDWARN:
81606 + case DK_WARNING:
81607 + color = LIGHTYELLOW;
81608 + break;
81609 +
81610 + case DK_ERROR:
81611 + case DK_FATAL:
81612 + case DK_ICE:
81613 + case DK_PERMERROR:
81614 + case DK_SORRY:
81615 + color = LIGHTRED;
81616 + break;
81617 +
81618 + default:
81619 + color = NORMAL;
81620 + }
81621 +
81622 + old_starter(context, diagnostic);
81623 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
81624 + return;
81625 + pp_destroy_prefix(context->printer);
81626 + pp_set_prefix(context->printer, newprefix);
81627 +}
81628 +
81629 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
81630 +{
81631 + old_finalizer(context, diagnostic);
81632 +}
81633 +
81634 +static void colorize_arm(void)
81635 +{
81636 + old_starter = diagnostic_starter(global_dc);
81637 + old_finalizer = diagnostic_finalizer(global_dc);
81638 +
81639 + diagnostic_starter(global_dc) = start_colorize;
81640 + diagnostic_finalizer(global_dc) = finalize_colorize;
81641 +}
81642 +
81643 +static unsigned int execute_colorize_rearm(void)
81644 +{
81645 + if (diagnostic_starter(global_dc) == start_colorize)
81646 + return 0;
81647 +
81648 + colorize_arm();
81649 + return 0;
81650 +}
81651 +
81652 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
81653 + .pass = {
81654 + .type = SIMPLE_IPA_PASS,
81655 + .name = "colorize_rearm",
81656 + .gate = NULL,
81657 + .execute = execute_colorize_rearm,
81658 + .sub = NULL,
81659 + .next = NULL,
81660 + .static_pass_number = 0,
81661 + .tv_id = TV_NONE,
81662 + .properties_required = 0,
81663 + .properties_provided = 0,
81664 + .properties_destroyed = 0,
81665 + .todo_flags_start = 0,
81666 + .todo_flags_finish = 0
81667 + }
81668 +};
81669 +
81670 +static void colorize_start_unit(void *gcc_data, void *user_data)
81671 +{
81672 + colorize_arm();
81673 +}
81674 +
81675 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81676 +{
81677 + const char * const plugin_name = plugin_info->base_name;
81678 + struct register_pass_info colorize_rearm_pass_info = {
81679 + .pass = &pass_ipa_colorize_rearm.pass,
81680 + .reference_pass_name = "*free_lang_data",
81681 + .ref_pass_instance_number = 0,
81682 + .pos_op = PASS_POS_INSERT_AFTER
81683 + };
81684 +
81685 + if (!plugin_default_version_check(version, &gcc_version)) {
81686 + error(G_("incompatible gcc/plugin versions"));
81687 + return 1;
81688 + }
81689 +
81690 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
81691 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
81692 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
81693 + return 0;
81694 +}
81695 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
81696 new file mode 100644
81697 index 0000000..88a7438
81698 --- /dev/null
81699 +++ b/tools/gcc/constify_plugin.c
81700 @@ -0,0 +1,303 @@
81701 +/*
81702 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
81703 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
81704 + * Licensed under the GPL v2, or (at your option) v3
81705 + *
81706 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
81707 + *
81708 + * Homepage:
81709 + * http://www.grsecurity.net/~ephox/const_plugin/
81710 + *
81711 + * Usage:
81712 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
81713 + * $ gcc -fplugin=constify_plugin.so test.c -O2
81714 + */
81715 +
81716 +#include "gcc-plugin.h"
81717 +#include "config.h"
81718 +#include "system.h"
81719 +#include "coretypes.h"
81720 +#include "tree.h"
81721 +#include "tree-pass.h"
81722 +#include "flags.h"
81723 +#include "intl.h"
81724 +#include "toplev.h"
81725 +#include "plugin.h"
81726 +#include "diagnostic.h"
81727 +#include "plugin-version.h"
81728 +#include "tm.h"
81729 +#include "function.h"
81730 +#include "basic-block.h"
81731 +#include "gimple.h"
81732 +#include "rtl.h"
81733 +#include "emit-rtl.h"
81734 +#include "tree-flow.h"
81735 +
81736 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
81737 +
81738 +int plugin_is_GPL_compatible;
81739 +
81740 +static struct plugin_info const_plugin_info = {
81741 + .version = "201111150100",
81742 + .help = "no-constify\tturn off constification\n",
81743 +};
81744 +
81745 +static void constify_type(tree type);
81746 +static bool walk_struct(tree node);
81747 +
81748 +static tree deconstify_type(tree old_type)
81749 +{
81750 + tree new_type, field;
81751 +
81752 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
81753 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
81754 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
81755 + DECL_FIELD_CONTEXT(field) = new_type;
81756 + TYPE_READONLY(new_type) = 0;
81757 + C_TYPE_FIELDS_READONLY(new_type) = 0;
81758 + return new_type;
81759 +}
81760 +
81761 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81762 +{
81763 + tree type;
81764 +
81765 + *no_add_attrs = true;
81766 + if (TREE_CODE(*node) == FUNCTION_DECL) {
81767 + error("%qE attribute does not apply to functions", name);
81768 + return NULL_TREE;
81769 + }
81770 +
81771 + if (TREE_CODE(*node) == VAR_DECL) {
81772 + error("%qE attribute does not apply to variables", name);
81773 + return NULL_TREE;
81774 + }
81775 +
81776 + if (TYPE_P(*node)) {
81777 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
81778 + *no_add_attrs = false;
81779 + else
81780 + error("%qE attribute applies to struct and union types only", name);
81781 + return NULL_TREE;
81782 + }
81783 +
81784 + type = TREE_TYPE(*node);
81785 +
81786 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
81787 + error("%qE attribute applies to struct and union types only", name);
81788 + return NULL_TREE;
81789 + }
81790 +
81791 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
81792 + error("%qE attribute is already applied to the type", name);
81793 + return NULL_TREE;
81794 + }
81795 +
81796 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
81797 + error("%qE attribute used on type that is not constified", name);
81798 + return NULL_TREE;
81799 + }
81800 +
81801 + if (TREE_CODE(*node) == TYPE_DECL) {
81802 + TREE_TYPE(*node) = deconstify_type(type);
81803 + TREE_READONLY(*node) = 0;
81804 + return NULL_TREE;
81805 + }
81806 +
81807 + return NULL_TREE;
81808 +}
81809 +
81810 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
81811 +{
81812 + *no_add_attrs = true;
81813 + if (!TYPE_P(*node)) {
81814 + error("%qE attribute applies to types only", name);
81815 + return NULL_TREE;
81816 + }
81817 +
81818 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
81819 + error("%qE attribute applies to struct and union types only", name);
81820 + return NULL_TREE;
81821 + }
81822 +
81823 + *no_add_attrs = false;
81824 + constify_type(*node);
81825 + return NULL_TREE;
81826 +}
81827 +
81828 +static struct attribute_spec no_const_attr = {
81829 + .name = "no_const",
81830 + .min_length = 0,
81831 + .max_length = 0,
81832 + .decl_required = false,
81833 + .type_required = false,
81834 + .function_type_required = false,
81835 + .handler = handle_no_const_attribute,
81836 +#if BUILDING_GCC_VERSION >= 4007
81837 + .affects_type_identity = true
81838 +#endif
81839 +};
81840 +
81841 +static struct attribute_spec do_const_attr = {
81842 + .name = "do_const",
81843 + .min_length = 0,
81844 + .max_length = 0,
81845 + .decl_required = false,
81846 + .type_required = false,
81847 + .function_type_required = false,
81848 + .handler = handle_do_const_attribute,
81849 +#if BUILDING_GCC_VERSION >= 4007
81850 + .affects_type_identity = true
81851 +#endif
81852 +};
81853 +
81854 +static void register_attributes(void *event_data, void *data)
81855 +{
81856 + register_attribute(&no_const_attr);
81857 + register_attribute(&do_const_attr);
81858 +}
81859 +
81860 +static void constify_type(tree type)
81861 +{
81862 + TYPE_READONLY(type) = 1;
81863 + C_TYPE_FIELDS_READONLY(type) = 1;
81864 +}
81865 +
81866 +static bool is_fptr(tree field)
81867 +{
81868 + tree ptr = TREE_TYPE(field);
81869 +
81870 + if (TREE_CODE(ptr) != POINTER_TYPE)
81871 + return false;
81872 +
81873 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
81874 +}
81875 +
81876 +static bool walk_struct(tree node)
81877 +{
81878 + tree field;
81879 +
81880 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
81881 + return false;
81882 +
81883 + if (TYPE_FIELDS(node) == NULL_TREE)
81884 + return false;
81885 +
81886 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
81887 + tree type = TREE_TYPE(field);
81888 + enum tree_code code = TREE_CODE(type);
81889 + if (code == RECORD_TYPE || code == UNION_TYPE) {
81890 + if (!(walk_struct(type)))
81891 + return false;
81892 + } else if (!is_fptr(field) && !TREE_READONLY(field))
81893 + return false;
81894 + }
81895 + return true;
81896 +}
81897 +
81898 +static void finish_type(void *event_data, void *data)
81899 +{
81900 + tree type = (tree)event_data;
81901 +
81902 + if (type == NULL_TREE)
81903 + return;
81904 +
81905 + if (TYPE_READONLY(type))
81906 + return;
81907 +
81908 + if (walk_struct(type))
81909 + constify_type(type);
81910 +}
81911 +
81912 +static unsigned int check_local_variables(void);
81913 +
81914 +struct gimple_opt_pass pass_local_variable = {
81915 + {
81916 + .type = GIMPLE_PASS,
81917 + .name = "check_local_variables",
81918 + .gate = NULL,
81919 + .execute = check_local_variables,
81920 + .sub = NULL,
81921 + .next = NULL,
81922 + .static_pass_number = 0,
81923 + .tv_id = TV_NONE,
81924 + .properties_required = 0,
81925 + .properties_provided = 0,
81926 + .properties_destroyed = 0,
81927 + .todo_flags_start = 0,
81928 + .todo_flags_finish = 0
81929 + }
81930 +};
81931 +
81932 +static unsigned int check_local_variables(void)
81933 +{
81934 + tree var;
81935 + referenced_var_iterator rvi;
81936 +
81937 +#if BUILDING_GCC_VERSION == 4005
81938 + FOR_EACH_REFERENCED_VAR(var, rvi) {
81939 +#else
81940 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
81941 +#endif
81942 + tree type = TREE_TYPE(var);
81943 +
81944 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
81945 + continue;
81946 +
81947 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
81948 + continue;
81949 +
81950 + if (!TYPE_READONLY(type))
81951 + continue;
81952 +
81953 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
81954 +// continue;
81955 +
81956 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
81957 +// continue;
81958 +
81959 + if (walk_struct(type)) {
81960 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
81961 + return 1;
81962 + }
81963 + }
81964 + return 0;
81965 +}
81966 +
81967 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81968 +{
81969 + const char * const plugin_name = plugin_info->base_name;
81970 + const int argc = plugin_info->argc;
81971 + const struct plugin_argument * const argv = plugin_info->argv;
81972 + int i;
81973 + bool constify = true;
81974 +
81975 + struct register_pass_info local_variable_pass_info = {
81976 + .pass = &pass_local_variable.pass,
81977 + .reference_pass_name = "*referenced_vars",
81978 + .ref_pass_instance_number = 0,
81979 + .pos_op = PASS_POS_INSERT_AFTER
81980 + };
81981 +
81982 + if (!plugin_default_version_check(version, &gcc_version)) {
81983 + error(G_("incompatible gcc/plugin versions"));
81984 + return 1;
81985 + }
81986 +
81987 + for (i = 0; i < argc; ++i) {
81988 + if (!(strcmp(argv[i].key, "no-constify"))) {
81989 + constify = false;
81990 + continue;
81991 + }
81992 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81993 + }
81994 +
81995 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
81996 + if (constify) {
81997 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
81998 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
81999 + }
82000 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82001 +
82002 + return 0;
82003 +}
82004 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
82005 new file mode 100644
82006 index 0000000..a5eabce
82007 --- /dev/null
82008 +++ b/tools/gcc/kallocstat_plugin.c
82009 @@ -0,0 +1,167 @@
82010 +/*
82011 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82012 + * Licensed under the GPL v2
82013 + *
82014 + * Note: the choice of the license means that the compilation process is
82015 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82016 + * but for the kernel it doesn't matter since it doesn't link against
82017 + * any of the gcc libraries
82018 + *
82019 + * gcc plugin to find the distribution of k*alloc sizes
82020 + *
82021 + * TODO:
82022 + *
82023 + * BUGS:
82024 + * - none known
82025 + */
82026 +#include "gcc-plugin.h"
82027 +#include "config.h"
82028 +#include "system.h"
82029 +#include "coretypes.h"
82030 +#include "tree.h"
82031 +#include "tree-pass.h"
82032 +#include "flags.h"
82033 +#include "intl.h"
82034 +#include "toplev.h"
82035 +#include "plugin.h"
82036 +//#include "expr.h" where are you...
82037 +#include "diagnostic.h"
82038 +#include "plugin-version.h"
82039 +#include "tm.h"
82040 +#include "function.h"
82041 +#include "basic-block.h"
82042 +#include "gimple.h"
82043 +#include "rtl.h"
82044 +#include "emit-rtl.h"
82045 +
82046 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82047 +
82048 +int plugin_is_GPL_compatible;
82049 +
82050 +static const char * const kalloc_functions[] = {
82051 + "__kmalloc",
82052 + "kmalloc",
82053 + "kmalloc_large",
82054 + "kmalloc_node",
82055 + "kmalloc_order",
82056 + "kmalloc_order_trace",
82057 + "kmalloc_slab",
82058 + "kzalloc",
82059 + "kzalloc_node",
82060 +};
82061 +
82062 +static struct plugin_info kallocstat_plugin_info = {
82063 + .version = "201111150100",
82064 +};
82065 +
82066 +static unsigned int execute_kallocstat(void);
82067 +
82068 +static struct gimple_opt_pass kallocstat_pass = {
82069 + .pass = {
82070 + .type = GIMPLE_PASS,
82071 + .name = "kallocstat",
82072 + .gate = NULL,
82073 + .execute = execute_kallocstat,
82074 + .sub = NULL,
82075 + .next = NULL,
82076 + .static_pass_number = 0,
82077 + .tv_id = TV_NONE,
82078 + .properties_required = 0,
82079 + .properties_provided = 0,
82080 + .properties_destroyed = 0,
82081 + .todo_flags_start = 0,
82082 + .todo_flags_finish = 0
82083 + }
82084 +};
82085 +
82086 +static bool is_kalloc(const char *fnname)
82087 +{
82088 + size_t i;
82089 +
82090 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
82091 + if (!strcmp(fnname, kalloc_functions[i]))
82092 + return true;
82093 + return false;
82094 +}
82095 +
82096 +static unsigned int execute_kallocstat(void)
82097 +{
82098 + basic_block bb;
82099 +
82100 + // 1. loop through BBs and GIMPLE statements
82101 + FOR_EACH_BB(bb) {
82102 + gimple_stmt_iterator gsi;
82103 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82104 + // gimple match:
82105 + tree fndecl, size;
82106 + gimple call_stmt;
82107 + const char *fnname;
82108 +
82109 + // is it a call
82110 + call_stmt = gsi_stmt(gsi);
82111 + if (!is_gimple_call(call_stmt))
82112 + continue;
82113 + fndecl = gimple_call_fndecl(call_stmt);
82114 + if (fndecl == NULL_TREE)
82115 + continue;
82116 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
82117 + continue;
82118 +
82119 + // is it a call to k*alloc
82120 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
82121 + if (!is_kalloc(fnname))
82122 + continue;
82123 +
82124 + // is the size arg the result of a simple const assignment
82125 + size = gimple_call_arg(call_stmt, 0);
82126 + while (true) {
82127 + gimple def_stmt;
82128 + expanded_location xloc;
82129 + size_t size_val;
82130 +
82131 + if (TREE_CODE(size) != SSA_NAME)
82132 + break;
82133 + def_stmt = SSA_NAME_DEF_STMT(size);
82134 + if (!def_stmt || !is_gimple_assign(def_stmt))
82135 + break;
82136 + if (gimple_num_ops(def_stmt) != 2)
82137 + break;
82138 + size = gimple_assign_rhs1(def_stmt);
82139 + if (!TREE_CONSTANT(size))
82140 + continue;
82141 + xloc = expand_location(gimple_location(def_stmt));
82142 + if (!xloc.file)
82143 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
82144 + size_val = TREE_INT_CST_LOW(size);
82145 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
82146 + break;
82147 + }
82148 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82149 +//debug_tree(gimple_call_fn(call_stmt));
82150 +//print_node(stderr, "pax", fndecl, 4);
82151 + }
82152 + }
82153 +
82154 + return 0;
82155 +}
82156 +
82157 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82158 +{
82159 + const char * const plugin_name = plugin_info->base_name;
82160 + struct register_pass_info kallocstat_pass_info = {
82161 + .pass = &kallocstat_pass.pass,
82162 + .reference_pass_name = "ssa",
82163 + .ref_pass_instance_number = 0,
82164 + .pos_op = PASS_POS_INSERT_AFTER
82165 + };
82166 +
82167 + if (!plugin_default_version_check(version, &gcc_version)) {
82168 + error(G_("incompatible gcc/plugin versions"));
82169 + return 1;
82170 + }
82171 +
82172 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
82173 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
82174 +
82175 + return 0;
82176 +}
82177 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
82178 new file mode 100644
82179 index 0000000..d8a8da2
82180 --- /dev/null
82181 +++ b/tools/gcc/kernexec_plugin.c
82182 @@ -0,0 +1,427 @@
82183 +/*
82184 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82185 + * Licensed under the GPL v2
82186 + *
82187 + * Note: the choice of the license means that the compilation process is
82188 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82189 + * but for the kernel it doesn't matter since it doesn't link against
82190 + * any of the gcc libraries
82191 + *
82192 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
82193 + *
82194 + * TODO:
82195 + *
82196 + * BUGS:
82197 + * - none known
82198 + */
82199 +#include "gcc-plugin.h"
82200 +#include "config.h"
82201 +#include "system.h"
82202 +#include "coretypes.h"
82203 +#include "tree.h"
82204 +#include "tree-pass.h"
82205 +#include "flags.h"
82206 +#include "intl.h"
82207 +#include "toplev.h"
82208 +#include "plugin.h"
82209 +//#include "expr.h" where are you...
82210 +#include "diagnostic.h"
82211 +#include "plugin-version.h"
82212 +#include "tm.h"
82213 +#include "function.h"
82214 +#include "basic-block.h"
82215 +#include "gimple.h"
82216 +#include "rtl.h"
82217 +#include "emit-rtl.h"
82218 +#include "tree-flow.h"
82219 +
82220 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82221 +extern rtx emit_move_insn(rtx x, rtx y);
82222 +
82223 +int plugin_is_GPL_compatible;
82224 +
82225 +static struct plugin_info kernexec_plugin_info = {
82226 + .version = "201111291120",
82227 + .help = "method=[bts|or]\tinstrumentation method\n"
82228 +};
82229 +
82230 +static unsigned int execute_kernexec_reload(void);
82231 +static unsigned int execute_kernexec_fptr(void);
82232 +static unsigned int execute_kernexec_retaddr(void);
82233 +static bool kernexec_cmodel_check(void);
82234 +
82235 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
82236 +static void (*kernexec_instrument_retaddr)(rtx);
82237 +
82238 +static struct gimple_opt_pass kernexec_reload_pass = {
82239 + .pass = {
82240 + .type = GIMPLE_PASS,
82241 + .name = "kernexec_reload",
82242 + .gate = kernexec_cmodel_check,
82243 + .execute = execute_kernexec_reload,
82244 + .sub = NULL,
82245 + .next = NULL,
82246 + .static_pass_number = 0,
82247 + .tv_id = TV_NONE,
82248 + .properties_required = 0,
82249 + .properties_provided = 0,
82250 + .properties_destroyed = 0,
82251 + .todo_flags_start = 0,
82252 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82253 + }
82254 +};
82255 +
82256 +static struct gimple_opt_pass kernexec_fptr_pass = {
82257 + .pass = {
82258 + .type = GIMPLE_PASS,
82259 + .name = "kernexec_fptr",
82260 + .gate = kernexec_cmodel_check,
82261 + .execute = execute_kernexec_fptr,
82262 + .sub = NULL,
82263 + .next = NULL,
82264 + .static_pass_number = 0,
82265 + .tv_id = TV_NONE,
82266 + .properties_required = 0,
82267 + .properties_provided = 0,
82268 + .properties_destroyed = 0,
82269 + .todo_flags_start = 0,
82270 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82271 + }
82272 +};
82273 +
82274 +static struct rtl_opt_pass kernexec_retaddr_pass = {
82275 + .pass = {
82276 + .type = RTL_PASS,
82277 + .name = "kernexec_retaddr",
82278 + .gate = kernexec_cmodel_check,
82279 + .execute = execute_kernexec_retaddr,
82280 + .sub = NULL,
82281 + .next = NULL,
82282 + .static_pass_number = 0,
82283 + .tv_id = TV_NONE,
82284 + .properties_required = 0,
82285 + .properties_provided = 0,
82286 + .properties_destroyed = 0,
82287 + .todo_flags_start = 0,
82288 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
82289 + }
82290 +};
82291 +
82292 +static bool kernexec_cmodel_check(void)
82293 +{
82294 + tree section;
82295 +
82296 + if (ix86_cmodel != CM_KERNEL)
82297 + return false;
82298 +
82299 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
82300 + if (!section || !TREE_VALUE(section))
82301 + return true;
82302 +
82303 + section = TREE_VALUE(TREE_VALUE(section));
82304 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
82305 + return true;
82306 +
82307 + return false;
82308 +}
82309 +
82310 +/*
82311 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
82312 + */
82313 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
82314 +{
82315 + gimple asm_movabs_stmt;
82316 +
82317 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
82318 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
82319 + gimple_asm_set_volatile(asm_movabs_stmt, true);
82320 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
82321 + update_stmt(asm_movabs_stmt);
82322 +}
82323 +
82324 +/*
82325 + * find all asm() stmts that clobber r10 and add a reload of r10
82326 + */
82327 +static unsigned int execute_kernexec_reload(void)
82328 +{
82329 + basic_block bb;
82330 +
82331 + // 1. loop through BBs and GIMPLE statements
82332 + FOR_EACH_BB(bb) {
82333 + gimple_stmt_iterator gsi;
82334 +
82335 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82336 + // gimple match: __asm__ ("" : : : "r10");
82337 + gimple asm_stmt;
82338 + size_t nclobbers;
82339 +
82340 + // is it an asm ...
82341 + asm_stmt = gsi_stmt(gsi);
82342 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
82343 + continue;
82344 +
82345 + // ... clobbering r10
82346 + nclobbers = gimple_asm_nclobbers(asm_stmt);
82347 + while (nclobbers--) {
82348 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
82349 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
82350 + continue;
82351 + kernexec_reload_fptr_mask(&gsi);
82352 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
82353 + break;
82354 + }
82355 + }
82356 + }
82357 +
82358 + return 0;
82359 +}
82360 +
82361 +/*
82362 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
82363 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
82364 + */
82365 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
82366 +{
82367 + gimple assign_intptr, assign_new_fptr, call_stmt;
82368 + tree intptr, old_fptr, new_fptr, kernexec_mask;
82369 +
82370 + call_stmt = gsi_stmt(*gsi);
82371 + old_fptr = gimple_call_fn(call_stmt);
82372 +
82373 + // create temporary unsigned long variable used for bitops and cast fptr to it
82374 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
82375 + add_referenced_var(intptr);
82376 + mark_sym_for_renaming(intptr);
82377 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
82378 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
82379 + update_stmt(assign_intptr);
82380 +
82381 + // apply logical or to temporary unsigned long and bitmask
82382 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
82383 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
82384 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
82385 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
82386 + update_stmt(assign_intptr);
82387 +
82388 + // cast temporary unsigned long back to a temporary fptr variable
82389 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
82390 + add_referenced_var(new_fptr);
82391 + mark_sym_for_renaming(new_fptr);
82392 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
82393 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
82394 + update_stmt(assign_new_fptr);
82395 +
82396 + // replace call stmt fn with the new fptr
82397 + gimple_call_set_fn(call_stmt, new_fptr);
82398 + update_stmt(call_stmt);
82399 +}
82400 +
82401 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
82402 +{
82403 + gimple asm_or_stmt, call_stmt;
82404 + tree old_fptr, new_fptr, input, output;
82405 + VEC(tree, gc) *inputs = NULL;
82406 + VEC(tree, gc) *outputs = NULL;
82407 +
82408 + call_stmt = gsi_stmt(*gsi);
82409 + old_fptr = gimple_call_fn(call_stmt);
82410 +
82411 + // create temporary fptr variable
82412 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
82413 + add_referenced_var(new_fptr);
82414 + mark_sym_for_renaming(new_fptr);
82415 +
82416 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
82417 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
82418 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
82419 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
82420 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
82421 + VEC_safe_push(tree, gc, inputs, input);
82422 + VEC_safe_push(tree, gc, outputs, output);
82423 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
82424 + gimple_asm_set_volatile(asm_or_stmt, true);
82425 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
82426 + update_stmt(asm_or_stmt);
82427 +
82428 + // replace call stmt fn with the new fptr
82429 + gimple_call_set_fn(call_stmt, new_fptr);
82430 + update_stmt(call_stmt);
82431 +}
82432 +
82433 +/*
82434 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
82435 + */
82436 +static unsigned int execute_kernexec_fptr(void)
82437 +{
82438 + basic_block bb;
82439 +
82440 + // 1. loop through BBs and GIMPLE statements
82441 + FOR_EACH_BB(bb) {
82442 + gimple_stmt_iterator gsi;
82443 +
82444 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82445 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
82446 + tree fn;
82447 + gimple call_stmt;
82448 +
82449 + // is it a call ...
82450 + call_stmt = gsi_stmt(gsi);
82451 + if (!is_gimple_call(call_stmt))
82452 + continue;
82453 + fn = gimple_call_fn(call_stmt);
82454 + if (TREE_CODE(fn) == ADDR_EXPR)
82455 + continue;
82456 + if (TREE_CODE(fn) != SSA_NAME)
82457 + gcc_unreachable();
82458 +
82459 + // ... through a function pointer
82460 + fn = SSA_NAME_VAR(fn);
82461 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
82462 + continue;
82463 + fn = TREE_TYPE(fn);
82464 + if (TREE_CODE(fn) != POINTER_TYPE)
82465 + continue;
82466 + fn = TREE_TYPE(fn);
82467 + if (TREE_CODE(fn) != FUNCTION_TYPE)
82468 + continue;
82469 +
82470 + kernexec_instrument_fptr(&gsi);
82471 +
82472 +//debug_tree(gimple_call_fn(call_stmt));
82473 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82474 + }
82475 + }
82476 +
82477 + return 0;
82478 +}
82479 +
82480 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
82481 +static void kernexec_instrument_retaddr_bts(rtx insn)
82482 +{
82483 + rtx btsq;
82484 + rtvec argvec, constraintvec, labelvec;
82485 + int line;
82486 +
82487 + // create asm volatile("btsq $63,(%%rsp)":::)
82488 + argvec = rtvec_alloc(0);
82489 + constraintvec = rtvec_alloc(0);
82490 + labelvec = rtvec_alloc(0);
82491 + line = expand_location(RTL_LOCATION(insn)).line;
82492 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82493 + MEM_VOLATILE_P(btsq) = 1;
82494 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
82495 + emit_insn_before(btsq, insn);
82496 +}
82497 +
82498 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
82499 +static void kernexec_instrument_retaddr_or(rtx insn)
82500 +{
82501 + rtx orq;
82502 + rtvec argvec, constraintvec, labelvec;
82503 + int line;
82504 +
82505 + // create asm volatile("orq %%r10,(%%rsp)":::)
82506 + argvec = rtvec_alloc(0);
82507 + constraintvec = rtvec_alloc(0);
82508 + labelvec = rtvec_alloc(0);
82509 + line = expand_location(RTL_LOCATION(insn)).line;
82510 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
82511 + MEM_VOLATILE_P(orq) = 1;
82512 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
82513 + emit_insn_before(orq, insn);
82514 +}
82515 +
82516 +/*
82517 + * find all asm level function returns and forcibly set the highest bit of the return address
82518 + */
82519 +static unsigned int execute_kernexec_retaddr(void)
82520 +{
82521 + rtx insn;
82522 +
82523 + // 1. find function returns
82524 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
82525 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
82526 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
82527 + rtx body;
82528 +
82529 + // is it a retn
82530 + if (!JUMP_P(insn))
82531 + continue;
82532 + body = PATTERN(insn);
82533 + if (GET_CODE(body) == PARALLEL)
82534 + body = XVECEXP(body, 0, 0);
82535 + if (GET_CODE(body) != RETURN)
82536 + continue;
82537 + kernexec_instrument_retaddr(insn);
82538 + }
82539 +
82540 +// print_simple_rtl(stderr, get_insns());
82541 +// print_rtl(stderr, get_insns());
82542 +
82543 + return 0;
82544 +}
82545 +
82546 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82547 +{
82548 + const char * const plugin_name = plugin_info->base_name;
82549 + const int argc = plugin_info->argc;
82550 + const struct plugin_argument * const argv = plugin_info->argv;
82551 + int i;
82552 + struct register_pass_info kernexec_reload_pass_info = {
82553 + .pass = &kernexec_reload_pass.pass,
82554 + .reference_pass_name = "ssa",
82555 + .ref_pass_instance_number = 0,
82556 + .pos_op = PASS_POS_INSERT_AFTER
82557 + };
82558 + struct register_pass_info kernexec_fptr_pass_info = {
82559 + .pass = &kernexec_fptr_pass.pass,
82560 + .reference_pass_name = "ssa",
82561 + .ref_pass_instance_number = 0,
82562 + .pos_op = PASS_POS_INSERT_AFTER
82563 + };
82564 + struct register_pass_info kernexec_retaddr_pass_info = {
82565 + .pass = &kernexec_retaddr_pass.pass,
82566 + .reference_pass_name = "pro_and_epilogue",
82567 + .ref_pass_instance_number = 0,
82568 + .pos_op = PASS_POS_INSERT_AFTER
82569 + };
82570 +
82571 + if (!plugin_default_version_check(version, &gcc_version)) {
82572 + error(G_("incompatible gcc/plugin versions"));
82573 + return 1;
82574 + }
82575 +
82576 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
82577 +
82578 + if (TARGET_64BIT == 0)
82579 + return 0;
82580 +
82581 + for (i = 0; i < argc; ++i) {
82582 + if (!strcmp(argv[i].key, "method")) {
82583 + if (!argv[i].value) {
82584 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82585 + continue;
82586 + }
82587 + if (!strcmp(argv[i].value, "bts")) {
82588 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
82589 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
82590 + } else if (!strcmp(argv[i].value, "or")) {
82591 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
82592 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
82593 + fix_register("r10", 1, 1);
82594 + } else
82595 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
82596 + continue;
82597 + }
82598 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82599 + }
82600 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
82601 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
82602 +
82603 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
82604 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
82605 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
82606 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
82607 +
82608 + return 0;
82609 +}
82610 diff --git a/tools/gcc/size_overflow_hash1.h b/tools/gcc/size_overflow_hash1.h
82611 new file mode 100644
82612 index 0000000..16ccac1
82613 --- /dev/null
82614 +++ b/tools/gcc/size_overflow_hash1.h
82615 @@ -0,0 +1,3047 @@
82616 +struct size_overflow_hash size_overflow_hash1[65536] = {
82617 + [10013].file = "security/smack/smackfs.c",
82618 + [10013].name = "smk_write_direct",
82619 + [10013].param3 = 1,
82620 + [10167].file = "sound/core/oss/pcm_plugin.c",
82621 + [10167].name = "snd_pcm_plugin_build",
82622 + [10167].param5 = 1,
82623 + [1020].file = "drivers/usb/misc/usbtest.c",
82624 + [1020].name = "test_unaligned_bulk",
82625 + [1020].param3 = 1,
82626 + [1022].file = "sound/pci/rme9652/rme9652.c",
82627 + [1022].name = "snd_rme9652_playback_copy",
82628 + [1022].param5 = 1,
82629 + [10321].file = "drivers/platform/x86/thinkpad_acpi.c",
82630 + [10321].name = "create_attr_set",
82631 + [10321].param1 = 1,
82632 + [10341].file = "fs/nfsd/nfs4xdr.c",
82633 + [10341].name = "read_buf",
82634 + [10341].param2 = 1,
82635 + [10357].file = "net/sunrpc/cache.c",
82636 + [10357].name = "cache_read",
82637 + [10357].param3 = 1,
82638 + [10397].file = "drivers/gpu/drm/i915/i915_debugfs.c",
82639 + [10397].name = "i915_wedged_write",
82640 + [10397].param3 = 1,
82641 + [10399].file = "kernel/trace/trace.c",
82642 + [10399].name = "trace_seq_to_user",
82643 + [10399].param3 = 1,
82644 + [10414].file = "drivers/tty/vt/vt.c",
82645 + [10414].name = "vc_do_resize",
82646 + [10414].param3 = 1,
82647 + [10414].param4 = 1,
82648 + [10565].file = "drivers/input/touchscreen/ad7879-spi.c",
82649 + [10565].name = "ad7879_spi_multi_read",
82650 + [10565].param3 = 1,
82651 + [10623].file = "drivers/infiniband/core/user_mad.c",
82652 + [10623].name = "ib_umad_write",
82653 + [10623].param3 = 1,
82654 + [10707].file = "fs/nfs/idmap.c",
82655 + [10707].name = "nfs_idmap_request_key",
82656 + [10707].param2 = 1,
82657 + [1073].file = "drivers/block/aoe/aoecmd.c",
82658 + [1073].name = "addtgt",
82659 + [1073].param3 = 1,
82660 + [10745].file = "fs/cifs/connect.c",
82661 + [10745].name = "get_server_iovec",
82662 + [10745].param2 = 1,
82663 + [10750].file = "drivers/net/wireless/iwmc3200wifi/rx.c",
82664 + [10750].name = "iwm_ntf_calib_res",
82665 + [10750].param3 = 1,
82666 + [10773].file = "drivers/input/mousedev.c",
82667 + [10773].name = "mousedev_read",
82668 + [10773].param3 = 1,
82669 + [10777].file = "fs/ntfs/file.c",
82670 + [10777].name = "ntfs_file_buffered_write",
82671 + [10777].param6 = 1,
82672 + [10893].file = "drivers/misc/sgi-gru/gruprocfs.c",
82673 + [10893].name = "options_write",
82674 + [10893].param3 = 1,
82675 + [10919].file = "net/ipv4/netfilter/arp_tables.c",
82676 + [10919].name = "do_arpt_set_ctl",
82677 + [10919].param4 = 1,
82678 + [1107].file = "mm/process_vm_access.c",
82679 + [1107].name = "process_vm_rw_single_vec",
82680 + [1107].param1 = 1,
82681 + [1107].param2 = 1,
82682 + [11230].file = "net/core/neighbour.c",
82683 + [11230].name = "neigh_hash_grow",
82684 + [11230].param2 = 1,
82685 + [11364].file = "fs/ext4/super.c",
82686 + [11364].name = "ext4_kvzalloc",
82687 + [11364].param1 = 1,
82688 + [114].file = "security/selinux/selinuxfs.c",
82689 + [114].name = "sel_write_relabel",
82690 + [114].param3 = 1,
82691 + [11549].file = "drivers/media/rc/redrat3.c",
82692 + [11549].name = "redrat3_transmit_ir",
82693 + [11549].param3 = 1,
82694 + [11568].file = "drivers/gpu/drm/drm_scatter.c",
82695 + [11568].name = "drm_vmalloc_dma",
82696 + [11568].param1 = 1,
82697 + [11582].file = "drivers/scsi/lpfc/lpfc_sli.c",
82698 + [11582].name = "lpfc_sli4_queue_alloc",
82699 + [11582].param3 = 1,
82700 + [11616].file = "security/selinux/selinuxfs.c",
82701 + [11616].name = "sel_write_enforce",
82702 + [11616].param3 = 1,
82703 + [11699].file = "drivers/net/ethernet/neterion/vxge/vxge-config.h",
82704 + [11699].name = "vxge_os_dma_malloc",
82705 + [11699].param2 = 1,
82706 + [11766].file = "drivers/block/paride/pt.c",
82707 + [11766].name = "pt_read",
82708 + [11766].param3 = 1,
82709 + [11784].file = "fs/bio.c",
82710 + [11784].name = "bio_kmalloc",
82711 + [11784].param2 = 1,
82712 + [11919].file = "drivers/lguest/core.c",
82713 + [11919].name = "__lgread",
82714 + [11919].param4 = 1,
82715 + [11925].file = "drivers/media/video/cx18/cx18-fileops.c",
82716 + [11925].name = "cx18_copy_mdl_to_user",
82717 + [11925].param4 = 1,
82718 + [11985].file = "drivers/block/floppy.c",
82719 + [11985].name = "fd_copyin",
82720 + [11985].param3 = 1,
82721 + [11986].file = "drivers/net/usb/asix.c",
82722 + [11986].name = "asix_read_cmd",
82723 + [11986].param5 = 1,
82724 + [12018].file = "sound/core/oss/pcm_oss.c",
82725 + [12018].name = "snd_pcm_oss_read1",
82726 + [12018].param3 = 1,
82727 + [12059].file = "drivers/net/wireless/libertas/debugfs.c",
82728 + [12059].name = "lbs_debugfs_write",
82729 + [12059].param3 = 1,
82730 + [12151].file = "fs/compat.c",
82731 + [12151].name = "compat_rw_copy_check_uvector",
82732 + [12151].param3 = 1,
82733 + [12205].file = "fs/reiserfs/journal.c",
82734 + [12205].name = "reiserfs_allocate_list_bitmaps",
82735 + [12205].param3 = 1,
82736 + [12234].file = "include/acpi/platform/aclinux.h",
82737 + [12234].name = "acpi_os_allocate",
82738 + [12234].param1 = 1,
82739 + [1227].file = "lib/cpu_rmap.c",
82740 + [1227].name = "alloc_cpu_rmap",
82741 + [1227].param1 = 1,
82742 + [12395].file = "drivers/char/hw_random/core.c",
82743 + [12395].name = "rng_dev_read",
82744 + [12395].param3 = 1,
82745 + [12602].file = "net/sunrpc/cache.c",
82746 + [12602].name = "cache_downcall",
82747 + [12602].param3 = 1,
82748 + [12712].file = "drivers/net/wimax/i2400m/fw.c",
82749 + [12712].name = "i2400m_zrealloc_2x",
82750 + [12712].param3 = 1,
82751 + [12755].file = "sound/drivers/opl4/opl4_proc.c",
82752 + [12755].name = "snd_opl4_mem_proc_read",
82753 + [12755].param5 = 1,
82754 + [12833].file = "net/sctp/auth.c",
82755 + [12833].name = "sctp_auth_create_key",
82756 + [12833].param1 = 1,
82757 + [12840].file = "net/sctp/tsnmap.c",
82758 + [12840].name = "sctp_tsnmap_mark",
82759 + [12840].param2 = 1,
82760 + [12931].file = "drivers/hid/hid-roccat.c",
82761 + [12931].name = "roccat_read",
82762 + [12931].param3 = 1,
82763 + [12954].file = "fs/proc/base.c",
82764 + [12954].name = "oom_adjust_write",
82765 + [12954].param3 = 1,
82766 + [13103].file = "drivers/acpi/acpica/utobject.c",
82767 + [13103].name = "acpi_ut_create_string_object",
82768 + [13103].param1 = 1,
82769 + [13121].file = "net/ipv4/ip_sockglue.c",
82770 + [13121].name = "do_ip_setsockopt",
82771 + [13121].param5 = 1,
82772 + [1327].file = "net/netfilter/nfnetlink_log.c",
82773 + [1327].name = "nfulnl_alloc_skb",
82774 + [1327].param2 = 1,
82775 + [13337].file = "net/core/iovec.c",
82776 + [13337].name = "csum_partial_copy_fromiovecend",
82777 + [13337].param4 = 1,
82778 + [13339].file = "security/smack/smackfs.c",
82779 + [13339].name = "smk_write_netlbladdr",
82780 + [13339].param3 = 1,
82781 + [13342].file = "fs/jbd2/journal.c",
82782 + [13342].name = "jbd2_alloc",
82783 + [13342].param1 = 1,
82784 + [13384].file = "drivers/char/virtio_console.c",
82785 + [13384].name = "alloc_buf",
82786 + [13384].param1 = 1,
82787 + [13412].file = "fs/proc/base.c",
82788 + [13412].name = "oom_score_adj_write",
82789 + [13412].param3 = 1,
82790 + [13559].file = "drivers/media/video/ivtv/ivtv-fileops.c",
82791 + [13559].name = "ivtv_read",
82792 + [13559].param3 = 1,
82793 + [13618].file = "drivers/net/team/team.c",
82794 + [13618].name = "team_options_register",
82795 + [13618].param3 = 1,
82796 + [13659].file = "drivers/net/wan/hdlc.c",
82797 + [13659].name = "attach_hdlc_protocol",
82798 + [13659].param3 = 1,
82799 + [13708].file = "drivers/usb/misc/usbtest.c",
82800 + [13708].name = "simple_alloc_urb",
82801 + [13708].param3 = 1,
82802 + [13805].file = "drivers/misc/altera-stapl/altera-jtag.c",
82803 + [13805].name = "altera_swap_dr",
82804 + [13805].param2 = 1,
82805 + [13868].file = "fs/lockd/mon.c",
82806 + [13868].name = "nsm_create_handle",
82807 + [13868].param4 = 1,
82808 + [13924].file = "net/ipv4/netfilter/ip_tables.c",
82809 + [13924].name = "do_ipt_set_ctl",
82810 + [13924].param4 = 1,
82811 + [14019].file = "net/dns_resolver/dns_key.c",
82812 + [14019].name = "dns_resolver_instantiate",
82813 + [14019].param2 = 1,
82814 + [14019].param3 = 1,
82815 + [14025].file = "net/ax25/af_ax25.c",
82816 + [14025].name = "ax25_setsockopt",
82817 + [14025].param5 = 1,
82818 + [14029].file = "drivers/spi/spidev.c",
82819 + [14029].name = "spidev_compat_ioctl",
82820 + [14029].param2 = 1,
82821 + [14090].file = "drivers/bluetooth/btmrvl_debugfs.c",
82822 + [14090].name = "btmrvl_hsmode_write",
82823 + [14090].param3 = 1,
82824 + [14149].file = "drivers/hid/hidraw.c",
82825 + [14149].name = "hidraw_ioctl",
82826 + [14149].param2 = 1,
82827 + [14153].file = "drivers/staging/bcm/led_control.c",
82828 + [14153].name = "ValidateDSDParamsChecksum",
82829 + [14153].param3 = 1,
82830 + [14174].file = "sound/pci/es1938.c",
82831 + [14174].name = "snd_es1938_capture_copy",
82832 + [14174].param5 = 1,
82833 + [14207].file = "drivers/media/video/v4l2-event.c",
82834 + [14207].name = "v4l2_event_subscribe",
82835 + [14207].param3 = 1,
82836 + [14241].file = "drivers/platform/x86/asus_acpi.c",
82837 + [14241].name = "brn_proc_write",
82838 + [14241].param3 = 1,
82839 + [14345].file = "fs/cachefiles/daemon.c",
82840 + [14345].name = "cachefiles_daemon_write",
82841 + [14345].param3 = 1,
82842 + [14347].file = "drivers/media/dvb/dvb-core/dvb_ca_en50221.c",
82843 + [14347].name = "dvb_ca_en50221_io_write",
82844 + [14347].param3 = 1,
82845 + [14566].file = "drivers/pci/hotplug/ibmphp_ebda.c",
82846 + [14566].name = "alloc_ebda_hpc",
82847 + [14566].param1 = 1,
82848 + [14566].param2 = 1,
82849 + [1458].file = "drivers/misc/lkdtm.c",
82850 + [1458].name = "direct_entry",
82851 + [1458].param3 = 1,
82852 + [14646].file = "fs/compat.c",
82853 + [14646].name = "compat_writev",
82854 + [14646].param3 = 1,
82855 + [14684].file = "drivers/media/video/stk-webcam.c",
82856 + [14684].name = "stk_allocate_buffers",
82857 + [14684].param2 = 1,
82858 + [14736].file = "drivers/usb/misc/usbtest.c",
82859 + [14736].name = "unlink_queued",
82860 + [14736].param3 = 1,
82861 + [1482].file = "drivers/scsi/scsi_netlink.c",
82862 + [1482].name = "scsi_nl_send_vendor_msg",
82863 + [1482].param5 = 1,
82864 + [15017].file = "drivers/edac/edac_device.c",
82865 + [15017].name = "edac_device_alloc_ctl_info",
82866 + [15017].param1 = 1,
82867 + [15044].file = "drivers/uio/uio.c",
82868 + [15044].name = "uio_write",
82869 + [15044].param3 = 1,
82870 + [15087].file = "fs/bio.c",
82871 + [15087].name = "bio_map_kern",
82872 + [15087].param2 = 1,
82873 + [15087].param3 = 1,
82874 + [15112].file = "drivers/xen/evtchn.c",
82875 + [15112].name = "evtchn_write",
82876 + [15112].param3 = 1,
82877 + [15130].file = "net/bluetooth/hci_core.c",
82878 + [15130].name = "hci_send_cmd",
82879 + [15130].param3 = 1,
82880 + [15202].file = "net/bluetooth/rfcomm/tty.c",
82881 + [15202].name = "rfcomm_wmalloc",
82882 + [15202].param2 = 1,
82883 + [15274].file = "crypto/shash.c",
82884 + [15274].name = "crypto_shash_setkey",
82885 + [15274].param3 = 1,
82886 + [15354].file = "drivers/isdn/mISDN/socket.c",
82887 + [15354].name = "mISDN_sock_sendmsg",
82888 + [15354].param4 = 1,
82889 + [15361].file = "drivers/char/agp/generic.c",
82890 + [15361].name = "agp_allocate_memory",
82891 + [15361].param2 = 1,
82892 + [15497].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
82893 + [15497].name = "ts_read",
82894 + [15497].param3 = 1,
82895 + [15551].file = "net/ipv4/netfilter/ipt_CLUSTERIP.c",
82896 + [15551].name = "clusterip_proc_write",
82897 + [15551].param3 = 1,
82898 + [15701].file = "drivers/hid/hid-roccat-common.c",
82899 + [15701].name = "roccat_common_receive",
82900 + [15701].param4 = 1,
82901 + [1572].file = "net/ceph/pagevec.c",
82902 + [1572].name = "ceph_copy_page_vector_to_user",
82903 + [1572].param4 = 1,
82904 + [15814].file = "net/mac80211/debugfs_netdev.c",
82905 + [15814].name = "ieee80211_if_write",
82906 + [15814].param3 = 1,
82907 + [15883].file = "security/keys/keyctl.c",
82908 + [15883].name = "sys_add_key",
82909 + [15883].param4 = 1,
82910 + [15884].file = "fs/exofs/super.c",
82911 + [15884].name = "exofs_read_lookup_dev_table",
82912 + [15884].param3 = 1,
82913 + [16037].file = "drivers/staging/media/easycap/easycap_sound.c",
82914 + [16037].name = "easycap_alsa_vmalloc",
82915 + [16037].param2 = 1,
82916 + [16073].file = "net/sctp/socket.c",
82917 + [16073].name = "sctp_setsockopt",
82918 + [16073].param5 = 1,
82919 + [16132].file = "drivers/staging/vme/devices/vme_user.c",
82920 + [16132].name = "buffer_from_user",
82921 + [16132].param3 = 1,
82922 + [16138].file = "security/selinux/ss/services.c",
82923 + [16138].name = "security_context_to_sid_force",
82924 + [16138].param2 = 1,
82925 + [16166].file = "drivers/platform/x86/thinkpad_acpi.c",
82926 + [16166].name = "dispatch_proc_write",
82927 + [16166].param3 = 1,
82928 + [16229].file = "drivers/scsi/scsi_transport_iscsi.c",
82929 + [16229].name = "iscsi_offload_mesg",
82930 + [16229].param5 = 1,
82931 + [16353].file = "drivers/base/regmap/regmap.c",
82932 + [16353].name = "regmap_raw_write",
82933 + [16353].param4 = 1,
82934 + [16383].file = "fs/proc/base.c",
82935 + [16383].name = "comm_write",
82936 + [16383].param3 = 1,
82937 + [16396].file = "drivers/misc/altera-stapl/altera-jtag.c",
82938 + [16396].name = "altera_irscan",
82939 + [16396].param2 = 1,
82940 + [16447].file = "drivers/hid/usbhid/hiddev.c",
82941 + [16447].name = "hiddev_ioctl",
82942 + [16447].param2 = 1,
82943 + [16453].file = "include/linux/slab.h",
82944 + [16453].name = "kzalloc",
82945 + [16453].param1 = 1,
82946 + [16605].file = "fs/ecryptfs/miscdev.c",
82947 + [16605].name = "ecryptfs_send_miscdev",
82948 + [16605].param2 = 1,
82949 + [16606].file = "drivers/ide/ide-tape.c",
82950 + [16606].name = "idetape_chrdev_write",
82951 + [16606].param3 = 1,
82952 + [16637].file = "security/keys/encrypted-keys/encrypted.c",
82953 + [16637].name = "datablob_hmac_verify",
82954 + [16637].param4 = 1,
82955 + [16828].file = "net/batman-adv/hash.c",
82956 + [16828].name = "hash_new",
82957 + [16828].param1 = 1,
82958 + [16853].file = "drivers/net/ethernet/chelsio/cxgb4vf/sge.c",
82959 + [16853].name = "t4vf_pktgl_to_skb",
82960 + [16853].param2 = 1,
82961 + [16911].file = "drivers/media/dvb/ttpci/av7110_hw.c",
82962 + [16911].name = "LoadBitmap",
82963 + [16911].param2 = 1,
82964 + [169].file = "drivers/net/ethernet/amd/pcnet32.c",
82965 + [169].name = "pcnet32_realloc_rx_ring",
82966 + [169].param3 = 1,
82967 + [17075].file = "sound/isa/gus/gus_dram.c",
82968 + [17075].name = "snd_gus_dram_write",
82969 + [17075].param4 = 1,
82970 + [17133].file = "drivers/usb/misc/iowarrior.c",
82971 + [17133].name = "iowarrior_read",
82972 + [17133].param3 = 1,
82973 + [17185].file = "net/wireless/scan.c",
82974 + [17185].name = "cfg80211_inform_bss",
82975 + [17185].param8 = 1,
82976 + [17349].file = "net/tipc/link.c",
82977 + [17349].name = "tipc_link_send_sections_fast",
82978 + [17349].param4 = 1,
82979 + [17377].file = "drivers/usb/class/cdc-wdm.c",
82980 + [17377].name = "wdm_write",
82981 + [17377].param3 = 1,
82982 + [17459].file = "drivers/usb/misc/rio500.c",
82983 + [17459].name = "write_rio",
82984 + [17459].param3 = 1,
82985 + [17460].file = "fs/nfsd/nfscache.c",
82986 + [17460].name = "nfsd_cache_update",
82987 + [17460].param3 = 1,
82988 + [17492].file = "net/dccp/proto.c",
82989 + [17492].name = "do_dccp_setsockopt",
82990 + [17492].param5 = 1,
82991 + [1754].file = "sound/core/oss/pcm_oss.c",
82992 + [1754].name = "snd_pcm_oss_write",
82993 + [1754].param3 = 1,
82994 + [17604].file = "fs/proc/generic.c",
82995 + [17604].name = "__proc_file_read",
82996 + [17604].param3 = 1,
82997 + [17718].file = "net/caif/caif_socket.c",
82998 + [17718].name = "setsockopt",
82999 + [17718].param5 = 1,
83000 + [17828].file = "kernel/sched/core.c",
83001 + [17828].name = "sched_feat_write",
83002 + [17828].param3 = 1,
83003 + [17841].file = "drivers/misc/tifm_core.c",
83004 + [17841].name = "tifm_alloc_adapter",
83005 + [17841].param1 = 1,
83006 + [17946].file = "drivers/net/wireless/libertas/if_spi.c",
83007 + [17946].name = "if_spi_host_to_card",
83008 + [17946].param4 = 1,
83009 + [1800].file = "drivers/media/dvb/dvb-core/dmxdev.c",
83010 + [1800].name = "dvb_dvr_do_ioctl",
83011 + [1800].param3 = 1,
83012 + [18119].file = "drivers/misc/iwmc3200top/fw-download.c",
83013 + [18119].name = "iwmct_fw_parser_init",
83014 + [18119].param4 = 1,
83015 + [18140].file = "drivers/scsi/pm8001/pm8001_ctl.c",
83016 + [18140].name = "pm8001_store_update_fw",
83017 + [18140].param4 = 1,
83018 + [18191].file = "sound/pci/hda/patch_realtek.c",
83019 + [18191].name = "new_bind_ctl",
83020 + [18191].param2 = 1,
83021 + [18224].file = "drivers/xen/grant-table.c",
83022 + [18224].name = "gnttab_map",
83023 + [18224].param2 = 1,
83024 + [18232].file = "fs/nfs/write.c",
83025 + [18232].name = "nfs_writedata_alloc",
83026 + [18232].param1 = 1,
83027 + [18247].file = "drivers/char/agp/generic.c",
83028 + [18247].name = "agp_create_user_memory",
83029 + [18247].param1 = 1,
83030 + [18303].file = "fs/xattr.c",
83031 + [18303].name = "getxattr",
83032 + [18303].param4 = 1,
83033 + [18353].file = "net/rfkill/core.c",
83034 + [18353].name = "rfkill_fop_read",
83035 + [18353].param3 = 1,
83036 + [18386].file = "fs/read_write.c",
83037 + [18386].name = "vfs_readv",
83038 + [18386].param3 = 1,
83039 + [18391].file = "fs/ocfs2/stack_user.c",
83040 + [18391].name = "ocfs2_control_write",
83041 + [18391].param3 = 1,
83042 + [183].file = "crypto/ahash.c",
83043 + [183].name = "crypto_ahash_setkey",
83044 + [183].param3 = 1,
83045 + [18406].file = "drivers/media/video/tm6000/tm6000-core.c",
83046 + [18406].name = "tm6000_read_write_usb",
83047 + [18406].param7 = 1,
83048 + [1845].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83049 + [1845].name = "rt2x00debug_write_rf",
83050 + [1845].param3 = 1,
83051 + [18465].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
83052 + [18465].name = "cxgb_alloc_mem",
83053 + [18465].param1 = 1,
83054 + [184].file = "drivers/firewire/nosy.c",
83055 + [184].name = "packet_buffer_init",
83056 + [184].param2 = 1,
83057 + [1858].file = "net/ipv6/netfilter/ip6_tables.c",
83058 + [1858].name = "do_ip6t_set_ctl",
83059 + [1858].param4 = 1,
83060 + [18659].file = "drivers/media/dvb/dvb-core/dvbdev.c",
83061 + [18659].name = "dvb_usercopy",
83062 + [18659].param2 = 1,
83063 + [18722].file = "security/tomoyo/condition.c",
83064 + [18722].name = "tomoyo_scan_bprm",
83065 + [18722].param2 = 1,
83066 + [18722].param4 = 1,
83067 + [18775].file = "include/linux/textsearch.h",
83068 + [18775].name = "alloc_ts_config",
83069 + [18775].param1 = 1,
83070 + [18940].file = "drivers/usb/host/hwa-hc.c",
83071 + [18940].name = "__hwahc_op_set_gtk",
83072 + [18940].param4 = 1,
83073 + [19012].file = "drivers/acpi/event.c",
83074 + [19012].name = "acpi_system_read_event",
83075 + [19012].param3 = 1,
83076 + [19028].file = "mm/filemap.c",
83077 + [19028].name = "iov_iter_copy_from_user_atomic",
83078 + [19028].param4 = 1,
83079 + [19107].file = "security/smack/smackfs.c",
83080 + [19107].name = "smk_write_load_list",
83081 + [19107].param3 = 1,
83082 + [19240].file = "net/sctp/socket.c",
83083 + [19240].name = "sctp_setsockopt_delayed_ack",
83084 + [19240].param3 = 1,
83085 + [19274].file = "net/core/pktgen.c",
83086 + [19274].name = "pktgen_if_write",
83087 + [19274].param3 = 1,
83088 + [19286].file = "drivers/base/regmap/regmap.c",
83089 + [19286].name = "_regmap_raw_write",
83090 + [19286].param4 = 1,
83091 + [19308].file = "drivers/char/mem.c",
83092 + [19308].name = "read_oldmem",
83093 + [19308].param3 = 1,
83094 + [19343].file = "security/keys/encrypted-keys/encrypted.c",
83095 + [19343].name = "datablob_hmac_append",
83096 + [19343].param3 = 1,
83097 + [19349].file = "drivers/acpi/acpica/utobject.c",
83098 + [19349].name = "acpi_ut_create_package_object",
83099 + [19349].param1 = 1,
83100 + [19453].file = "drivers/net/ethernet/chelsio/cxgb/sge.c",
83101 + [19453].name = "sge_rx",
83102 + [19453].param3 = 1,
83103 + [19504].file = "drivers/usb/serial/garmin_gps.c",
83104 + [19504].name = "pkt_add",
83105 + [19504].param3 = 1,
83106 + [19522].file = "mm/percpu.c",
83107 + [19522].name = "pcpu_mem_zalloc",
83108 + [19522].param1 = 1,
83109 + [19548].file = "drivers/scsi/qla2xxx/qla_init.c",
83110 + [19548].name = "qla2x00_get_ctx_sp",
83111 + [19548].param3 = 1,
83112 + [19592].file = "net/dccp/proto.c",
83113 + [19592].name = "dccp_setsockopt_service",
83114 + [19592].param4 = 1,
83115 + [19726].file = "kernel/trace/trace.c",
83116 + [19726].name = "tracing_set_trace_write",
83117 + [19726].param3 = 1,
83118 + [19738].file = "fs/sysfs/file.c",
83119 + [19738].name = "sysfs_write_file",
83120 + [19738].param3 = 1,
83121 + [19833].file = "drivers/xen/privcmd.c",
83122 + [19833].name = "gather_array",
83123 + [19833].param3 = 1,
83124 + [19910].file = "drivers/media/video/saa7164/saa7164-buffer.c",
83125 + [19910].name = "saa7164_buffer_alloc_user",
83126 + [19910].param2 = 1,
83127 + [19920].file = "drivers/input/joydev.c",
83128 + [19920].name = "joydev_ioctl",
83129 + [19920].param2 = 1,
83130 + [19931].file = "drivers/usb/misc/ftdi-elan.c",
83131 + [19931].name = "ftdi_elan_write",
83132 + [19931].param3 = 1,
83133 + [19960].file = "drivers/usb/class/usblp.c",
83134 + [19960].name = "usblp_read",
83135 + [19960].param3 = 1,
83136 + [1996].file = "drivers/scsi/libsrp.c",
83137 + [1996].name = "srp_target_alloc",
83138 + [1996].param3 = 1,
83139 + [20023].file = "drivers/media/video/gspca/gspca.c",
83140 + [20023].name = "dev_read",
83141 + [20023].param3 = 1,
83142 + [20207].file = "net/core/sock.c",
83143 + [20207].name = "sock_alloc_send_pskb",
83144 + [20207].param2 = 1,
83145 + [20263].file = "kernel/trace/trace_events.c",
83146 + [20263].name = "event_filter_write",
83147 + [20263].param3 = 1,
83148 + [20314].file = "drivers/gpu/drm/drm_hashtab.c",
83149 + [20314].name = "drm_ht_create",
83150 + [20314].param2 = 1,
83151 + [20320].file = "drivers/mfd/sm501.c",
83152 + [20320].name = "sm501_create_subdev",
83153 + [20320].param3 = 1,
83154 + [20320].param4 = 1,
83155 + [20376].file = "mm/nobootmem.c",
83156 + [20376].name = "__alloc_bootmem_nopanic",
83157 + [20376].param1 = 1,
83158 + [20409].file = "drivers/media/dvb/dvb-usb/opera1.c",
83159 + [20409].name = "opera1_usb_i2c_msgxfer",
83160 + [20409].param4 = 1,
83161 + [20473].file = "drivers/mtd/mtdchar.c",
83162 + [20473].name = "mtdchar_write",
83163 + [20473].param3 = 1,
83164 + [20611].file = "net/netfilter/x_tables.c",
83165 + [20611].name = "xt_alloc_table_info",
83166 + [20611].param1 = 1,
83167 + [20618].file = "drivers/staging/crystalhd/crystalhd_lnx.c",
83168 + [20618].name = "chd_dec_fetch_cdata",
83169 + [20618].param3 = 1,
83170 + [20713].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
83171 + [20713].name = "ttm_bo_io",
83172 + [20713].param5 = 1,
83173 + [20801].file = "drivers/vhost/vhost.c",
83174 + [20801].name = "vhost_add_used_n",
83175 + [20801].param3 = 1,
83176 + [20835].file = "drivers/isdn/i4l/isdn_common.c",
83177 + [20835].name = "isdn_read",
83178 + [20835].param3 = 1,
83179 + [20951].file = "crypto/rng.c",
83180 + [20951].name = "rngapi_reset",
83181 + [20951].param3 = 1,
83182 + [21125].file = "fs/gfs2/dir.c",
83183 + [21125].name = "gfs2_alloc_sort_buffer",
83184 + [21125].param1 = 1,
83185 + [21132].file = "kernel/cgroup.c",
83186 + [21132].name = "cgroup_write_X64",
83187 + [21132].param5 = 1,
83188 + [21138].file = "drivers/uio/uio.c",
83189 + [21138].name = "uio_read",
83190 + [21138].param3 = 1,
83191 + [21193].file = "net/wireless/sme.c",
83192 + [21193].name = "cfg80211_disconnected",
83193 + [21193].param4 = 1,
83194 + [21312].file = "lib/ts_kmp.c",
83195 + [21312].name = "kmp_init",
83196 + [21312].param2 = 1,
83197 + [21335].file = "net/econet/af_econet.c",
83198 + [21335].name = "econet_sendmsg",
83199 + [21335].param4 = 1,
83200 + [21406].file = "fs/libfs.c",
83201 + [21406].name = "simple_write_to_buffer",
83202 + [21406].param2 = 1,
83203 + [21406].param5 = 1,
83204 + [21451].file = "net/netfilter/ipvs/ip_vs_ctl.c",
83205 + [21451].name = "do_ip_vs_set_ctl",
83206 + [21451].param4 = 1,
83207 + [21459].file = "security/smack/smackfs.c",
83208 + [21459].name = "smk_write_doi",
83209 + [21459].param3 = 1,
83210 + [21508].file = "include/linux/usb/wusb.h",
83211 + [21508].name = "wusb_prf_64",
83212 + [21508].param7 = 1,
83213 + [21511].file = "drivers/input/ff-core.c",
83214 + [21511].name = "input_ff_create",
83215 + [21511].param2 = 1,
83216 + [21538].file = "net/bluetooth/l2cap_sock.c",
83217 + [21538].name = "l2cap_sock_setsockopt",
83218 + [21538].param5 = 1,
83219 + [21543].file = "drivers/media/video/gspca/gspca.c",
83220 + [21543].name = "frame_alloc",
83221 + [21543].param4 = 1,
83222 + [21608].file = "drivers/char/tpm/tpm.c",
83223 + [21608].name = "tpm_write",
83224 + [21608].param3 = 1,
83225 + [2160].file = "drivers/net/wireless/ray_cs.c",
83226 + [2160].name = "int_proc_write",
83227 + [2160].param3 = 1,
83228 + [21632].file = "fs/afs/cell.c",
83229 + [21632].name = "afs_cell_create",
83230 + [21632].param2 = 1,
83231 + [21679].file = "drivers/net/wireless/ath/carl9170/debug.c",
83232 + [21679].name = "carl9170_debugfs_write",
83233 + [21679].param3 = 1,
83234 + [21784].file = "crypto/ahash.c",
83235 + [21784].name = "ahash_setkey_unaligned",
83236 + [21784].param3 = 1,
83237 + [2180].file = "drivers/char/ppdev.c",
83238 + [2180].name = "pp_write",
83239 + [2180].param3 = 1,
83240 + [21810].file = "net/core/netprio_cgroup.c",
83241 + [21810].name = "extend_netdev_table",
83242 + [21810].param2 = 1,
83243 + [21906].file = "net/atm/mpc.c",
83244 + [21906].name = "copy_macs",
83245 + [21906].param4 = 1,
83246 + [21946].file = "fs/nfs/idmap.c",
83247 + [21946].name = "nfs_map_name_to_uid",
83248 + [21946].param3 = 1,
83249 + [22052].file = "drivers/net/ethernet/chelsio/cxgb3/sge.c",
83250 + [22052].name = "get_packet_pg",
83251 + [22052].param4 = 1,
83252 + [22085].file = "drivers/staging/sep/sep_driver.c",
83253 + [22085].name = "sep_lock_user_pages",
83254 + [22085].param2 = 1,
83255 + [22085].param3 = 1,
83256 + [22190].file = "drivers/char/tpm/tpm.c",
83257 + [22190].name = "tpm_read",
83258 + [22190].param3 = 1,
83259 + [22291].file = "net/core/pktgen.c",
83260 + [22291].name = "pgctrl_write",
83261 + [22291].param3 = 1,
83262 + [22439].file = "fs/afs/rxrpc.c",
83263 + [22439].name = "afs_alloc_flat_call",
83264 + [22439].param2 = 1,
83265 + [22439].param3 = 1,
83266 + [2243].file = "drivers/scsi/scsi_tgt_lib.c",
83267 + [2243].name = "scsi_tgt_kspace_exec",
83268 + [2243].param8 = 1,
83269 + [22440].file = "drivers/uwb/neh.c",
83270 + [22440].name = "uwb_rc_neh_grok_event",
83271 + [22440].param3 = 1,
83272 + [22611].file = "drivers/staging/android/logger.c",
83273 + [22611].name = "do_write_log_from_user",
83274 + [22611].param3 = 1,
83275 + [22614].file = "drivers/media/video/cx18/cx18-fileops.c",
83276 + [22614].name = "cx18_copy_buf_to_user",
83277 + [22614].param4 = 1,
83278 + [22667].file = "drivers/misc/altera-stapl/altera-jtag.c",
83279 + [22667].name = "altera_set_ir_post",
83280 + [22667].param2 = 1,
83281 + [22772].file = "drivers/target/iscsi/iscsi_target_erl1.c",
83282 + [22772].name = "iscsit_dump_data_payload",
83283 + [22772].param2 = 1,
83284 + [22777].file = "drivers/infiniband/ulp/srp/ib_srp.c",
83285 + [22777].name = "srp_alloc_iu",
83286 + [22777].param2 = 1,
83287 + [22811].file = "drivers/usb/dwc3/debugfs.c",
83288 + [22811].name = "dwc3_mode_write",
83289 + [22811].param3 = 1,
83290 + [22817].file = "drivers/media/video/usbvision/usbvision-core.c",
83291 + [22817].name = "usbvision_rvmalloc",
83292 + [22817].param1 = 1,
83293 + [22864].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83294 + [22864].name = "ath6kl_add_bss_if_needed",
83295 + [22864].param6 = 1,
83296 + [2286].file = "drivers/scsi/mvumi.c",
83297 + [2286].name = "mvumi_alloc_mem_resource",
83298 + [2286].param3 = 1,
83299 + [22904].file = "security/selinux/ss/services.c",
83300 + [22904].name = "security_context_to_sid_default",
83301 + [22904].param2 = 1,
83302 + [22932].file = "fs/compat.c",
83303 + [22932].name = "compat_sys_writev",
83304 + [22932].param3 = 1,
83305 + [2302].file = "drivers/media/video/stk-webcam.c",
83306 + [2302].name = "v4l_stk_read",
83307 + [2302].param3 = 1,
83308 + [2307].file = "drivers/pcmcia/cistpl.c",
83309 + [2307].name = "pcmcia_replace_cis",
83310 + [2307].param3 = 1,
83311 + [23117].file = "drivers/media/dvb/ttpci/av7110_av.c",
83312 + [23117].name = "dvb_audio_write",
83313 + [23117].param3 = 1,
83314 + [23220].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
83315 + [23220].name = "do_dmabuf_dirty_sou",
83316 + [23220].param7 = 1,
83317 + [23232].file = "drivers/md/persistent-data/dm-space-map-checker.c",
83318 + [23232].name = "sm_checker_extend",
83319 + [23232].param2 = 1,
83320 + [2324].file = "net/ieee802154/wpan-class.c",
83321 + [2324].name = "wpan_phy_alloc",
83322 + [2324].param1 = 1,
83323 + [2328].file = "kernel/trace/ftrace.c",
83324 + [2328].name = "ftrace_pid_write",
83325 + [2328].param3 = 1,
83326 + [23290].file = "fs/proc/base.c",
83327 + [23290].name = "mem_rw",
83328 + [23290].param3 = 1,
83329 + [23449].file = "crypto/blkcipher.c",
83330 + [23449].name = "blkcipher_next_slow",
83331 + [23449].param3 = 1,
83332 + [23449].param4 = 1,
83333 + [23535].file = "ipc/sem.c",
83334 + [23535].name = "sys_semtimedop",
83335 + [23535].param3 = 1,
83336 + [2357].file = "drivers/usb/serial/garmin_gps.c",
83337 + [2357].name = "garmin_read_process",
83338 + [2357].param3 = 1,
83339 + [23589].file = "kernel/relay.c",
83340 + [23589].name = "subbuf_read_actor",
83341 + [23589].param3 = 1,
83342 + [23848].file = "crypto/blkcipher.c",
83343 + [23848].name = "async_setkey",
83344 + [23848].param3 = 1,
83345 + [2386].file = "drivers/acpi/acpica/exnames.c",
83346 + [2386].name = "acpi_ex_allocate_name_string",
83347 + [2386].param2 = 1,
83348 + [2389].file = "net/core/sock.c",
83349 + [2389].name = "sock_rmalloc",
83350 + [2389].param2 = 1,
83351 + [23994].file = "net/bluetooth/mgmt.c",
83352 + [23994].name = "set_powered",
83353 + [23994].param4 = 1,
83354 + [23999].file = "sound/pci/rme9652/hdsp.c",
83355 + [23999].name = "snd_hdsp_capture_copy",
83356 + [23999].param5 = 1,
83357 + [24233].file = "drivers/pci/pcie/aer/aer_inject.c",
83358 + [24233].name = "aer_inject_write",
83359 + [24233].param3 = 1,
83360 + [24359].file = "kernel/power/qos.c",
83361 + [24359].name = "pm_qos_power_write",
83362 + [24359].param3 = 1,
83363 + [24457].file = "fs/btrfs/backref.c",
83364 + [24457].name = "init_data_container",
83365 + [24457].param1 = 1,
83366 + [24719].file = "drivers/input/evdev.c",
83367 + [24719].name = "bits_to_user",
83368 + [24719].param3 = 1,
83369 + [2472].file = "net/ipv4/netfilter/ip_tables.c",
83370 + [2472].name = "compat_do_ipt_set_ctl",
83371 + [2472].param4 = 1,
83372 + [24755].file = "drivers/infiniband/hw/qib/qib_diag.c",
83373 + [24755].name = "qib_diag_write",
83374 + [24755].param3 = 1,
83375 + [24805].file = "security/keys/user_defined.c",
83376 + [24805].name = "user_update",
83377 + [24805].param3 = 1,
83378 + [25036].file = "fs/pipe.c",
83379 + [25036].name = "pipe_iov_copy_from_user",
83380 + [25036].param3 = 1,
83381 + [25078].file = "drivers/net/wireless/p54/fwio.c",
83382 + [25078].name = "p54_download_eeprom",
83383 + [25078].param4 = 1,
83384 + [25127].file = "drivers/scsi/device_handler/scsi_dh_alua.c",
83385 + [25127].name = "realloc_buffer",
83386 + [25127].param2 = 1,
83387 + [25145].file = "net/tipc/link.c",
83388 + [25145].name = "link_send_sections_long",
83389 + [25145].param4 = 1,
83390 + [25157].file = "security/keys/request_key_auth.c",
83391 + [25157].name = "request_key_auth_new",
83392 + [25157].param3 = 1,
83393 + [25158].file = "drivers/net/ethernet/mellanox/mlx4/en_rx.c",
83394 + [25158].name = "mlx4_en_create_rx_ring",
83395 + [25158].param3 = 1,
83396 + [25267].file = "fs/configfs/file.c",
83397 + [25267].name = "configfs_write_file",
83398 + [25267].param3 = 1,
83399 + [25495].file = "drivers/scsi/bfa/bfad_debugfs.c",
83400 + [25495].name = "bfad_debugfs_write_regwr",
83401 + [25495].param3 = 1,
83402 + [25558].file = "fs/proc/task_mmu.c",
83403 + [25558].name = "clear_refs_write",
83404 + [25558].param3 = 1,
83405 + [25692].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
83406 + [25692].name = "ath6kl_wmi_send_action_cmd",
83407 + [25692].param7 = 1,
83408 + [25765].file = "drivers/media/dvb/b2c2/flexcop.c",
83409 + [25765].name = "flexcop_device_kmalloc",
83410 + [25765].param1 = 1,
83411 + [26100].file = "sound/core/info.c",
83412 + [26100].name = "snd_info_entry_write",
83413 + [26100].param3 = 1,
83414 + [26256].file = "fs/hpfs/name.c",
83415 + [26256].name = "hpfs_translate_name",
83416 + [26256].param3 = 1,
83417 + [26394].file = "drivers/hid/hidraw.c",
83418 + [26394].name = "hidraw_get_report",
83419 + [26394].param3 = 1,
83420 + [26494].file = "kernel/signal.c",
83421 + [26494].name = "sys_rt_sigpending",
83422 + [26494].param2 = 1,
83423 + [26497].file = "security/keys/keyctl.c",
83424 + [26497].name = "sys_keyctl",
83425 + [26497].param4 = 1,
83426 + [26533].file = "drivers/block/aoe/aoechr.c",
83427 + [26533].name = "aoechr_write",
83428 + [26533].param3 = 1,
83429 + [26560].file = "crypto/algapi.c",
83430 + [26560].name = "crypto_alloc_instance2",
83431 + [26560].param3 = 1,
83432 + [26605].file = "security/selinux/selinuxfs.c",
83433 + [26605].name = "sel_write_user",
83434 + [26605].param3 = 1,
83435 + [26620].file = "net/bluetooth/mgmt.c",
83436 + [26620].name = "mgmt_control",
83437 + [26620].param3 = 1,
83438 + [26701].file = "drivers/mtd/chips/cfi_util.c",
83439 + [26701].name = "cfi_read_pri",
83440 + [26701].param3 = 1,
83441 + [26757].file = "fs/xattr.c",
83442 + [26757].name = "sys_fgetxattr",
83443 + [26757].param4 = 1,
83444 + [2678].file = "drivers/platform/x86/asus_acpi.c",
83445 + [2678].name = "disp_proc_write",
83446 + [2678].param3 = 1,
83447 + [26834].file = "drivers/gpu/drm/drm_drv.c",
83448 + [26834].name = "drm_ioctl",
83449 + [26834].param2 = 1,
83450 + [26843].file = "drivers/firewire/core-cdev.c",
83451 + [26843].name = "fw_device_op_compat_ioctl",
83452 + [26843].param2 = 1,
83453 + [26845].file = "drivers/scsi/qla2xxx/qla_bsg.c",
83454 + [26845].name = "qla2x00_get_ctx_bsg_sp",
83455 + [26845].param3 = 1,
83456 + [26888].file = "net/bridge/br_ioctl.c",
83457 + [26888].name = "get_fdb_entries",
83458 + [26888].param3 = 1,
83459 + [26962].file = "drivers/usb/class/usbtmc.c",
83460 + [26962].name = "usbtmc_write",
83461 + [26962].param3 = 1,
83462 + [26966].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
83463 + [26966].name = "ts_write",
83464 + [26966].param3 = 1,
83465 + [27004].file = "drivers/misc/hpilo.c",
83466 + [27004].name = "ilo_write",
83467 + [27004].param3 = 1,
83468 + [27025].file = "fs/ntfs/file.c",
83469 + [27025].name = "__ntfs_copy_from_user_iovec_inatomic",
83470 + [27025].param3 = 1,
83471 + [27025].param4 = 1,
83472 + [27061].file = "drivers/firewire/core-cdev.c",
83473 + [27061].name = "iso_callback",
83474 + [27061].param3 = 1,
83475 + [2711].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
83476 + [2711].name = "dvb_ringbuffer_read_user",
83477 + [2711].param3 = 1,
83478 + [27129].file = "fs/lockd/mon.c",
83479 + [27129].name = "nsm_get_handle",
83480 + [27129].param4 = 1,
83481 + [27142].file = "fs/proc/kcore.c",
83482 + [27142].name = "read_kcore",
83483 + [27142].param3 = 1,
83484 + [27164].file = "include/drm/drm_mem_util.h",
83485 + [27164].name = "drm_calloc_large",
83486 + [27164].param1 = 1,
83487 + [27164].param2 = 1,
83488 + [27176].file = "drivers/mtd/devices/mtd_dataflash.c",
83489 + [27176].name = "otp_read",
83490 + [27176].param2 = 1,
83491 + [27176].param5 = 1,
83492 + [27232].file = "security/apparmor/lib.c",
83493 + [27232].name = "kvmalloc",
83494 + [27232].param1 = 1,
83495 + [27275].file = "drivers/scsi/cxgbi/libcxgbi.c",
83496 + [27275].name = "cxgbi_ddp_reserve",
83497 + [27275].param4 = 1,
83498 + [27280].file = "drivers/net/ethernet/mellanox/mlx4/en_tx.c",
83499 + [27280].name = "mlx4_en_create_tx_ring",
83500 + [27280].param4 = 1,
83501 + [27290].file = "security/selinux/ss/services.c",
83502 + [27290].name = "security_context_to_sid_core",
83503 + [27290].param2 = 1,
83504 + [27302].file = "fs/proc/base.c",
83505 + [27302].name = "proc_loginuid_write",
83506 + [27302].param3 = 1,
83507 + [2730].file = "drivers/target/iscsi/iscsi_target_parameters.c",
83508 + [2730].name = "iscsi_decode_text_input",
83509 + [2730].param4 = 1,
83510 + [27314].file = "net/bluetooth/mgmt.c",
83511 + [27314].name = "cmd_complete",
83512 + [27314].param5 = 1,
83513 + [27472].file = "security/selinux/selinuxfs.c",
83514 + [27472].name = "sel_write_load",
83515 + [27472].param3 = 1,
83516 + [27491].file = "fs/proc/base.c",
83517 + [27491].name = "proc_pid_attr_write",
83518 + [27491].param3 = 1,
83519 + [27568].file = "drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c",
83520 + [27568].name = "t4_alloc_mem",
83521 + [27568].param1 = 1,
83522 + [27582].file = "drivers/platform/x86/asus_acpi.c",
83523 + [27582].name = "ledd_proc_write",
83524 + [27582].param3 = 1,
83525 + [27595].file = "net/core/sock.c",
83526 + [27595].name = "sock_alloc_send_skb",
83527 + [27595].param2 = 1,
83528 + [27648].file = "net/bluetooth/l2cap_core.c",
83529 + [27648].name = "l2cap_bredr_sig_cmd",
83530 + [27648].param3 = 1,
83531 + [27697].file = "drivers/staging/mei/iorw.c",
83532 + [27697].name = "amthi_read",
83533 + [27697].param4 = 1,
83534 + [27911].file = "fs/ext4/resize.c",
83535 + [27911].name = "alloc_flex_gd",
83536 + [27911].param1 = 1,
83537 + [27927].file = "drivers/tty/tty_io.c",
83538 + [27927].name = "redirected_tty_write",
83539 + [27927].param3 = 1,
83540 + [28040].file = "kernel/kfifo.c",
83541 + [28040].name = "__kfifo_alloc",
83542 + [28040].param2 = 1,
83543 + [28040].param3 = 1,
83544 + [28151].file = "mm/filemap_xip.c",
83545 + [28151].name = "do_xip_mapping_read",
83546 + [28151].param5 = 1,
83547 + [28247].file = "net/sctp/tsnmap.c",
83548 + [28247].name = "sctp_tsnmap_init",
83549 + [28247].param2 = 1,
83550 + [28253].file = "include/linux/fb.h",
83551 + [28253].name = "alloc_apertures",
83552 + [28253].param1 = 1,
83553 + [28265].file = "fs/notify/fanotify/fanotify_user.c",
83554 + [28265].name = "fanotify_write",
83555 + [28265].param3 = 1,
83556 + [28316].file = "drivers/input/joydev.c",
83557 + [28316].name = "joydev_ioctl_common",
83558 + [28316].param2 = 1,
83559 + [28359].file = "drivers/spi/spidev.c",
83560 + [28359].name = "spidev_message",
83561 + [28359].param3 = 1,
83562 + [28360].file = "drivers/hid/usbhid/hiddev.c",
83563 + [28360].name = "hiddev_compat_ioctl",
83564 + [28360].param2 = 1,
83565 + [28407].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
83566 + [28407].name = "rt2x00debug_write_csr",
83567 + [28407].param3 = 1,
83568 + [2847].file = "fs/ntfs/file.c",
83569 + [2847].name = "ntfs_copy_from_user",
83570 + [2847].param3 = 1,
83571 + [2847].param5 = 1,
83572 + [28584].file = "drivers/memstick/core/memstick.c",
83573 + [28584].name = "memstick_alloc_host",
83574 + [28584].param1 = 1,
83575 + [28783].file = "drivers/gpu/drm/i915/i915_debugfs.c",
83576 + [28783].name = "i915_cache_sharing_write",
83577 + [28783].param3 = 1,
83578 + [28787].file = "drivers/media/video/videobuf2-core.c",
83579 + [28787].name = "vb2_write",
83580 + [28787].param3 = 1,
83581 + [28879].file = "drivers/base/map.c",
83582 + [28879].name = "kobj_map",
83583 + [28879].param2 = 1,
83584 + [28879].param3 = 1,
83585 + [28889].file = "drivers/char/pcmcia/cm4040_cs.c",
83586 + [28889].name = "cm4040_write",
83587 + [28889].param3 = 1,
83588 + [29073].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
83589 + [29073].name = "vmw_kms_readback",
83590 + [29073].param6 = 1,
83591 + [29085].file = "security/apparmor/apparmorfs.c",
83592 + [29085].name = "profile_load",
83593 + [29085].param3 = 1,
83594 + [29092].file = "lib/lru_cache.c",
83595 + [29092].name = "lc_create",
83596 + [29092].param3 = 1,
83597 + [29257].file = "drivers/vhost/vhost.c",
83598 + [29257].name = "vhost_add_used_and_signal_n",
83599 + [29257].param4 = 1,
83600 + [29267].file = "net/ipv4/fib_trie.c",
83601 + [29267].name = "tnode_alloc",
83602 + [29267].param1 = 1,
83603 + [29338].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
83604 + [29338].name = "bnad_debugfs_write_regwr",
83605 + [29338].param3 = 1,
83606 + [29353].file = "net/sctp/socket.c",
83607 + [29353].name = "sctp_setsockopt_del_key",
83608 + [29353].param3 = 1,
83609 + [29405].file = "drivers/media/dvb/dvb-usb/dw2102.c",
83610 + [29405].name = "dw210x_op_rw",
83611 + [29405].param6 = 1,
83612 + [29542].file = "net/nfc/nci/core.c",
83613 + [29542].name = "nci_send_cmd",
83614 + [29542].param3 = 1,
83615 + [29714].file = "drivers/scsi/cxgbi/libcxgbi.c",
83616 + [29714].name = "cxgbi_device_register",
83617 + [29714].param1 = 1,
83618 + [29714].param2 = 1,
83619 + [2972].file = "drivers/staging/crystalhd/crystalhd_misc.c",
83620 + [2972].name = "crystalhd_create_dio_pool",
83621 + [2972].param2 = 1,
83622 + [29769].file = "drivers/misc/iwmc3200top/log.c",
83623 + [29769].name = "store_iwmct_log_level",
83624 + [29769].param4 = 1,
83625 + [29792].file = "drivers/staging/bcm/nvm.c",
83626 + [29792].name = "BcmCopySection",
83627 + [29792].param5 = 1,
83628 + [29859].file = "net/rds/page.c",
83629 + [29859].name = "rds_page_copy_user",
83630 + [29859].param4 = 1,
83631 + [29905].file = "mm/nobootmem.c",
83632 + [29905].name = "___alloc_bootmem",
83633 + [29905].param1 = 1,
83634 + [2995].file = "mm/page_alloc.c",
83635 + [2995].name = "alloc_large_system_hash",
83636 + [2995].param2 = 1,
83637 + [30000].file = "drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c",
83638 + [30000].name = "wlc_phy_loadsampletable_nphy",
83639 + [30000].param3 = 1,
83640 + [30242].file = "fs/cifs/cifssmb.c",
83641 + [30242].name = "cifs_readdata_alloc",
83642 + [30242].param1 = 1,
83643 + [30494].file = "net/ceph/buffer.c",
83644 + [30494].name = "ceph_buffer_new",
83645 + [30494].param1 = 1,
83646 + [30590].file = "security/tomoyo/memory.c",
83647 + [30590].name = "tomoyo_commit_ok",
83648 + [30590].param2 = 1,
83649 + [3060].file = "lib/mpi/mpiutil.c",
83650 + [3060].name = "mpi_alloc_limb_space",
83651 + [3060].param1 = 1,
83652 + [30687].file = "drivers/uwb/uwb-debug.c",
83653 + [30687].name = "command_write",
83654 + [30687].param3 = 1,
83655 + [30726].file = "drivers/bluetooth/hci_vhci.c",
83656 + [30726].name = "vhci_get_user",
83657 + [30726].param3 = 1,
83658 + [30873].file = "net/packet/af_packet.c",
83659 + [30873].name = "alloc_one_pg_vec_page",
83660 + [30873].param1 = 1,
83661 + [30970].file = "drivers/staging/hv/storvsc_drv.c",
83662 + [30970].name = "create_bounce_buffer",
83663 + [30970].param3 = 1,
83664 + [310].file = "drivers/block/drbd/drbd_bitmap.c",
83665 + [310].name = "bm_realloc_pages",
83666 + [310].param2 = 1,
83667 + [3119].file = "drivers/misc/ibmasm/command.c",
83668 + [3119].name = "ibmasm_new_command",
83669 + [3119].param2 = 1,
83670 + [31207].file = "drivers/platform/x86/asus_acpi.c",
83671 + [31207].name = "parse_arg",
83672 + [31207].param2 = 1,
83673 + [31287].file = "drivers/scsi/libsrp.c",
83674 + [31287].name = "srp_iu_pool_alloc",
83675 + [31287].param2 = 1,
83676 + [31291].file = "sound/pci/rme9652/rme9652.c",
83677 + [31291].name = "snd_rme9652_capture_copy",
83678 + [31291].param5 = 1,
83679 + [31348].file = "kernel/sched/core.c",
83680 + [31348].name = "sys_sched_getaffinity",
83681 + [31348].param2 = 1,
83682 + [31492].file = "drivers/hid/hidraw.c",
83683 + [31492].name = "hidraw_read",
83684 + [31492].param3 = 1,
83685 + [3170].file = "security/integrity/ima/ima_fs.c",
83686 + [3170].name = "ima_write_policy",
83687 + [3170].param3 = 1,
83688 + [31782].file = "drivers/misc/pti.c",
83689 + [31782].name = "pti_char_write",
83690 + [31782].param3 = 1,
83691 + [31789].file = "fs/file.c",
83692 + [31789].name = "alloc_fdmem",
83693 + [31789].param1 = 1,
83694 + [31957].file = "fs/afs/proc.c",
83695 + [31957].name = "afs_proc_cells_write",
83696 + [31957].param3 = 1,
83697 + [32002].file = "net/sctp/socket.c",
83698 + [32002].name = "sctp_setsockopt_active_key",
83699 + [32002].param3 = 1,
83700 + [32182].file = "net/sunrpc/cache.c",
83701 + [32182].name = "cache_write",
83702 + [32182].param3 = 1,
83703 + [32278].file = "kernel/time/timer_stats.c",
83704 + [32278].name = "tstats_write",
83705 + [32278].param3 = 1,
83706 + [32326].file = "drivers/tty/n_r3964.c",
83707 + [32326].name = "r3964_write",
83708 + [32326].param4 = 1,
83709 + [32399].file = "drivers/net/phy/mdio_bus.c",
83710 + [32399].name = "mdiobus_alloc_size",
83711 + [32399].param1 = 1,
83712 + [32402].file = "net/ceph/pagevec.c",
83713 + [32402].name = "ceph_copy_user_to_page_vector",
83714 + [32402].param4 = 1,
83715 + [3241].file = "drivers/usb/wusbcore/crypto.c",
83716 + [3241].name = "wusb_prf",
83717 + [3241].param7 = 1,
83718 + [32459].file = "drivers/media/radio/radio-wl1273.c",
83719 + [32459].name = "wl1273_fm_fops_write",
83720 + [32459].param3 = 1,
83721 + [32531].file = "fs/bio.c",
83722 + [32531].name = "__bio_map_kern",
83723 + [32531].param2 = 1,
83724 + [32531].param3 = 1,
83725 + [32537].file = "drivers/staging/vme/devices/vme_user.c",
83726 + [32537].name = "buffer_to_user",
83727 + [32537].param3 = 1,
83728 + [32560].file = "drivers/input/input-mt.c",
83729 + [32560].name = "input_mt_init_slots",
83730 + [32560].param2 = 1,
83731 + [32600].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83732 + [32600].name = "ath6kl_set_assoc_req_ies",
83733 + [32600].param3 = 1,
83734 + [32608].file = "security/selinux/selinuxfs.c",
83735 + [32608].name = "sel_write_checkreqprot",
83736 + [32608].param3 = 1,
83737 + [32812].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
83738 + [32812].name = "__vxge_hw_channel_allocate",
83739 + [32812].param3 = 1,
83740 + [32950].file = "fs/reiserfs/resize.c",
83741 + [32950].name = "reiserfs_resize",
83742 + [32950].param2 = 1,
83743 + [33010].file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
83744 + [33010].name = "dvb_ringbuffer_pkt_read_user",
83745 + [33010].param5 = 1,
83746 + [33130].file = "net/llc/llc_sap.c",
83747 + [33130].name = "llc_alloc_frame",
83748 + [33130].param4 = 1,
83749 + [33221].file = "crypto/ablkcipher.c",
83750 + [33221].name = "ablkcipher_copy_iv",
83751 + [33221].param3 = 1,
83752 + [33268].file = "mm/maccess.c",
83753 + [33268].name = "__probe_kernel_write",
83754 + [33268].param3 = 1,
83755 + [33280].file = "fs/xfs/kmem.c",
83756 + [33280].name = "kmem_realloc",
83757 + [33280].param2 = 1,
83758 + [33375].file = "drivers/staging/rtl8712/osdep_service.h",
83759 + [33375].name = "_malloc",
83760 + [33375].param1 = 1,
83761 + [33420].file = "drivers/net/team/team.c",
83762 + [33420].name = "__team_options_register",
83763 + [33420].param3 = 1,
83764 + [33489].file = "fs/binfmt_misc.c",
83765 + [33489].name = "create_entry",
83766 + [33489].param2 = 1,
83767 + [33637].file = "net/9p/client.c",
83768 + [33637].name = "p9_client_read",
83769 + [33637].param5 = 1,
83770 + [33669].file = "fs/gfs2/glock.c",
83771 + [33669].name = "gfs2_glock_nq_m",
83772 + [33669].param1 = 1,
83773 + [33704].file = "drivers/gpu/drm/ttm/ttm_page_alloc_dma.c",
83774 + [33704].name = "ttm_dma_page_pool_free",
83775 + [33704].param2 = 1,
83776 + [33779].file = "drivers/staging/vme/devices/vme_user.c",
83777 + [33779].name = "resource_from_user",
83778 + [33779].param3 = 1,
83779 + [33810].file = "net/mac80211/util.c",
83780 + [33810].name = "ieee80211_send_probe_req",
83781 + [33810].param6 = 1,
83782 + [3384].file = "drivers/block/paride/pg.c",
83783 + [3384].name = "pg_write",
83784 + [3384].param3 = 1,
83785 + [34105].file = "fs/libfs.c",
83786 + [34105].name = "simple_read_from_buffer",
83787 + [34105].param2 = 1,
83788 + [34105].param5 = 1,
83789 + [34120].file = "drivers/media/video/pvrusb2/pvrusb2-io.c",
83790 + [34120].name = "pvr2_stream_buffer_count",
83791 + [34120].param2 = 1,
83792 + [34226].file = "mm/shmem.c",
83793 + [34226].name = "shmem_xattr_set",
83794 + [34226].param4 = 1,
83795 + [34251].file = "drivers/staging/cxt1e1/sbecom_inline_linux.h",
83796 + [34251].name = "OS_kmalloc",
83797 + [34251].param1 = 1,
83798 + [34276].file = "drivers/media/video/videobuf2-core.c",
83799 + [34276].name = "__vb2_perform_fileio",
83800 + [34276].param3 = 1,
83801 + [34278].file = "fs/ubifs/debug.c",
83802 + [34278].name = "dfs_global_file_write",
83803 + [34278].param3 = 1,
83804 + [34432].file = "drivers/edac/edac_pci.c",
83805 + [34432].name = "edac_pci_alloc_ctl_info",
83806 + [34432].param1 = 1,
83807 + [34532].file = "drivers/virtio/virtio_ring.c",
83808 + [34532].name = "vring_add_indirect",
83809 + [34532].param3 = 1,
83810 + [34532].param4 = 1,
83811 + [34543].file = "net/sctp/tsnmap.c",
83812 + [34543].name = "sctp_tsnmap_grow",
83813 + [34543].param2 = 1,
83814 + [34551].file = "fs/ocfs2/stack_user.c",
83815 + [34551].name = "ocfs2_control_cfu",
83816 + [34551].param2 = 1,
83817 + [34634].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83818 + [34634].name = "ath6kl_send_go_probe_resp",
83819 + [34634].param3 = 1,
83820 + [34666].file = "fs/cifs/cifs_debug.c",
83821 + [34666].name = "cifs_security_flags_proc_write",
83822 + [34666].param3 = 1,
83823 + [3466].file = "drivers/misc/altera-stapl/altera-jtag.c",
83824 + [3466].name = "altera_drscan",
83825 + [3466].param2 = 1,
83826 + [34672].file = "drivers/tty/tty_io.c",
83827 + [34672].name = "tty_write",
83828 + [34672].param3 = 1,
83829 + [34679].file = "drivers/media/video/ivtv/ivtv-fileops.c",
83830 + [34679].name = "ivtv_copy_buf_to_user",
83831 + [34679].param4 = 1,
83832 + [34721].file = "drivers/usb/host/hwa-hc.c",
83833 + [34721].name = "__hwahc_dev_set_key",
83834 + [34721].param5 = 1,
83835 + [34749].file = "mm/nobootmem.c",
83836 + [34749].name = "__alloc_bootmem_low_node",
83837 + [34749].param2 = 1,
83838 + [34760].file = "include/acpi/platform/aclinux.h",
83839 + [34760].name = "acpi_os_allocate_zeroed",
83840 + [34760].param1 = 1,
83841 + [34802].file = "drivers/scsi/cxgbi/libcxgbi.h",
83842 + [34802].name = "cxgbi_alloc_big_mem",
83843 + [34802].param1 = 1,
83844 + [34863].file = "drivers/video/fbsysfs.c",
83845 + [34863].name = "framebuffer_alloc",
83846 + [34863].param1 = 1,
83847 + [34868].file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
83848 + [34868].name = "bnad_debugfs_write_regrd",
83849 + [34868].param3 = 1,
83850 + [34882].file = "drivers/platform/x86/toshiba_acpi.c",
83851 + [34882].name = "video_proc_write",
83852 + [34882].param3 = 1,
83853 + [35050].file = "fs/ocfs2/dlmfs/dlmfs.c",
83854 + [35050].name = "dlmfs_file_write",
83855 + [35050].param3 = 1,
83856 + [35119].file = "fs/xattr.c",
83857 + [35119].name = "sys_llistxattr",
83858 + [35119].param3 = 1,
83859 + [35129].file = "mm/nobootmem.c",
83860 + [35129].name = "___alloc_bootmem_nopanic",
83861 + [35129].param1 = 1,
83862 + [35159].file = "drivers/net/wimax/i2400m/usb.c",
83863 + [35159].name = "__i2400mu_send_barker",
83864 + [35159].param3 = 1,
83865 + [35232].file = "drivers/media/video/cx18/cx18-fileops.c",
83866 + [35232].name = "cx18_read",
83867 + [35232].param3 = 1,
83868 + [35234].file = "net/irda/irnet/irnet_ppp.c",
83869 + [35234].name = "irnet_ctrl_write",
83870 + [35234].param3 = 1,
83871 + [35256].file = "sound/core/memory.c",
83872 + [35256].name = "copy_from_user_toio",
83873 + [35256].param3 = 1,
83874 + [35268].file = "security/keys/request_key_auth.c",
83875 + [35268].name = "request_key_auth_read",
83876 + [35268].param3 = 1,
83877 + [3538].file = "net/bluetooth/mgmt.c",
83878 + [3538].name = "disconnect",
83879 + [3538].param4 = 1,
83880 + [35443].file = "sound/core/pcm_memory.c",
83881 + [35443].name = "_snd_pcm_lib_alloc_vmalloc_buffer",
83882 + [35443].param2 = 1,
83883 + [35468].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
83884 + [35468].name = "xenbus_file_write",
83885 + [35468].param3 = 1,
83886 + [35536].file = "kernel/sysctl_binary.c",
83887 + [35536].name = "bin_uuid",
83888 + [35536].param3 = 1,
83889 + [35551].file = "drivers/media/video/ivtv/ivtv-fileops.c",
83890 + [35551].name = "ivtv_read_pos",
83891 + [35551].param3 = 1,
83892 + [35556].file = "fs/read_write.c",
83893 + [35556].name = "sys_readv",
83894 + [35556].param3 = 1,
83895 + [35693].file = "drivers/staging/mei/main.c",
83896 + [35693].name = "mei_read",
83897 + [35693].param3 = 1,
83898 + [35703].file = "crypto/ablkcipher.c",
83899 + [35703].name = "ablkcipher_next_slow",
83900 + [35703].param3 = 1,
83901 + [35703].param4 = 1,
83902 + [35729].file = "include/linux/skbuff.h",
83903 + [35729].name = "__dev_alloc_skb",
83904 + [35729].param1 = 1,
83905 + [35731].file = "drivers/usb/class/cdc-wdm.c",
83906 + [35731].name = "wdm_read",
83907 + [35731].param3 = 1,
83908 + [35796].file = "drivers/mtd/nand/nand_bch.c",
83909 + [35796].name = "nand_bch_init",
83910 + [35796].param2 = 1,
83911 + [35796].param3 = 1,
83912 + [35880].file = "fs/ecryptfs/crypto.c",
83913 + [35880].name = "ecryptfs_encrypt_and_encode_filename",
83914 + [35880].param6 = 1,
83915 + [36076].file = "drivers/net/ethernet/sfc/tx.c",
83916 + [36076].name = "efx_tsoh_heap_alloc",
83917 + [36076].param2 = 1,
83918 + [36080].file = "drivers/media/video/v4l2-ioctl.c",
83919 + [36080].name = "video_usercopy",
83920 + [36080].param2 = 1,
83921 + [36149].file = "fs/udf/inode.c",
83922 + [36149].name = "udf_alloc_i_data",
83923 + [36149].param2 = 1,
83924 + [36183].file = "drivers/tty/vt/vc_screen.c",
83925 + [36183].name = "vcs_read",
83926 + [36183].param3 = 1,
83927 + [36199].file = "net/sunrpc/auth_gss/auth_gss.c",
83928 + [36199].name = "gss_pipe_downcall",
83929 + [36199].param3 = 1,
83930 + [36206].file = "net/ipv4/tcp_input.c",
83931 + [36206].name = "tcp_collapse",
83932 + [36206].param5 = 1,
83933 + [36206].param6 = 1,
83934 + [36230].file = "drivers/net/wan/hdlc_ppp.c",
83935 + [36230].name = "ppp_cp_parse_cr",
83936 + [36230].param4 = 1,
83937 + [36284].file = "drivers/spi/spi.c",
83938 + [36284].name = "spi_register_board_info",
83939 + [36284].param2 = 1,
83940 + [36490].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
83941 + [36490].name = "ath6kl_cfg80211_connect_event",
83942 + [36490].param7 = 1,
83943 + [36522].file = "drivers/hid/hidraw.c",
83944 + [36522].name = "hidraw_send_report",
83945 + [36522].param3 = 1,
83946 + [36560].file = "net/sunrpc/cache.c",
83947 + [36560].name = "write_flush",
83948 + [36560].param3 = 1,
83949 + [36807].file = "drivers/usb/mon/mon_bin.c",
83950 + [36807].name = "mon_bin_get_event",
83951 + [36807].param4 = 1,
83952 + [37034].file = "fs/cifs/cifssmb.c",
83953 + [37034].name = "cifs_writedata_alloc",
83954 + [37034].param1 = 1,
83955 + [37044].file = "sound/firewire/packets-buffer.c",
83956 + [37044].name = "iso_packets_buffer_init",
83957 + [37044].param3 = 1,
83958 + [37108].file = "drivers/media/dvb/ttpci/av7110_av.c",
83959 + [37108].name = "dvb_video_write",
83960 + [37108].param3 = 1,
83961 + [37154].file = "net/nfc/llcp/commands.c",
83962 + [37154].name = "nfc_llcp_build_tlv",
83963 + [37154].param3 = 1,
83964 + [37163].file = "net/core/skbuff.c",
83965 + [37163].name = "__netdev_alloc_skb",
83966 + [37163].param2 = 1,
83967 + [37233].file = "fs/ocfs2/cluster/tcp.c",
83968 + [37233].name = "o2net_send_message_vec",
83969 + [37233].param4 = 1,
83970 + [37241].file = "net/atm/lec.c",
83971 + [37241].name = "lane2_associate_req",
83972 + [37241].param4 = 1,
83973 + [37384].file = "drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c",
83974 + [37384].name = "vmw_fifo_reserve",
83975 + [37384].param2 = 1,
83976 + [37497].file = "net/mac80211/util.c",
83977 + [37497].name = "ieee80211_build_probe_req",
83978 + [37497].param7 = 1,
83979 + [37535].file = "kernel/trace/trace.c",
83980 + [37535].name = "tracing_trace_options_write",
83981 + [37535].param3 = 1,
83982 + [37611].file = "drivers/xen/xenbus/xenbus_xs.c",
83983 + [37611].name = "split",
83984 + [37611].param2 = 1,
83985 + [37661].file = "mm/filemap.c",
83986 + [37661].name = "file_read_actor",
83987 + [37661].param4 = 1,
83988 + [37852].file = "drivers/staging/android/logger.c",
83989 + [37852].name = "do_read_log_to_user",
83990 + [37852].param4 = 1,
83991 + [37921].file = "drivers/net/wireless/wl12xx/rx.c",
83992 + [37921].name = "wl1271_rx_handle_data",
83993 + [37921].param3 = 1,
83994 + [37976].file = "drivers/platform/x86/asus_acpi.c",
83995 + [37976].name = "bluetooth_proc_write",
83996 + [37976].param3 = 1,
83997 + [3797].file = "sound/pci/asihpi/hpicmn.c",
83998 + [3797].name = "hpi_alloc_control_cache",
83999 + [3797].param1 = 1,
84000 + [3801].file = "drivers/block/paride/pt.c",
84001 + [3801].name = "pt_write",
84002 + [3801].param3 = 1,
84003 + [38052].file = "kernel/kexec.c",
84004 + [38052].name = "kimage_normal_alloc",
84005 + [38052].param3 = 1,
84006 + [38057].file = "fs/coda/psdev.c",
84007 + [38057].name = "coda_psdev_write",
84008 + [38057].param3 = 1,
84009 + [38186].file = "kernel/signal.c",
84010 + [38186].name = "do_sigpending",
84011 + [38186].param2 = 1,
84012 + [38314].file = "fs/nfs/read.c",
84013 + [38314].name = "nfs_readdata_alloc",
84014 + [38314].param1 = 1,
84015 + [38401].file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
84016 + [38401].name = "queue_reply",
84017 + [38401].param3 = 1,
84018 + [3841].file = "drivers/platform/x86/asus_acpi.c",
84019 + [3841].name = "write_led",
84020 + [3841].param2 = 1,
84021 + [38532].file = "fs/afs/cell.c",
84022 + [38532].name = "afs_cell_lookup",
84023 + [38532].param2 = 1,
84024 + [38564].file = "fs/nfs/nfs4proc.c",
84025 + [38564].name = "nfs4_realloc_slot_table",
84026 + [38564].param2 = 1,
84027 + [38576].file = "drivers/i2c/i2c-dev.c",
84028 + [38576].name = "i2cdev_read",
84029 + [38576].param3 = 1,
84030 + [38704].file = "drivers/media/video/uvc/uvc_driver.c",
84031 + [38704].name = "uvc_alloc_entity",
84032 + [38704].param3 = 1,
84033 + [38704].param4 = 1,
84034 + [38747].file = "fs/xattr.c",
84035 + [38747].name = "sys_lgetxattr",
84036 + [38747].param4 = 1,
84037 + [38867].file = "drivers/scsi/scsi_transport_fc.c",
84038 + [38867].name = "fc_host_post_vendor_event",
84039 + [38867].param3 = 1,
84040 + [38931].file = "drivers/isdn/hardware/eicon/capimain.c",
84041 + [38931].name = "diva_os_alloc_message_buffer",
84042 + [38931].param1 = 1,
84043 + [38972].file = "security/smack/smackfs.c",
84044 + [38972].name = "smk_write_logging",
84045 + [38972].param3 = 1,
84046 + [39001].file = "net/xfrm/xfrm_hash.c",
84047 + [39001].name = "xfrm_hash_alloc",
84048 + [39001].param1 = 1,
84049 + [39052].file = "drivers/input/evdev.c",
84050 + [39052].name = "evdev_ioctl",
84051 + [39052].param2 = 1,
84052 + [39066].file = "drivers/media/dvb/frontends/tda10048.c",
84053 + [39066].name = "tda10048_writeregbulk",
84054 + [39066].param4 = 1,
84055 + [39118].file = "drivers/misc/iwmc3200top/log.c",
84056 + [39118].name = "store_iwmct_log_level_fw",
84057 + [39118].param4 = 1,
84058 + [39254].file = "drivers/char/pcmcia/cm4000_cs.c",
84059 + [39254].name = "cmm_write",
84060 + [39254].param3 = 1,
84061 + [39392].file = "drivers/atm/solos-pci.c",
84062 + [39392].name = "send_command",
84063 + [39392].param4 = 1,
84064 + [39415].file = "fs/pstore/inode.c",
84065 + [39415].name = "pstore_mkfile",
84066 + [39415].param5 = 1,
84067 + [39417].file = "drivers/block/DAC960.c",
84068 + [39417].name = "dac960_user_command_proc_write",
84069 + [39417].param3 = 1,
84070 + [39460].file = "fs/btrfs/volumes.c",
84071 + [39460].name = "btrfs_map_block",
84072 + [39460].param3 = 1,
84073 + [39479].file = "drivers/ide/ide-tape.c",
84074 + [39479].name = "idetape_chrdev_read",
84075 + [39479].param3 = 1,
84076 + [39586].file = "drivers/hv/channel.c",
84077 + [39586].name = "create_gpadl_header",
84078 + [39586].param2 = 1,
84079 + [39638].file = "security/selinux/selinuxfs.c",
84080 + [39638].name = "sel_write_avc_cache_threshold",
84081 + [39638].param3 = 1,
84082 + [39645].file = "drivers/media/dvb/dvb-core/dvbdev.c",
84083 + [39645].name = "dvb_generic_ioctl",
84084 + [39645].param2 = 1,
84085 + [39770].file = "include/linux/mISDNif.h",
84086 + [39770].name = "mI_alloc_skb",
84087 + [39770].param1 = 1,
84088 + [39813].file = "fs/ocfs2/stack_user.c",
84089 + [39813].name = "ocfs2_control_message",
84090 + [39813].param3 = 1,
84091 + [39888].file = "net/core/skbuff.c",
84092 + [39888].name = "__alloc_skb",
84093 + [39888].param1 = 1,
84094 + [39980].file = "net/bluetooth/mgmt.c",
84095 + [39980].name = "pair_device",
84096 + [39980].param4 = 1,
84097 + [40043].file = "drivers/media/video/v4l2-ioctl.c",
84098 + [40043].name = "video_ioctl2",
84099 + [40043].param2 = 1,
84100 + [40049].file = "drivers/bluetooth/btmrvl_debugfs.c",
84101 + [40049].name = "btmrvl_psmode_write",
84102 + [40049].param3 = 1,
84103 + [40075].file = "drivers/media/video/c-qcam.c",
84104 + [40075].name = "qc_capture",
84105 + [40075].param3 = 1,
84106 + [40163].file = "fs/ncpfs/file.c",
84107 + [40163].name = "ncp_file_write",
84108 + [40163].param3 = 1,
84109 + [40240].file = "drivers/char/nvram.c",
84110 + [40240].name = "nvram_write",
84111 + [40240].param3 = 1,
84112 + [40256].file = "drivers/tty/vt/vc_screen.c",
84113 + [40256].name = "vcs_write",
84114 + [40256].param3 = 1,
84115 + [40302].file = "sound/isa/gus/gus_dram.c",
84116 + [40302].name = "snd_gus_dram_poke",
84117 + [40302].param4 = 1,
84118 + [40339].file = "drivers/acpi/apei/hest.c",
84119 + [40339].name = "hest_ghes_dev_register",
84120 + [40339].param1 = 1,
84121 + [40355].file = "drivers/staging/mei/main.c",
84122 + [40355].name = "mei_write",
84123 + [40355].param3 = 1,
84124 + [40373].file = "fs/cifs/cifs_spnego.c",
84125 + [40373].name = "cifs_spnego_key_instantiate",
84126 + [40373].param3 = 1,
84127 + [40519].file = "net/sctp/socket.c",
84128 + [40519].name = "sctp_setsockopt_events",
84129 + [40519].param3 = 1,
84130 + [40694].file = "mm/page_cgroup.c",
84131 + [40694].name = "alloc_page_cgroup",
84132 + [40694].param1 = 1,
84133 + [40731].file = "drivers/tty/tty_io.c",
84134 + [40731].name = "do_tty_write",
84135 + [40731].param5 = 1,
84136 + [40754].file = "fs/btrfs/delayed-inode.c",
84137 + [40754].name = "btrfs_alloc_delayed_item",
84138 + [40754].param1 = 1,
84139 + [40786].file = "net/ipv4/netfilter/nf_nat_snmp_basic.c",
84140 + [40786].name = "asn1_octets_decode",
84141 + [40786].param2 = 1,
84142 + [40901].file = "drivers/block/drbd/drbd_bitmap.c",
84143 + [40901].name = "drbd_bm_resize",
84144 + [40901].param2 = 1,
84145 + [40951].file = "drivers/xen/evtchn.c",
84146 + [40951].name = "evtchn_read",
84147 + [40951].param3 = 1,
84148 + [40952].file = "drivers/misc/sgi-xp/xpc_partition.c",
84149 + [40952].name = "xpc_kmalloc_cacheline_aligned",
84150 + [40952].param1 = 1,
84151 + [41000].file = "sound/core/pcm_native.c",
84152 + [41000].name = "snd_pcm_aio_read",
84153 + [41000].param3 = 1,
84154 + [41005].file = "net/bridge/netfilter/ebtables.c",
84155 + [41005].name = "copy_counters_to_user",
84156 + [41005].param5 = 1,
84157 + [41041].file = "net/core/sock.c",
84158 + [41041].name = "sock_wmalloc",
84159 + [41041].param2 = 1,
84160 + [41122].file = "fs/binfmt_misc.c",
84161 + [41122].name = "bm_status_write",
84162 + [41122].param3 = 1,
84163 + [41176].file = "kernel/trace/trace_events.c",
84164 + [41176].name = "subsystem_filter_write",
84165 + [41176].param3 = 1,
84166 + [41249].file = "drivers/media/video/zr364xx.c",
84167 + [41249].name = "send_control_msg",
84168 + [41249].param6 = 1,
84169 + [41287].file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
84170 + [41287].name = "vxge_os_dma_malloc_async",
84171 + [41287].param3 = 1,
84172 + [41302].file = "net/dns_resolver/dns_query.c",
84173 + [41302].name = "dns_query",
84174 + [41302].param3 = 1,
84175 + [41408].file = "mm/filemap_xip.c",
84176 + [41408].name = "__xip_file_write",
84177 + [41408].param3 = 1,
84178 + [41547].file = "net/bluetooth/smp.c",
84179 + [41547].name = "smp_build_cmd",
84180 + [41547].param3 = 1,
84181 + [4155].file = "kernel/kexec.c",
84182 + [4155].name = "do_kimage_alloc",
84183 + [4155].param3 = 1,
84184 + [41676].file = "fs/compat.c",
84185 + [41676].name = "compat_sys_preadv",
84186 + [41676].param3 = 1,
84187 + [4167].file = "drivers/media/dvb/frontends/cx24116.c",
84188 + [4167].name = "cx24116_writeregN",
84189 + [4167].param4 = 1,
84190 + [41793].file = "drivers/net/wireless/ath/ath6kl/wmi.c",
84191 + [41793].name = "ath6kl_wmi_send_mgmt_cmd",
84192 + [41793].param7 = 1,
84193 + [41924].file = "security/keys/keyctl.c",
84194 + [41924].name = "keyctl_get_security",
84195 + [41924].param3 = 1,
84196 + [41968].file = "fs/btrfs/volumes.c",
84197 + [41968].name = "__btrfs_map_block",
84198 + [41968].param3 = 1,
84199 + [4202].file = "drivers/edac/edac_mc.c",
84200 + [4202].name = "edac_mc_alloc",
84201 + [4202].param1 = 1,
84202 + [42081].file = "net/econet/af_econet.c",
84203 + [42081].name = "aun_incoming",
84204 + [42081].param3 = 1,
84205 + [42143].file = "drivers/media/video/c-qcam.c",
84206 + [42143].name = "qcam_read",
84207 + [42143].param3 = 1,
84208 + [42206].file = "fs/quota/quota_tree.c",
84209 + [42206].name = "getdqbuf",
84210 + [42206].param1 = 1,
84211 + [42270].file = "net/wireless/scan.c",
84212 + [42270].name = "cfg80211_inform_bss_frame",
84213 + [42270].param4 = 1,
84214 + [42281].file = "include/linux/mISDNif.h",
84215 + [42281].name = "_queue_data",
84216 + [42281].param4 = 1,
84217 + [42420].file = "drivers/net/wireless/hostap/hostap_ioctl.c",
84218 + [42420].name = "prism2_set_genericelement",
84219 + [42420].param3 = 1,
84220 + [42472].file = "fs/compat.c",
84221 + [42472].name = "compat_readv",
84222 + [42472].param3 = 1,
84223 + [42473].file = "net/tipc/name_table.c",
84224 + [42473].name = "tipc_subseq_alloc",
84225 + [42473].param1 = 1,
84226 + [42562].file = "kernel/kfifo.c",
84227 + [42562].name = "__kfifo_to_user_r",
84228 + [42562].param3 = 1,
84229 + [42666].file = "drivers/pcmcia/cistpl.c",
84230 + [42666].name = "read_cis_cache",
84231 + [42666].param4 = 1,
84232 + [42714].file = "drivers/scsi/scsi_tgt_lib.c",
84233 + [42714].name = "scsi_tgt_copy_sense",
84234 + [42714].param3 = 1,
84235 + [42833].file = "kernel/trace/blktrace.c",
84236 + [42833].name = "blk_msg_write",
84237 + [42833].param3 = 1,
84238 + [42857].file = "security/selinux/selinuxfs.c",
84239 + [42857].name = "sel_write_member",
84240 + [42857].param3 = 1,
84241 + [42882].file = "security/keys/user_defined.c",
84242 + [42882].name = "user_instantiate",
84243 + [42882].param3 = 1,
84244 + [42930].file = "net/caif/cfpkt_skbuff.c",
84245 + [42930].name = "cfpkt_create_pfx",
84246 + [42930].param1 = 1,
84247 + [42930].param2 = 1,
84248 + [43023].file = "drivers/usb/misc/usblcd.c",
84249 + [43023].name = "lcd_write",
84250 + [43023].param3 = 1,
84251 + [43104].file = "drivers/mtd/devices/mtd_dataflash.c",
84252 + [43104].name = "dataflash_read_user_otp",
84253 + [43104].param3 = 1,
84254 + [43133].file = "lib/mpi/mpiutil.c",
84255 + [43133].name = "mpi_resize",
84256 + [43133].param2 = 1,
84257 + [4324].file = "drivers/video/fbmem.c",
84258 + [4324].name = "fb_read",
84259 + [4324].param3 = 1,
84260 + [43266].file = "fs/afs/cell.c",
84261 + [43266].name = "afs_cell_alloc",
84262 + [43266].param2 = 1,
84263 + [4328].file = "drivers/usb/musb/musb_debugfs.c",
84264 + [4328].name = "musb_test_mode_write",
84265 + [4328].param3 = 1,
84266 + [43380].file = "drivers/scsi/bfa/bfad_debugfs.c",
84267 + [43380].name = "bfad_debugfs_write_regrd",
84268 + [43380].param3 = 1,
84269 + [43510].file = "kernel/kexec.c",
84270 + [43510].name = "compat_sys_kexec_load",
84271 + [43510].param2 = 1,
84272 + [43540].file = "include/rdma/ib_verbs.h",
84273 + [43540].name = "ib_copy_to_udata",
84274 + [43540].param3 = 1,
84275 + [4357].file = "security/tomoyo/securityfs_if.c",
84276 + [4357].name = "tomoyo_read_self",
84277 + [4357].param3 = 1,
84278 + [43590].file = "security/smack/smackfs.c",
84279 + [43590].name = "smk_write_onlycap",
84280 + [43590].param3 = 1,
84281 + [43596].file = "drivers/usb/core/buffer.c",
84282 + [43596].name = "hcd_buffer_alloc",
84283 + [43596].param2 = 1,
84284 + [43632].file = "drivers/media/video/videobuf2-core.c",
84285 + [43632].name = "vb2_read",
84286 + [43632].param3 = 1,
84287 + [43659].file = "drivers/firmware/efivars.c",
84288 + [43659].name = "efivar_create_sysfs_entry",
84289 + [43659].param2 = 1,
84290 + [43731].file = "drivers/hid/hid-picolcd.c",
84291 + [43731].name = "picolcd_debug_eeprom_read",
84292 + [43731].param3 = 1,
84293 + [43777].file = "drivers/acpi/acpica/utobject.c",
84294 + [43777].name = "acpi_ut_create_buffer_object",
84295 + [43777].param1 = 1,
84296 + [43798].file = "net/bluetooth/mgmt.c",
84297 + [43798].name = "set_local_name",
84298 + [43798].param4 = 1,
84299 + [4380].file = "drivers/mtd/devices/mtd_dataflash.c",
84300 + [4380].name = "dataflash_read_fact_otp",
84301 + [4380].param3 = 1,
84302 + [43834].file = "security/apparmor/apparmorfs.c",
84303 + [43834].name = "profile_replace",
84304 + [43834].param3 = 1,
84305 + [43895].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
84306 + [43895].name = "ddb_output_write",
84307 + [43895].param3 = 1,
84308 + [43899].file = "drivers/media/rc/imon.c",
84309 + [43899].name = "vfd_write",
84310 + [43899].param3 = 1,
84311 + [43900].file = "drivers/scsi/cxgbi/libcxgbi.c",
84312 + [43900].name = "cxgbi_device_portmap_create",
84313 + [43900].param3 = 1,
84314 + [43922].file = "drivers/mmc/card/mmc_test.c",
84315 + [43922].name = "mmc_test_alloc_mem",
84316 + [43922].param3 = 1,
84317 + [43946].file = "drivers/net/wireless/ath/ath6kl/txrx.c",
84318 + [43946].name = "aggr_recv_addba_req_evt",
84319 + [43946].param4 = 1,
84320 + [44006].file = "mm/process_vm_access.c",
84321 + [44006].name = "process_vm_rw_pages",
84322 + [44006].param5 = 1,
84323 + [44006].param6 = 1,
84324 + [44050].file = "fs/nfs/idmap.c",
84325 + [44050].name = "nfs_map_group_to_gid",
84326 + [44050].param3 = 1,
84327 + [44125].file = "fs/ext4/super.c",
84328 + [44125].name = "ext4_kvmalloc",
84329 + [44125].param1 = 1,
84330 + [44266].file = "kernel/cgroup.c",
84331 + [44266].name = "cgroup_write_string",
84332 + [44266].param5 = 1,
84333 + [44290].file = "drivers/net/usb/dm9601.c",
84334 + [44290].name = "dm_read",
84335 + [44290].param3 = 1,
84336 + [44308].file = "crypto/af_alg.c",
84337 + [44308].name = "alg_setkey",
84338 + [44308].param3 = 1,
84339 + [44510].file = "drivers/net/ethernet/broadcom/bnx2.c",
84340 + [44510].name = "bnx2_nvram_write",
84341 + [44510].param2 = 1,
84342 + [44625].file = "net/bluetooth/mgmt.c",
84343 + [44625].name = "set_connectable",
84344 + [44625].param4 = 1,
84345 + [44642].file = "drivers/net/wireless/iwmc3200wifi/commands.c",
84346 + [44642].name = "iwm_umac_set_config_var",
84347 + [44642].param4 = 1,
84348 + [44698].file = "net/sctp/socket.c",
84349 + [44698].name = "sctp_setsockopt_context",
84350 + [44698].param3 = 1,
84351 + [4471].file = "fs/ntfs/malloc.h",
84352 + [4471].name = "__ntfs_malloc",
84353 + [4471].param1 = 1,
84354 + [44773].file = "drivers/staging/vme/devices/vme_user.c",
84355 + [44773].name = "vme_user_write",
84356 + [44773].param3 = 1,
84357 + [44825].file = "drivers/scsi/osd/osd_initiator.c",
84358 + [44825].name = "_osd_realloc_seg",
84359 + [44825].param3 = 1,
84360 + [44852].file = "net/sctp/socket.c",
84361 + [44852].name = "sctp_setsockopt_rtoinfo",
84362 + [44852].param3 = 1,
84363 + [44936].file = "drivers/md/dm-raid.c",
84364 + [44936].name = "context_alloc",
84365 + [44936].param3 = 1,
84366 + [44943].file = "mm/util.c",
84367 + [44943].name = "kmemdup",
84368 + [44943].param2 = 1,
84369 + [44946].file = "net/sctp/socket.c",
84370 + [44946].name = "sctp_setsockopt_auth_chunk",
84371 + [44946].param3 = 1,
84372 + [44990].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
84373 + [44990].name = "pvr2_ioread_set_sync_key",
84374 + [44990].param3 = 1,
84375 + [45000].file = "fs/afs/proc.c",
84376 + [45000].name = "afs_proc_rootcell_write",
84377 + [45000].param3 = 1,
84378 + [45117].file = "drivers/staging/winbond/wb35reg.c",
84379 + [45117].name = "Wb35Reg_BurstWrite",
84380 + [45117].param4 = 1,
84381 + [45200].file = "drivers/scsi/scsi_proc.c",
84382 + [45200].name = "proc_scsi_write_proc",
84383 + [45200].param3 = 1,
84384 + [45217].file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
84385 + [45217].name = "iwl_dbgfs_debug_level_write",
84386 + [45217].param3 = 1,
84387 + [45233].file = "net/rds/info.c",
84388 + [45233].name = "rds_info_getsockopt",
84389 + [45233].param3 = 1,
84390 + [45326].file = "drivers/mtd/ubi/cdev.c",
84391 + [45326].name = "vol_cdev_read",
84392 + [45326].param3 = 1,
84393 + [45335].file = "fs/read_write.c",
84394 + [45335].name = "vfs_writev",
84395 + [45335].param3 = 1,
84396 + [45366].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
84397 + [45366].name = "init_tid_tabs",
84398 + [45366].param2 = 1,
84399 + [45366].param3 = 1,
84400 + [45366].param4 = 1,
84401 + [45534].file = "drivers/net/wireless/ath/carl9170/cmd.c",
84402 + [45534].name = "carl9170_cmd_buf",
84403 + [45534].param3 = 1,
84404 + [45576].file = "net/netfilter/xt_recent.c",
84405 + [45576].name = "recent_mt_proc_write",
84406 + [45576].param3 = 1,
84407 + [45583].file = "fs/gfs2/dir.c",
84408 + [45583].name = "leaf_dealloc",
84409 + [45583].param3 = 1,
84410 + [45586].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
84411 + [45586].name = "rt2x00debug_write_bbp",
84412 + [45586].param3 = 1,
84413 + [45629].file = "lib/bch.c",
84414 + [45629].name = "bch_alloc",
84415 + [45629].param1 = 1,
84416 + [45633].file = "drivers/input/evdev.c",
84417 + [45633].name = "evdev_do_ioctl",
84418 + [45633].param2 = 1,
84419 + [45743].file = "drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c",
84420 + [45743].name = "qlcnic_alloc_msix_entries",
84421 + [45743].param2 = 1,
84422 + [45864].file = "drivers/atm/ambassador.c",
84423 + [45864].name = "create_queues",
84424 + [45864].param2 = 1,
84425 + [45864].param3 = 1,
84426 + [45930].file = "security/apparmor/apparmorfs.c",
84427 + [45930].name = "profile_remove",
84428 + [45930].param3 = 1,
84429 + [45954].file = "drivers/usb/misc/legousbtower.c",
84430 + [45954].name = "tower_write",
84431 + [45954].param3 = 1,
84432 + [46140].file = "sound/core/memalloc.c",
84433 + [46140].name = "snd_mem_proc_write",
84434 + [46140].param3 = 1,
84435 + [4616].file = "net/sunrpc/cache.c",
84436 + [4616].name = "cache_do_downcall",
84437 + [4616].param3 = 1,
84438 + [46243].file = "fs/binfmt_misc.c",
84439 + [46243].name = "bm_register_write",
84440 + [46243].param3 = 1,
84441 + [46250].file = "fs/xattr.c",
84442 + [46250].name = "sys_getxattr",
84443 + [46250].param4 = 1,
84444 + [46343].file = "fs/compat.c",
84445 + [46343].name = "compat_do_readv_writev",
84446 + [46343].param4 = 1,
84447 + [46400].file = "drivers/staging/sep/sep_driver.c",
84448 + [46400].name = "sep_prepare_input_output_dma_table",
84449 + [46400].param2 = 1,
84450 + [46400].param3 = 1,
84451 + [46400].param4 = 1,
84452 + [4644].file = "drivers/net/usb/mcs7830.c",
84453 + [4644].name = "mcs7830_get_reg",
84454 + [4644].param3 = 1,
84455 + [46605].file = "sound/core/oss/pcm_oss.c",
84456 + [46605].name = "snd_pcm_oss_sync1",
84457 + [46605].param2 = 1,
84458 + [46630].file = "net/decnet/af_decnet.c",
84459 + [46630].name = "__dn_setsockopt",
84460 + [46630].param5 = 1,
84461 + [46655].file = "drivers/media/video/hdpvr/hdpvr-video.c",
84462 + [46655].name = "hdpvr_read",
84463 + [46655].param3 = 1,
84464 + [46685].file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
84465 + [46685].name = "ttm_bo_fbdev_io",
84466 + [46685].param4 = 1,
84467 + [46742].file = "drivers/scsi/st.c",
84468 + [46742].name = "sgl_map_user_pages",
84469 + [46742].param2 = 1,
84470 + [46881].file = "drivers/char/lp.c",
84471 + [46881].name = "lp_write",
84472 + [46881].param3 = 1,
84473 + [47130].file = "kernel/kfifo.c",
84474 + [47130].name = "kfifo_copy_to_user",
84475 + [47130].param3 = 1,
84476 + [47265].file = "drivers/scsi/bnx2fc/bnx2fc_io.c",
84477 + [47265].name = "bnx2fc_cmd_mgr_alloc",
84478 + [47265].param2 = 1,
84479 + [47265].param3 = 1,
84480 + [47309].file = "drivers/scsi/aic94xx/aic94xx_init.c",
84481 + [47309].name = "asd_store_update_bios",
84482 + [47309].param4 = 1,
84483 + [47342].file = "fs/proc/base.c",
84484 + [47342].name = "sched_autogroup_write",
84485 + [47342].param3 = 1,
84486 + [47363].file = "drivers/input/evdev.c",
84487 + [47363].name = "evdev_ioctl_handler",
84488 + [47363].param2 = 1,
84489 + [47385].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
84490 + [47385].name = "zd_usb_iowrite16v",
84491 + [47385].param3 = 1,
84492 + [4738].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
84493 + [4738].name = "ath6kl_set_ap_probe_resp_ies",
84494 + [4738].param3 = 1,
84495 + [47393].file = "drivers/net/wireless/ath/main.c",
84496 + [47393].name = "ath_rxbuf_alloc",
84497 + [47393].param2 = 1,
84498 + [47463].file = "fs/xfs/kmem.c",
84499 + [47463].name = "kmem_zalloc",
84500 + [47463].param1 = 1,
84501 + [47474].file = "kernel/trace/trace.c",
84502 + [47474].name = "tracing_buffers_read",
84503 + [47474].param3 = 1,
84504 + [47636].file = "drivers/usb/class/usblp.c",
84505 + [47636].name = "usblp_ioctl",
84506 + [47636].param2 = 1,
84507 + [47637].file = "drivers/block/cciss.c",
84508 + [47637].name = "cciss_proc_write",
84509 + [47637].param3 = 1,
84510 + [47712].file = "net/sctp/socket.c",
84511 + [47712].name = "sctp_setsockopt_maxburst",
84512 + [47712].param3 = 1,
84513 + [47728].file = "drivers/char/agp/isoch.c",
84514 + [47728].name = "agp_3_5_isochronous_node_enable",
84515 + [47728].param3 = 1,
84516 + [4779].file = "fs/pipe.c",
84517 + [4779].name = "pipe_set_size",
84518 + [4779].param2 = 1,
84519 + [47881].file = "security/selinux/selinuxfs.c",
84520 + [47881].name = "sel_write_disable",
84521 + [47881].param3 = 1,
84522 + [48111].file = "net/wireless/sme.c",
84523 + [48111].name = "cfg80211_roamed_bss",
84524 + [48111].param4 = 1,
84525 + [48111].param6 = 1,
84526 + [48124].file = "drivers/net/wireless/iwmc3200wifi/main.c",
84527 + [48124].name = "iwm_notif_send",
84528 + [48124].param6 = 1,
84529 + [48155].file = "net/sctp/sm_make_chunk.c",
84530 + [48155].name = "sctp_make_abort_user",
84531 + [48155].param3 = 1,
84532 + [48182].file = "crypto/cryptd.c",
84533 + [48182].name = "cryptd_alloc_instance",
84534 + [48182].param2 = 1,
84535 + [48182].param3 = 1,
84536 + [48248].file = "security/keys/keyctl.c",
84537 + [48248].name = "keyctl_instantiate_key",
84538 + [48248].param3 = 1,
84539 + [4829].file = "drivers/block/floppy.c",
84540 + [4829].name = "fd_copyout",
84541 + [4829].param3 = 1,
84542 + [48632].file = "net/bluetooth/l2cap_core.c",
84543 + [48632].name = "l2cap_build_cmd",
84544 + [48632].param4 = 1,
84545 + [48642].file = "fs/hugetlbfs/inode.c",
84546 + [48642].name = "hugetlbfs_read",
84547 + [48642].param3 = 1,
84548 + [48720].file = "drivers/gpu/drm/i915/i915_debugfs.c",
84549 + [48720].name = "i915_max_freq_write",
84550 + [48720].param3 = 1,
84551 + [48768].file = "net/irda/irnet/irnet_ppp.c",
84552 + [48768].name = "dev_irnet_write",
84553 + [48768].param3 = 1,
84554 + [48818].file = "net/sunrpc/svc.c",
84555 + [48818].name = "svc_pool_map_alloc_arrays",
84556 + [48818].param2 = 1,
84557 + [48856].file = "drivers/acpi/acpica/utalloc.c",
84558 + [48856].name = "acpi_ut_initialize_buffer",
84559 + [48856].param2 = 1,
84560 + [48862].file = "net/sctp/socket.c",
84561 + [48862].name = "sctp_setsockopt_adaptation_layer",
84562 + [48862].param3 = 1,
84563 + [49126].file = "lib/prio_heap.c",
84564 + [49126].name = "heap_init",
84565 + [49126].param2 = 1,
84566 + [49143].file = "sound/core/oss/pcm_oss.c",
84567 + [49143].name = "snd_pcm_oss_write2",
84568 + [49143].param3 = 1,
84569 + [49216].file = "fs/read_write.c",
84570 + [49216].name = "do_readv_writev",
84571 + [49216].param4 = 1,
84572 + [49426].file = "net/bluetooth/l2cap_sock.c",
84573 + [49426].name = "l2cap_sock_setsockopt_old",
84574 + [49426].param4 = 1,
84575 + [49448].file = "drivers/isdn/gigaset/common.c",
84576 + [49448].name = "gigaset_initdriver",
84577 + [49448].param2 = 1,
84578 + [49494].file = "drivers/virtio/virtio_ring.c",
84579 + [49494].name = "vring_new_virtqueue",
84580 + [49494].param1 = 1,
84581 + [49499].file = "drivers/block/nvme.c",
84582 + [49499].name = "nvme_alloc_iod",
84583 + [49499].param1 = 1,
84584 + [49510].file = "net/sctp/socket.c",
84585 + [49510].name = "sctp_setsockopt_autoclose",
84586 + [49510].param3 = 1,
84587 + [4958].file = "drivers/net/wireless/p54/fwio.c",
84588 + [4958].name = "p54_alloc_skb",
84589 + [4958].param3 = 1,
84590 + [49604].file = "crypto/af_alg.c",
84591 + [49604].name = "alg_setsockopt",
84592 + [49604].param5 = 1,
84593 + [49646].file = "drivers/tty/vt/vt.c",
84594 + [49646].name = "vc_resize",
84595 + [49646].param2 = 1,
84596 + [49646].param3 = 1,
84597 + [49658].file = "drivers/net/wireless/brcm80211/brcmsmac/dma.c",
84598 + [49658].name = "dma_attach",
84599 + [49658].param6 = 1,
84600 + [49658].param7 = 1,
84601 + [49663].file = "drivers/media/video/uvc/uvc_driver.c",
84602 + [49663].name = "uvc_simplify_fraction",
84603 + [49663].param3 = 1,
84604 + [49746].file = "net/ipv4/netfilter/arp_tables.c",
84605 + [49746].name = "compat_do_arpt_set_ctl",
84606 + [49746].param4 = 1,
84607 + [49780].file = "net/mac80211/key.c",
84608 + [49780].name = "ieee80211_key_alloc",
84609 + [49780].param3 = 1,
84610 + [49805].file = "drivers/pci/pci.c",
84611 + [49805].name = "pci_add_cap_save_buffer",
84612 + [49805].param3 = 1,
84613 + [49845].file = "mm/vmalloc.c",
84614 + [49845].name = "__vmalloc_node",
84615 + [49845].param1 = 1,
84616 + [49929].file = "drivers/mtd/ubi/cdev.c",
84617 + [49929].name = "vol_cdev_direct_write",
84618 + [49929].param3 = 1,
84619 + [49935].file = "fs/xfs/kmem.c",
84620 + [49935].name = "kmem_zalloc_greedy",
84621 + [49935].param2 = 1,
84622 + [49935].param3 = 1,
84623 + [49].file = "net/atm/svc.c",
84624 + [49].name = "svc_setsockopt",
84625 + [49].param5 = 1,
84626 + [50518].file = "drivers/gpu/drm/nouveau/nouveau_gem.c",
84627 + [50518].name = "u_memcpya",
84628 + [50518].param2 = 1,
84629 + [50518].param3 = 1,
84630 + [5052].file = "drivers/char/ppdev.c",
84631 + [5052].name = "pp_read",
84632 + [5052].param3 = 1,
84633 + [50562].file = "drivers/media/video/zoran/zoran_procfs.c",
84634 + [50562].name = "zoran_write",
84635 + [50562].param3 = 1,
84636 + [50617].file = "fs/hugetlbfs/inode.c",
84637 + [50617].name = "hugetlbfs_read_actor",
84638 + [50617].param2 = 1,
84639 + [50617].param4 = 1,
84640 + [50617].param5 = 1,
84641 + [50692].file = "lib/ts_bm.c",
84642 + [50692].name = "bm_init",
84643 + [50692].param2 = 1,
84644 + [50813].file = "mm/vmalloc.c",
84645 + [50813].name = "__vmalloc_node_flags",
84646 + [50813].param1 = 1,
84647 + [5087].file = "drivers/atm/solos-pci.c",
84648 + [5087].name = "console_store",
84649 + [5087].param4 = 1,
84650 + [5102].file = "drivers/usb/misc/usbtest.c",
84651 + [5102].name = "usbtest_alloc_urb",
84652 + [5102].param3 = 1,
84653 + [5102].param5 = 1,
84654 + [51061].file = "net/bluetooth/mgmt.c",
84655 + [51061].name = "pin_code_reply",
84656 + [51061].param4 = 1,
84657 + [51139].file = "fs/pipe.c",
84658 + [51139].name = "pipe_iov_copy_to_user",
84659 + [51139].param3 = 1,
84660 + [51177].file = "net/sunrpc/xprtrdma/transport.c",
84661 + [51177].name = "xprt_rdma_allocate",
84662 + [51177].param2 = 1,
84663 + [51182].file = "drivers/misc/sgi-xp/xpc_main.c",
84664 + [51182].name = "xpc_kzalloc_cacheline_aligned",
84665 + [51182].param1 = 1,
84666 + [51250].file = "fs/read_write.c",
84667 + [51250].name = "rw_copy_check_uvector",
84668 + [51250].param3 = 1,
84669 + [51253].file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
84670 + [51253].name = "rt2x00debug_write_eeprom",
84671 + [51253].param3 = 1,
84672 + [51323].file = "sound/pci/ac97/ac97_pcm.c",
84673 + [51323].name = "snd_ac97_pcm_assign",
84674 + [51323].param2 = 1,
84675 + [51340].file = "drivers/usb/class/usblp.c",
84676 + [51340].name = "usblp_write",
84677 + [51340].param3 = 1,
84678 + [51499].file = "net/802/garp.c",
84679 + [51499].name = "garp_attr_create",
84680 + [51499].param3 = 1,
84681 + [51842].file = "drivers/hid/hid-core.c",
84682 + [51842].name = "hid_register_field",
84683 + [51842].param2 = 1,
84684 + [51842].param3 = 1,
84685 + [5197].file = "net/core/dev.c",
84686 + [5197].name = "dev_set_alias",
84687 + [5197].param3 = 1,
84688 + [5204].file = "drivers/media/video/usbvision/usbvision-video.c",
84689 + [5204].name = "usbvision_v4l2_read",
84690 + [5204].param3 = 1,
84691 + [5206].file = "drivers/media/dvb/ttpci/av7110_v4l.c",
84692 + [5206].name = "av7110_vbi_write",
84693 + [5206].param3 = 1,
84694 + [52086].file = "drivers/usb/image/mdc800.c",
84695 + [52086].name = "mdc800_device_read",
84696 + [52086].param3 = 1,
84697 + [52099].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
84698 + [52099].name = "do_surface_dirty_sou",
84699 + [52099].param7 = 1,
84700 + [52172].file = "drivers/pcmcia/cistpl.c",
84701 + [52172].name = "pccard_store_cis",
84702 + [52172].param6 = 1,
84703 + [52173].file = "drivers/misc/ibmasm/ibmasmfs.c",
84704 + [52173].name = "remote_settings_file_write",
84705 + [52173].param3 = 1,
84706 + [52199].file = "mm/nobootmem.c",
84707 + [52199].name = "__alloc_bootmem",
84708 + [52199].param1 = 1,
84709 + [52343].file = "drivers/usb/misc/adutux.c",
84710 + [52343].name = "adu_read",
84711 + [52343].param3 = 1,
84712 + [52401].file = "drivers/staging/rtl8712/rtl871x_ioctl_linux.c",
84713 + [52401].name = "r871x_set_wpa_ie",
84714 + [52401].param3 = 1,
84715 + [52699].file = "lib/ts_fsm.c",
84716 + [52699].name = "fsm_init",
84717 + [52699].param2 = 1,
84718 + [52721].file = "security/keys/encrypted-keys/encrypted.c",
84719 + [52721].name = "encrypted_instantiate",
84720 + [52721].param3 = 1,
84721 + [52902].file = "fs/xfs/kmem.h",
84722 + [52902].name = "kmem_zalloc_large",
84723 + [52902].param1 = 1,
84724 + [52950].file = "net/bluetooth/mgmt.c",
84725 + [52950].name = "set_discoverable",
84726 + [52950].param4 = 1,
84727 + [53041].file = "fs/libfs.c",
84728 + [53041].name = "simple_transaction_get",
84729 + [53041].param3 = 1,
84730 + [5313].file = "fs/gfs2/quota.c",
84731 + [5313].name = "do_sync",
84732 + [5313].param1 = 1,
84733 + [53209].file = "drivers/usb/host/ehci-sched.c",
84734 + [53209].name = "iso_sched_alloc",
84735 + [53209].param1 = 1,
84736 + [53302].file = "drivers/firewire/core-cdev.c",
84737 + [53302].name = "dispatch_ioctl",
84738 + [53302].param2 = 1,
84739 + [53355].file = "fs/ceph/dir.c",
84740 + [53355].name = "ceph_read_dir",
84741 + [53355].param3 = 1,
84742 + [53405].file = "drivers/media/video/videobuf-core.c",
84743 + [53405].name = "__videobuf_copy_to_user",
84744 + [53405].param4 = 1,
84745 + [53407].file = "net/wireless/sme.c",
84746 + [53407].name = "cfg80211_connect_result",
84747 + [53407].param4 = 1,
84748 + [53407].param6 = 1,
84749 + [53426].file = "fs/libfs.c",
84750 + [53426].name = "simple_transaction_read",
84751 + [53426].param3 = 1,
84752 + [5344].file = "security/selinux/ss/hashtab.c",
84753 + [5344].name = "hashtab_create",
84754 + [5344].param3 = 1,
84755 + [53513].file = "drivers/mmc/core/mmc_ops.c",
84756 + [53513].name = "mmc_send_bus_test",
84757 + [53513].param4 = 1,
84758 + [53626].file = "drivers/block/paride/pg.c",
84759 + [53626].name = "pg_read",
84760 + [53626].param3 = 1,
84761 + [53631].file = "mm/util.c",
84762 + [53631].name = "memdup_user",
84763 + [53631].param2 = 1,
84764 + [53674].file = "drivers/media/dvb/ttpci/av7110_ca.c",
84765 + [53674].name = "ci_ll_write",
84766 + [53674].param4 = 1,
84767 + [5389].file = "drivers/infiniband/core/uverbs_cmd.c",
84768 + [5389].name = "ib_uverbs_unmarshall_recv",
84769 + [5389].param5 = 1,
84770 + [53901].file = "net/rds/message.c",
84771 + [53901].name = "rds_message_alloc",
84772 + [53901].param1 = 1,
84773 + [53902].file = "net/sctp/socket.c",
84774 + [53902].name = "sctp_setsockopt_initmsg",
84775 + [53902].param3 = 1,
84776 + [5410].file = "kernel/kexec.c",
84777 + [5410].name = "sys_kexec_load",
84778 + [5410].param2 = 1,
84779 + [54172].file = "net/nfc/core.c",
84780 + [54172].name = "nfc_alloc_recv_skb",
84781 + [54172].param1 = 1,
84782 + [54182].file = "drivers/block/rbd.c",
84783 + [54182].name = "rbd_snap_add",
84784 + [54182].param4 = 1,
84785 + [54201].file = "drivers/platform/x86/asus_acpi.c",
84786 + [54201].name = "mled_proc_write",
84787 + [54201].param3 = 1,
84788 + [54263].file = "security/keys/trusted.c",
84789 + [54263].name = "trusted_instantiate",
84790 + [54263].param3 = 1,
84791 + [54296].file = "include/linux/mISDNif.h",
84792 + [54296].name = "_alloc_mISDN_skb",
84793 + [54296].param3 = 1,
84794 + [54298].file = "drivers/usb/wusbcore/crypto.c",
84795 + [54298].name = "wusb_ccm_mac",
84796 + [54298].param7 = 1,
84797 + [54318].file = "include/drm/drm_mem_util.h",
84798 + [54318].name = "drm_malloc_ab",
84799 + [54318].param1 = 1,
84800 + [54318].param2 = 1,
84801 + [54335].file = "drivers/md/dm-table.c",
84802 + [54335].name = "dm_vcalloc",
84803 + [54335].param1 = 1,
84804 + [54335].param2 = 1,
84805 + [54338].file = "fs/ntfs/malloc.h",
84806 + [54338].name = "ntfs_malloc_nofs",
84807 + [54338].param1 = 1,
84808 + [54339].file = "security/smack/smackfs.c",
84809 + [54339].name = "smk_write_cipso",
84810 + [54339].param3 = 1,
84811 + [54369].file = "drivers/usb/storage/realtek_cr.c",
84812 + [54369].name = "rts51x_read_mem",
84813 + [54369].param4 = 1,
84814 + [5438].file = "sound/core/memory.c",
84815 + [5438].name = "copy_to_user_fromio",
84816 + [5438].param3 = 1,
84817 + [54401].file = "lib/dynamic_debug.c",
84818 + [54401].name = "ddebug_proc_write",
84819 + [54401].param3 = 1,
84820 + [54467].file = "net/packet/af_packet.c",
84821 + [54467].name = "packet_setsockopt",
84822 + [54467].param5 = 1,
84823 + [54573].file = "ipc/sem.c",
84824 + [54573].name = "sys_semop",
84825 + [54573].param3 = 1,
84826 + [54583].file = "net/sctp/socket.c",
84827 + [54583].name = "sctp_setsockopt_peer_addr_params",
84828 + [54583].param3 = 1,
84829 + [54643].file = "drivers/isdn/hardware/eicon/divasi.c",
84830 + [54643].name = "um_idi_write",
84831 + [54643].param3 = 1,
84832 + [54657].file = "mm/migrate.c",
84833 + [54657].name = "do_pages_stat",
84834 + [54657].param2 = 1,
84835 + [54663].file = "drivers/isdn/hardware/eicon/platform.h",
84836 + [54663].name = "diva_os_malloc",
84837 + [54663].param2 = 1,
84838 + [54701].file = "drivers/misc/altera-stapl/altera-jtag.c",
84839 + [54701].name = "altera_swap_ir",
84840 + [54701].param2 = 1,
84841 + [54751].file = "drivers/infiniband/core/device.c",
84842 + [54751].name = "ib_alloc_device",
84843 + [54751].param1 = 1,
84844 + [54771].file = "drivers/isdn/mISDN/socket.c",
84845 + [54771].name = "_l2_alloc_skb",
84846 + [54771].param1 = 1,
84847 + [54777].file = "drivers/net/wireless/ath/ath6kl/debug.c",
84848 + [54777].name = "ath6kl_debug_roam_tbl_event",
84849 + [54777].param3 = 1,
84850 + [54806].file = "drivers/scsi/lpfc/lpfc_debugfs.c",
84851 + [54806].name = "lpfc_debugfs_dif_err_write",
84852 + [54806].param3 = 1,
84853 + [5494].file = "fs/cifs/cifsacl.c",
84854 + [5494].name = "cifs_idmap_key_instantiate",
84855 + [5494].param3 = 1,
84856 + [55066].file = "net/ipv6/ipv6_sockglue.c",
84857 + [55066].name = "do_ipv6_setsockopt",
84858 + [55066].param5 = 1,
84859 + [55105].file = "drivers/base/devres.c",
84860 + [55105].name = "devres_alloc",
84861 + [55105].param2 = 1,
84862 + [55115].file = "net/sctp/probe.c",
84863 + [55115].name = "sctpprobe_read",
84864 + [55115].param3 = 1,
84865 + [55155].file = "net/bluetooth/rfcomm/sock.c",
84866 + [55155].name = "rfcomm_sock_setsockopt",
84867 + [55155].param5 = 1,
84868 + [55187].file = "security/keys/keyctl.c",
84869 + [55187].name = "keyctl_describe_key",
84870 + [55187].param3 = 1,
84871 + [55253].file = "drivers/net/wireless/ray_cs.c",
84872 + [55253].name = "ray_cs_essid_proc_write",
84873 + [55253].param3 = 1,
84874 + [55341].file = "drivers/staging/sep/sep_driver.c",
84875 + [55341].name = "sep_prepare_input_output_dma_table_in_dcb",
84876 + [55341].param4 = 1,
84877 + [55341].param5 = 1,
84878 + [55417].file = "drivers/hv/channel.c",
84879 + [55417].name = "vmbus_open",
84880 + [55417].param2 = 1,
84881 + [55417].param3 = 1,
84882 + [5548].file = "drivers/media/media-entity.c",
84883 + [5548].name = "media_entity_init",
84884 + [5548].param2 = 1,
84885 + [5548].param4 = 1,
84886 + [55546].file = "drivers/spi/spi.c",
84887 + [55546].name = "spi_alloc_master",
84888 + [55546].param2 = 1,
84889 + [55580].file = "drivers/usb/mon/mon_bin.c",
84890 + [55580].name = "copy_from_buf",
84891 + [55580].param2 = 1,
84892 + [55584].file = "drivers/tty/tty_buffer.c",
84893 + [55584].name = "tty_buffer_alloc",
84894 + [55584].param2 = 1,
84895 + [55712].file = "drivers/char/mem.c",
84896 + [55712].name = "read_zero",
84897 + [55712].param3 = 1,
84898 + [55727].file = "drivers/media/video/stk-webcam.c",
84899 + [55727].name = "stk_prepare_sio_buffers",
84900 + [55727].param2 = 1,
84901 + [55816].file = "drivers/misc/altera-stapl/altera-jtag.c",
84902 + [55816].name = "altera_set_ir_pre",
84903 + [55816].param2 = 1,
84904 + [55826].file = "drivers/infiniband/hw/ipath/ipath_file_ops.c",
84905 + [55826].name = "ipath_get_base_info",
84906 + [55826].param3 = 1,
84907 + [5586].file = "net/atm/common.c",
84908 + [5586].name = "alloc_tx",
84909 + [5586].param2 = 1,
84910 + [55978].file = "drivers/usb/misc/iowarrior.c",
84911 + [55978].name = "iowarrior_write",
84912 + [55978].param3 = 1,
84913 + [56170].file = "drivers/usb/wusbcore/wa-xfer.c",
84914 + [56170].name = "__wa_xfer_setup_segs",
84915 + [56170].param2 = 1,
84916 + [56199].file = "fs/binfmt_misc.c",
84917 + [56199].name = "parse_command",
84918 + [56199].param2 = 1,
84919 + [56218].file = "drivers/mmc/card/mmc_test.c",
84920 + [56218].name = "mtf_test_write",
84921 + [56218].param3 = 1,
84922 + [56239].file = "fs/sysfs/file.c",
84923 + [56239].name = "fill_write_buffer",
84924 + [56239].param3 = 1,
84925 + [5624].file = "drivers/net/wireless/ath/ath9k/wmi.c",
84926 + [5624].name = "ath9k_wmi_cmd",
84927 + [5624].param4 = 1,
84928 + [56416].file = "drivers/misc/lkdtm.c",
84929 + [56416].name = "do_register_entry",
84930 + [56416].param4 = 1,
84931 + [56458].file = "drivers/usb/host/hwa-hc.c",
84932 + [56458].name = "__hwahc_op_set_ptk",
84933 + [56458].param5 = 1,
84934 + [56471].file = "include/linux/slab.h",
84935 + [56471].name = "kcalloc",
84936 + [56471].param1 = 1,
84937 + [56471].param2 = 1,
84938 + [56513].file = "fs/cifs/connect.c",
84939 + [56513].name = "cifs_readv_from_socket",
84940 + [56513].param3 = 1,
84941 + [56531].file = "net/bluetooth/l2cap_core.c",
84942 + [56531].name = "l2cap_send_cmd",
84943 + [56531].param4 = 1,
84944 + [56544].file = "drivers/block/drbd/drbd_receiver.c",
84945 + [56544].name = "receive_DataRequest",
84946 + [56544].param3 = 1,
84947 + [56609].file = "lib/mpi/mpi-internal.h",
84948 + [56609].name = "RESIZE_IF_NEEDED",
84949 + [56609].param2 = 1,
84950 + [56652].file = "drivers/misc/altera-stapl/altera-jtag.c",
84951 + [56652].name = "altera_set_dr_post",
84952 + [56652].param2 = 1,
84953 + [56653].file = "net/irda/af_irda.c",
84954 + [56653].name = "irda_setsockopt",
84955 + [56653].param5 = 1,
84956 + [56672].file = "drivers/char/agp/generic.c",
84957 + [56672].name = "agp_alloc_page_array",
84958 + [56672].param1 = 1,
84959 + [56798].file = "fs/bio.c",
84960 + [56798].name = "bio_alloc_map_data",
84961 + [56798].param2 = 1,
84962 + [56843].file = "drivers/scsi/scsi_transport_iscsi.c",
84963 + [56843].name = "iscsi_recv_pdu",
84964 + [56843].param4 = 1,
84965 + [56903].file = "drivers/mtd/mtdchar.c",
84966 + [56903].name = "mtdchar_readoob",
84967 + [56903].param4 = 1,
84968 + [5699].file = "net/sctp/socket.c",
84969 + [5699].name = "sctp_setsockopt_default_send_param",
84970 + [5699].param3 = 1,
84971 + [5704].file = "drivers/mtd/mtdswap.c",
84972 + [5704].name = "mtdswap_init",
84973 + [5704].param2 = 1,
84974 + [57128].file = "drivers/pnp/pnpbios/proc.c",
84975 + [57128].name = "pnpbios_proc_write",
84976 + [57128].param3 = 1,
84977 + [57190].file = "drivers/char/agp/generic.c",
84978 + [57190].name = "agp_generic_alloc_user",
84979 + [57190].param1 = 1,
84980 + [57252].file = "drivers/media/dvb/dvb-core/dmxdev.c",
84981 + [57252].name = "dvb_dmxdev_set_buffer_size",
84982 + [57252].param2 = 1,
84983 + [57392].file = "drivers/block/aoe/aoecmd.c",
84984 + [57392].name = "new_skb",
84985 + [57392].param1 = 1,
84986 + [57471].file = "drivers/media/video/sn9c102/sn9c102_core.c",
84987 + [57471].name = "sn9c102_read",
84988 + [57471].param3 = 1,
84989 + [57547].file = "security/keys/encrypted-keys/encrypted.c",
84990 + [57547].name = "get_derived_key",
84991 + [57547].param4 = 1,
84992 + [57552].file = "net/sunrpc/cache.c",
84993 + [57552].name = "cache_slow_downcall",
84994 + [57552].param2 = 1,
84995 + [57670].file = "drivers/bluetooth/btmrvl_debugfs.c",
84996 + [57670].name = "btmrvl_pscmd_write",
84997 + [57670].param3 = 1,
84998 + [57710].file = "include/linux/usb/wusb.h",
84999 + [57710].name = "wusb_prf_256",
85000 + [57710].param7 = 1,
85001 + [57724].file = "net/bluetooth/hci_sock.c",
85002 + [57724].name = "hci_sock_setsockopt",
85003 + [57724].param5 = 1,
85004 + [57761].file = "kernel/kexec.c",
85005 + [57761].name = "kimage_crash_alloc",
85006 + [57761].param3 = 1,
85007 + [57786].file = "net/ipv6/netfilter/ip6_tables.c",
85008 + [57786].name = "compat_do_ip6t_set_ctl",
85009 + [57786].param4 = 1,
85010 + [57872].file = "fs/ceph/xattr.c",
85011 + [57872].name = "ceph_setxattr",
85012 + [57872].param4 = 1,
85013 + [57927].file = "fs/read_write.c",
85014 + [57927].name = "sys_preadv",
85015 + [57927].param3 = 1,
85016 + [58012].file = "include/net/bluetooth/bluetooth.h",
85017 + [58012].name = "bt_skb_alloc",
85018 + [58012].param1 = 1,
85019 + [58020].file = "drivers/firewire/core-cdev.c",
85020 + [58020].name = "fw_device_op_ioctl",
85021 + [58020].param2 = 1,
85022 + [58043].file = "kernel/auditfilter.c",
85023 + [58043].name = "audit_unpack_string",
85024 + [58043].param3 = 1,
85025 + [58087].file = "kernel/module.c",
85026 + [58087].name = "module_alloc_update_bounds_rw",
85027 + [58087].param1 = 1,
85028 + [58124].file = "drivers/usb/misc/usbtest.c",
85029 + [58124].name = "ctrl_out",
85030 + [58124].param3 = 1,
85031 + [58124].param5 = 1,
85032 + [58217].file = "net/sctp/socket.c",
85033 + [58217].name = "sctp_setsockopt_peer_primary_addr",
85034 + [58217].param3 = 1,
85035 + [58263].file = "security/keys/keyring.c",
85036 + [58263].name = "keyring_read",
85037 + [58263].param3 = 1,
85038 + [5830].file = "drivers/gpu/vga/vga_switcheroo.c",
85039 + [5830].name = "vga_switcheroo_debugfs_write",
85040 + [5830].param3 = 1,
85041 + [58320].file = "drivers/scsi/scsi_proc.c",
85042 + [58320].name = "proc_scsi_write",
85043 + [58320].param3 = 1,
85044 + [58344].file = "net/sunrpc/cache.c",
85045 + [58344].name = "read_flush",
85046 + [58344].param3 = 1,
85047 + [58379].file = "mm/nobootmem.c",
85048 + [58379].name = "__alloc_bootmem_node",
85049 + [58379].param2 = 1,
85050 + [58597].file = "kernel/kfifo.c",
85051 + [58597].name = "__kfifo_to_user",
85052 + [58597].param3 = 1,
85053 + [58641].file = "drivers/usb/misc/adutux.c",
85054 + [58641].name = "adu_write",
85055 + [58641].param3 = 1,
85056 + [58709].file = "fs/compat.c",
85057 + [58709].name = "compat_sys_pwritev",
85058 + [58709].param3 = 1,
85059 + [58769].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
85060 + [58769].name = "zd_usb_read_fw",
85061 + [58769].param4 = 1,
85062 + [5876].file = "drivers/net/ppp/ppp_generic.c",
85063 + [5876].name = "ppp_write",
85064 + [5876].param3 = 1,
85065 + [58826].file = "net/sunrpc/xprt.c",
85066 + [58826].name = "xprt_alloc",
85067 + [58826].param2 = 1,
85068 + [58865].file = "include/linux/slub_def.h",
85069 + [58865].name = "kmalloc_order_trace",
85070 + [58865].param1 = 1,
85071 + [58867].file = "drivers/platform/x86/asus_acpi.c",
85072 + [58867].name = "wled_proc_write",
85073 + [58867].param3 = 1,
85074 + [58888].file = "fs/xattr.c",
85075 + [58888].name = "listxattr",
85076 + [58888].param3 = 1,
85077 + [58889].file = "kernel/trace/trace_kprobe.c",
85078 + [58889].name = "probes_write",
85079 + [58889].param3 = 1,
85080 + [58912].file = "drivers/lguest/core.c",
85081 + [58912].name = "__lgwrite",
85082 + [58912].param4 = 1,
85083 + [58918].file = "sound/core/pcm_native.c",
85084 + [58918].name = "snd_pcm_aio_write",
85085 + [58918].param3 = 1,
85086 + [58942].file = "drivers/block/aoe/aoedev.c",
85087 + [58942].name = "aoedev_flush",
85088 + [58942].param2 = 1,
85089 + [58958].file = "fs/fuse/control.c",
85090 + [58958].name = "fuse_conn_limit_write",
85091 + [58958].param3 = 1,
85092 + [59005].file = "drivers/staging/sep/sep_driver.c",
85093 + [59005].name = "sep_prepare_input_dma_table",
85094 + [59005].param2 = 1,
85095 + [59005].param3 = 1,
85096 + [59013].file = "fs/xfs/xfs_ioctl.c",
85097 + [59013].name = "xfs_handle_to_dentry",
85098 + [59013].param3 = 1,
85099 + [59034].file = "drivers/acpi/acpica/dsobject.c",
85100 + [59034].name = "acpi_ds_build_internal_package_obj",
85101 + [59034].param3 = 1,
85102 + [59073].file = "drivers/staging/speakup/i18n.c",
85103 + [59073].name = "msg_set",
85104 + [59073].param3 = 1,
85105 + [59074].file = "drivers/scsi/cxgbi/libcxgbi.c",
85106 + [59074].name = "ddp_make_gl",
85107 + [59074].param1 = 1,
85108 + [59297].file = "drivers/media/dvb/ttpci/av7110_av.c",
85109 + [59297].name = "dvb_play",
85110 + [59297].param3 = 1,
85111 + [59472].file = "drivers/misc/ibmasm/ibmasmfs.c",
85112 + [59472].name = "command_file_write",
85113 + [59472].param3 = 1,
85114 + [59504].file = "fs/exofs/super.c",
85115 + [59504].name = "__alloc_dev_table",
85116 + [59504].param2 = 1,
85117 + [59505].file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
85118 + [59505].name = "pvr2_ioread_read",
85119 + [59505].param3 = 1,
85120 + [59681].file = "fs/xfs/kmem.c",
85121 + [59681].name = "kmem_alloc",
85122 + [59681].param1 = 1,
85123 + [5968].file = "net/sunrpc/sched.c",
85124 + [5968].name = "rpc_malloc",
85125 + [5968].param2 = 1,
85126 + [59695].file = "net/ipv4/netfilter/ipt_ULOG.c",
85127 + [59695].name = "ulog_alloc_skb",
85128 + [59695].param1 = 1,
85129 + [59838].file = "net/netlink/af_netlink.c",
85130 + [59838].name = "nl_pid_hash_zalloc",
85131 + [59838].param1 = 1,
85132 + [59856].file = "drivers/base/devres.c",
85133 + [59856].name = "devm_kzalloc",
85134 + [59856].param2 = 1,
85135 + [60066].file = "mm/filemap.c",
85136 + [60066].name = "iov_iter_copy_from_user",
85137 + [60066].param4 = 1,
85138 + [60185].file = "kernel/params.c",
85139 + [60185].name = "kmalloc_parameter",
85140 + [60185].param1 = 1,
85141 + [60198].file = "fs/nfs/nfs4proc.c",
85142 + [60198].name = "nfs4_write_cached_acl",
85143 + [60198].param3 = 1,
85144 + [60330].file = "drivers/media/video/w9966.c",
85145 + [60330].name = "w9966_v4l_read",
85146 + [60330].param3 = 1,
85147 + [604].file = "drivers/staging/rtl8712/usb_ops_linux.c",
85148 + [604].name = "r8712_usbctrl_vendorreq",
85149 + [604].param6 = 1,
85150 + [60543].file = "drivers/usb/class/usbtmc.c",
85151 + [60543].name = "usbtmc_read",
85152 + [60543].param3 = 1,
85153 + [60683].file = "sound/drivers/opl4/opl4_proc.c",
85154 + [60683].name = "snd_opl4_mem_proc_write",
85155 + [60683].param5 = 1,
85156 + [60693].file = "drivers/misc/hpilo.c",
85157 + [60693].name = "ilo_read",
85158 + [60693].param3 = 1,
85159 + [60744].file = "sound/pci/emu10k1/emuproc.c",
85160 + [60744].name = "snd_emu10k1_fx8010_read",
85161 + [60744].param5 = 1,
85162 + [60777].file = "fs/ntfs/malloc.h",
85163 + [60777].name = "ntfs_malloc_nofs_nofail",
85164 + [60777].param1 = 1,
85165 + [60833].file = "drivers/block/aoe/aoenet.c",
85166 + [60833].name = "set_aoe_iflist",
85167 + [60833].param2 = 1,
85168 + [60882].file = "drivers/input/joydev.c",
85169 + [60882].name = "joydev_compat_ioctl",
85170 + [60882].param2 = 1,
85171 + [60891].file = "kernel/sched/core.c",
85172 + [60891].name = "sys_sched_setaffinity",
85173 + [60891].param2 = 1,
85174 + [60920].file = "drivers/infiniband/hw/qib/qib_file_ops.c",
85175 + [60920].name = "qib_get_base_info",
85176 + [60920].param3 = 1,
85177 + [60928].file = "drivers/staging/bcm/Bcmchar.c",
85178 + [60928].name = "bcm_char_read",
85179 + [60928].param3 = 1,
85180 + [61122].file = "drivers/base/devres.c",
85181 + [61122].name = "alloc_dr",
85182 + [61122].param2 = 1,
85183 + [61254].file = "drivers/scsi/scsi_devinfo.c",
85184 + [61254].name = "proc_scsi_devinfo_write",
85185 + [61254].param3 = 1,
85186 + [61283].file = "drivers/net/wireless/ath/ath6kl/debug.c",
85187 + [61283].name = "ath6kl_fwlog_read",
85188 + [61283].param3 = 1,
85189 + [61289].file = "security/apparmor/apparmorfs.c",
85190 + [61289].name = "aa_simple_write_to_buffer",
85191 + [61289].param4 = 1,
85192 + [61389].file = "include/linux/slab.h",
85193 + [61389].name = "kzalloc_node",
85194 + [61389].param1 = 1,
85195 + [61441].file = "fs/ntfs/file.c",
85196 + [61441].name = "ntfs_copy_from_user_iovec",
85197 + [61441].param3 = 1,
85198 + [61441].param6 = 1,
85199 + [61552].file = "drivers/input/evdev.c",
85200 + [61552].name = "str_to_user",
85201 + [61552].param2 = 1,
85202 + [61673].file = "security/keys/trusted.c",
85203 + [61673].name = "trusted_update",
85204 + [61673].param3 = 1,
85205 + [61676].file = "kernel/module.c",
85206 + [61676].name = "module_alloc_update_bounds_rx",
85207 + [61676].param1 = 1,
85208 + [61684].file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
85209 + [61684].name = "cxgb3_get_cpl_reply_skb",
85210 + [61684].param2 = 1,
85211 + [6173].file = "net/netlink/af_netlink.c",
85212 + [6173].name = "netlink_sendmsg",
85213 + [6173].param4 = 1,
85214 + [61770].file = "drivers/media/video/et61x251/et61x251_core.c",
85215 + [61770].name = "et61x251_read",
85216 + [61770].param3 = 1,
85217 + [61772].file = "fs/exofs/ore_raid.c",
85218 + [61772].name = "_sp2d_alloc",
85219 + [61772].param1 = 1,
85220 + [61772].param2 = 1,
85221 + [61772].param3 = 1,
85222 + [61926].file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
85223 + [61926].name = "ddb_input_read",
85224 + [61926].param3 = 1,
85225 + [61932].file = "drivers/message/fusion/mptctl.c",
85226 + [61932].name = "__mptctl_ioctl",
85227 + [61932].param2 = 1,
85228 + [61966].file = "fs/nfs/nfs4proc.c",
85229 + [61966].name = "nfs4_alloc_slots",
85230 + [61966].param1 = 1,
85231 + [62081].file = "drivers/net/irda/vlsi_ir.c",
85232 + [62081].name = "vlsi_alloc_ring",
85233 + [62081].param3 = 1,
85234 + [62081].param4 = 1,
85235 + [62116].file = "fs/libfs.c",
85236 + [62116].name = "simple_attr_read",
85237 + [62116].param3 = 1,
85238 + [6211].file = "drivers/net/ethernet/amd/pcnet32.c",
85239 + [6211].name = "pcnet32_realloc_tx_ring",
85240 + [6211].param3 = 1,
85241 + [62294].file = "sound/core/info.c",
85242 + [62294].name = "resize_info_buffer",
85243 + [62294].param2 = 1,
85244 + [62387].file = "fs/nfs/idmap.c",
85245 + [62387].name = "nfs_idmap_lookup_id",
85246 + [62387].param2 = 1,
85247 + [62465].file = "drivers/misc/altera-stapl/altera-jtag.c",
85248 + [62465].name = "altera_set_dr_pre",
85249 + [62465].param2 = 1,
85250 + [62466].file = "lib/mpi/mpiutil.c",
85251 + [62466].name = "mpi_alloc",
85252 + [62466].param1 = 1,
85253 + [62495].file = "drivers/block/floppy.c",
85254 + [62495].name = "fallback_on_nodma_alloc",
85255 + [62495].param2 = 1,
85256 + [62498].file = "fs/xattr.c",
85257 + [62498].name = "sys_listxattr",
85258 + [62498].param3 = 1,
85259 + [625].file = "fs/read_write.c",
85260 + [625].name = "sys_pwritev",
85261 + [625].param3 = 1,
85262 + [62662].file = "drivers/message/fusion/mptctl.c",
85263 + [62662].name = "mptctl_getiocinfo",
85264 + [62662].param2 = 1,
85265 + [62669].file = "drivers/platform/x86/asus_acpi.c",
85266 + [62669].name = "tled_proc_write",
85267 + [62669].param3 = 1,
85268 + [62714].file = "security/keys/keyctl.c",
85269 + [62714].name = "keyctl_update_key",
85270 + [62714].param3 = 1,
85271 + [62760].file = "drivers/media/dvb/ttpci/av7110_av.c",
85272 + [62760].name = "play_iframe",
85273 + [62760].param3 = 1,
85274 + [62851].file = "fs/proc/vmcore.c",
85275 + [62851].name = "read_vmcore",
85276 + [62851].param3 = 1,
85277 + [62870].file = "fs/nfs/idmap.c",
85278 + [62870].name = "nfs_idmap_get_desc",
85279 + [62870].param2 = 1,
85280 + [62870].param4 = 1,
85281 + [62905].file = "net/caif/cfpkt_skbuff.c",
85282 + [62905].name = "cfpkt_create",
85283 + [62905].param1 = 1,
85284 + [62920].file = "drivers/net/wireless/b43/phy_n.c",
85285 + [62920].name = "b43_nphy_load_samples",
85286 + [62920].param3 = 1,
85287 + [62925].file = "include/rdma/ib_verbs.h",
85288 + [62925].name = "ib_copy_from_udata",
85289 + [62925].param3 = 1,
85290 + [62934].file = "drivers/net/wireless/wl1251/cmd.c",
85291 + [62934].name = "wl1251_cmd_template_set",
85292 + [62934].param4 = 1,
85293 + [62940].file = "drivers/scsi/libsrp.c",
85294 + [62940].name = "srp_ring_alloc",
85295 + [62940].param2 = 1,
85296 + [62967].file = "security/keys/encrypted-keys/encrypted.c",
85297 + [62967].name = "encrypted_update",
85298 + [62967].param3 = 1,
85299 + [62970].file = "net/sched/sch_api.c",
85300 + [62970].name = "qdisc_class_hash_alloc",
85301 + [62970].param1 = 1,
85302 + [62999].file = "net/core/neighbour.c",
85303 + [62999].name = "neigh_hash_alloc",
85304 + [62999].param1 = 1,
85305 + [63007].file = "fs/proc/base.c",
85306 + [63007].name = "proc_coredump_filter_write",
85307 + [63007].param3 = 1,
85308 + [63010].file = "drivers/gpu/drm/ttm/ttm_page_alloc.c",
85309 + [63010].name = "ttm_page_pool_free",
85310 + [63010].param2 = 1,
85311 + [63045].file = "crypto/shash.c",
85312 + [63045].name = "shash_setkey_unaligned",
85313 + [63045].param3 = 1,
85314 + [63075].file = "kernel/relay.c",
85315 + [63075].name = "relay_alloc_page_array",
85316 + [63075].param1 = 1,
85317 + [63076].file = "fs/cifs/xattr.c",
85318 + [63076].name = "cifs_setxattr",
85319 + [63076].param4 = 1,
85320 + [63091].file = "drivers/net/usb/pegasus.c",
85321 + [63091].name = "get_registers",
85322 + [63091].param3 = 1,
85323 + [6331].file = "drivers/atm/solos-pci.c",
85324 + [6331].name = "solos_param_store",
85325 + [6331].param4 = 1,
85326 + [63367].file = "net/netfilter/ipset/ip_set_core.c",
85327 + [63367].name = "ip_set_alloc",
85328 + [63367].param1 = 1,
85329 + [63489].file = "drivers/bluetooth/btmrvl_debugfs.c",
85330 + [63489].name = "btmrvl_hscfgcmd_write",
85331 + [63489].param3 = 1,
85332 + [63490].file = "crypto/shash.c",
85333 + [63490].name = "shash_compat_setkey",
85334 + [63490].param3 = 1,
85335 + [63605].file = "mm/mempool.c",
85336 + [63605].name = "mempool_kmalloc",
85337 + [63605].param2 = 1,
85338 + [63633].file = "drivers/bluetooth/btmrvl_sdio.c",
85339 + [63633].name = "btmrvl_sdio_host_to_card",
85340 + [63633].param3 = 1,
85341 + [63961].file = "fs/xattr.c",
85342 + [63961].name = "sys_flistxattr",
85343 + [63961].param3 = 1,
85344 + [63964].file = "net/sctp/socket.c",
85345 + [63964].name = "sctp_setsockopt_maxseg",
85346 + [63964].param3 = 1,
85347 + [63988].file = "drivers/input/evdev.c",
85348 + [63988].name = "evdev_ioctl_compat",
85349 + [63988].param2 = 1,
85350 + [64055].file = "drivers/media/dvb/ttpci/av7110_av.c",
85351 + [64055].name = "dvb_aplay",
85352 + [64055].param3 = 1,
85353 + [64156].file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
85354 + [64156].name = "ath6kl_mgmt_tx",
85355 + [64156].param9 = 1,
85356 + [64226].file = "drivers/md/persistent-data/dm-space-map-checker.c",
85357 + [64226].name = "ca_extend",
85358 + [64226].param2 = 1,
85359 + [64227].file = "mm/nobootmem.c",
85360 + [64227].name = "__alloc_bootmem_node_nopanic",
85361 + [64227].param2 = 1,
85362 + [64351].file = "kernel/kfifo.c",
85363 + [64351].name = "kfifo_copy_from_user",
85364 + [64351].param3 = 1,
85365 + [64392].file = "drivers/mmc/core/mmc_ops.c",
85366 + [64392].name = "mmc_send_cxd_data",
85367 + [64392].param5 = 1,
85368 + [64423].file = "kernel/sched/core.c",
85369 + [64423].name = "get_user_cpu_mask",
85370 + [64423].param2 = 1,
85371 + [64432].file = "security/selinux/selinuxfs.c",
85372 + [64432].name = "sel_write_create",
85373 + [64432].param3 = 1,
85374 + [64471].file = "drivers/bluetooth/btmrvl_debugfs.c",
85375 + [64471].name = "btmrvl_hscmd_write",
85376 + [64471].param3 = 1,
85377 + [64667].file = "sound/core/oss/pcm_oss.c",
85378 + [64667].name = "snd_pcm_oss_read",
85379 + [64667].param3 = 1,
85380 + [64689].file = "sound/isa/gus/gus_dram.c",
85381 + [64689].name = "snd_gus_dram_read",
85382 + [64689].param4 = 1,
85383 + [64692].file = "fs/binfmt_misc.c",
85384 + [64692].name = "bm_entry_write",
85385 + [64692].param3 = 1,
85386 + [64705].file = "drivers/staging/iio/accel/sca3000_ring.c",
85387 + [64705].name = "sca3000_read_first_n_hw_rb",
85388 + [64705].param2 = 1,
85389 + [64713].file = "fs/cifs/connect.c",
85390 + [64713].name = "extract_hostname",
85391 + [64713].param1 = 1,
85392 + [64743].file = "fs/ocfs2/dlmfs/dlmfs.c",
85393 + [64743].name = "dlmfs_file_read",
85394 + [64743].param3 = 1,
85395 + [64771].file = "security/keys/encrypted-keys/encrypted.c",
85396 + [64771].name = "datablob_format",
85397 + [64771].param2 = 1,
85398 + [6477].file = "net/bluetooth/mgmt.c",
85399 + [6477].name = "mgmt_pending_add",
85400 + [6477].param5 = 1,
85401 + [64906].file = "drivers/net/wireless/b43legacy/debugfs.c",
85402 + [64906].name = "b43legacy_debugfs_write",
85403 + [64906].param3 = 1,
85404 + [64913].file = "sound/core/oss/pcm_oss.c",
85405 + [64913].name = "snd_pcm_oss_write1",
85406 + [64913].param3 = 1,
85407 + [64961].file = "drivers/spi/spidev.c",
85408 + [64961].name = "spidev_ioctl",
85409 + [64961].param2 = 1,
85410 + [65033].file = "crypto/shash.c",
85411 + [65033].name = "shash_async_setkey",
85412 + [65033].param3 = 1,
85413 + [65093].file = "security/integrity/evm/evm_secfs.c",
85414 + [65093].name = "evm_write_key",
85415 + [65093].param3 = 1,
85416 + [6514].file = "mm/nobootmem.c",
85417 + [6514].name = "__alloc_bootmem_low",
85418 + [6514].param1 = 1,
85419 + [65169].file = "net/core/skbuff.c",
85420 + [65169].name = "dev_alloc_skb",
85421 + [65169].param1 = 1,
85422 + [6517].file = "drivers/md/dm-table.c",
85423 + [6517].name = "alloc_targets",
85424 + [6517].param2 = 1,
85425 + [65205].file = "drivers/input/evdev.c",
85426 + [65205].name = "handle_eviocgbit",
85427 + [65205].param3 = 1,
85428 + [65237].file = "kernel/profile.c",
85429 + [65237].name = "read_profile",
85430 + [65237].param3 = 1,
85431 + [65343].file = "kernel/trace/trace.c",
85432 + [65343].name = "tracing_clock_write",
85433 + [65343].param3 = 1,
85434 + [65345].file = "lib/xz/xz_dec_lzma2.c",
85435 + [65345].name = "xz_dec_lzma2_create",
85436 + [65345].param2 = 1,
85437 + [65409].file = "net/802/garp.c",
85438 + [65409].name = "garp_request_join",
85439 + [65409].param4 = 1,
85440 + [65432].file = "drivers/hid/hid-roccat-kone.c",
85441 + [65432].name = "kone_receive",
85442 + [65432].param4 = 1,
85443 + [65514].file = "drivers/media/video/gspca/t613.c",
85444 + [65514].name = "reg_w_ixbuf",
85445 + [65514].param4 = 1,
85446 + [6551].file = "drivers/usb/host/xhci-mem.c",
85447 + [6551].name = "xhci_alloc_stream_info",
85448 + [6551].param3 = 1,
85449 + [65535].file = "drivers/media/dvb/dvb-usb/opera1.c",
85450 + [65535].name = "opera1_xilinx_rw",
85451 + [65535].param5 = 1,
85452 + [6672].file = "drivers/net/wireless/b43/debugfs.c",
85453 + [6672].name = "b43_debugfs_write",
85454 + [6672].param3 = 1,
85455 + [6691].file = "drivers/acpi/proc.c",
85456 + [6691].name = "acpi_system_write_wakeup_device",
85457 + [6691].param3 = 1,
85458 + [6865].file = "drivers/staging/iio/ring_sw.c",
85459 + [6865].name = "iio_read_first_n_sw_rb",
85460 + [6865].param2 = 1,
85461 + [6867].file = "fs/coda/psdev.c",
85462 + [6867].name = "coda_psdev_read",
85463 + [6867].param3 = 1,
85464 + [6891].file = "drivers/bluetooth/btmrvl_debugfs.c",
85465 + [6891].name = "btmrvl_gpiogap_write",
85466 + [6891].param3 = 1,
85467 + [6944].file = "drivers/ide/ide-proc.c",
85468 + [6944].name = "ide_settings_proc_write",
85469 + [6944].param3 = 1,
85470 + [6950].file = "drivers/isdn/capi/capi.c",
85471 + [6950].name = "capi_write",
85472 + [6950].param3 = 1,
85473 + [697].file = "sound/isa/gus/gus_dram.c",
85474 + [697].name = "snd_gus_dram_peek",
85475 + [697].param4 = 1,
85476 + [7066].file = "security/keys/keyctl.c",
85477 + [7066].name = "keyctl_instantiate_key_common",
85478 + [7066].param4 = 1,
85479 + [7125].file = "include/net/nfc/nci_core.h",
85480 + [7125].name = "nci_skb_alloc",
85481 + [7125].param2 = 1,
85482 + [7129].file = "mm/maccess.c",
85483 + [7129].name = "__probe_kernel_read",
85484 + [7129].param3 = 1,
85485 + [7158].file = "kernel/trace/trace.c",
85486 + [7158].name = "tracing_read_pipe",
85487 + [7158].param3 = 1,
85488 + [720].file = "sound/pci/rme9652/hdsp.c",
85489 + [720].name = "snd_hdsp_playback_copy",
85490 + [720].param5 = 1,
85491 + [7236].file = "drivers/gpu/drm/drm_crtc.c",
85492 + [7236].name = "drm_plane_init",
85493 + [7236].param6 = 1,
85494 + [7411].file = "drivers/vhost/vhost.c",
85495 + [7411].name = "__vhost_add_used_n",
85496 + [7411].param3 = 1,
85497 + [7432].file = "net/bluetooth/mgmt.c",
85498 + [7432].name = "mgmt_event",
85499 + [7432].param4 = 1,
85500 + [7488].file = "security/keys/user_defined.c",
85501 + [7488].name = "user_read",
85502 + [7488].param3 = 1,
85503 + [7551].file = "drivers/input/touchscreen/ad7879-spi.c",
85504 + [7551].name = "ad7879_spi_xfer",
85505 + [7551].param3 = 1,
85506 + [7671].file = "mm/nobootmem.c",
85507 + [7671].name = "__alloc_bootmem_node_high",
85508 + [7671].param2 = 1,
85509 + [7676].file = "drivers/acpi/custom_method.c",
85510 + [7676].name = "cm_write",
85511 + [7676].param3 = 1,
85512 + [7693].file = "net/sctp/socket.c",
85513 + [7693].name = "sctp_setsockopt_associnfo",
85514 + [7693].param3 = 1,
85515 + [7697].file = "security/selinux/selinuxfs.c",
85516 + [7697].name = "sel_write_access",
85517 + [7697].param3 = 1,
85518 + [7843].file = "fs/compat.c",
85519 + [7843].name = "compat_sys_readv",
85520 + [7843].param3 = 1,
85521 + [7883].file = "net/sched/sch_sfq.c",
85522 + [7883].name = "sfq_alloc",
85523 + [7883].param1 = 1,
85524 + [7924].file = "drivers/media/video/cx18/cx18-fileops.c",
85525 + [7924].name = "cx18_read_pos",
85526 + [7924].param3 = 1,
85527 + [7958].file = "drivers/gpu/vga/vgaarb.c",
85528 + [7958].name = "vga_arb_write",
85529 + [7958].param3 = 1,
85530 + [7976].file = "drivers/usb/gadget/rndis.c",
85531 + [7976].name = "rndis_add_response",
85532 + [7976].param2 = 1,
85533 + [7985].file = "net/mac80211/cfg.c",
85534 + [7985].name = "ieee80211_mgmt_tx",
85535 + [7985].param9 = 1,
85536 + [8014].file = "net/netfilter/ipset/ip_set_list_set.c",
85537 + [8014].name = "init_list_set",
85538 + [8014].param2 = 1,
85539 + [8014].param3 = 1,
85540 + [8126].file = "sound/soc/soc-core.c",
85541 + [8126].name = "codec_reg_read_file",
85542 + [8126].param3 = 1,
85543 + [8317].file = "security/smack/smackfs.c",
85544 + [8317].name = "smk_write_ambient",
85545 + [8317].param3 = 1,
85546 + [8335].file = "drivers/media/dvb/dvb-core/dmxdev.c",
85547 + [8335].name = "dvb_dvr_set_buffer_size",
85548 + [8335].param2 = 1,
85549 + [8383].file = "kernel/module.c",
85550 + [8383].name = "copy_and_check",
85551 + [8383].param3 = 1,
85552 + [8411].file = "net/caif/cfpkt_skbuff.c",
85553 + [8411].name = "cfpkt_append",
85554 + [8411].param3 = 1,
85555 + [8536].file = "fs/cifs/dns_resolve.c",
85556 + [8536].name = "dns_resolve_server_name_to_ip",
85557 + [8536].param1 = 1,
85558 + [857].file = "drivers/virtio/virtio_ring.c",
85559 + [857].name = "virtqueue_add_buf",
85560 + [857].param3 = 1,
85561 + [857].param4 = 1,
85562 + [8650].file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
85563 + [8650].name = "vmw_kms_present",
85564 + [8650].param9 = 1,
85565 + [8654].file = "drivers/net/wireless/mwifiex/sdio.c",
85566 + [8654].name = "mwifiex_alloc_sdio_mpa_buffers",
85567 + [8654].param2 = 1,
85568 + [8654].param3 = 1,
85569 + [865].file = "drivers/base/regmap/regmap-debugfs.c",
85570 + [865].name = "regmap_access_read_file",
85571 + [865].param3 = 1,
85572 + [8663].file = "net/bridge/netfilter/ebtables.c",
85573 + [8663].name = "do_update_counters",
85574 + [8663].param4 = 1,
85575 + [8684].file = "fs/read_write.c",
85576 + [8684].name = "sys_writev",
85577 + [8684].param3 = 1,
85578 + [8699].file = "security/selinux/selinuxfs.c",
85579 + [8699].name = "sel_commit_bools_write",
85580 + [8699].param3 = 1,
85581 + [8764].file = "drivers/usb/core/devio.c",
85582 + [8764].name = "usbdev_read",
85583 + [8764].param3 = 1,
85584 + [8802].file = "fs/dlm/user.c",
85585 + [8802].name = "device_write",
85586 + [8802].param3 = 1,
85587 + [8810].file = "net/mac80211/debugfs_sta.c",
85588 + [8810].name = "sta_agg_status_write",
85589 + [8810].param3 = 1,
85590 + [8815].file = "security/tomoyo/securityfs_if.c",
85591 + [8815].name = "tomoyo_write_self",
85592 + [8815].param3 = 1,
85593 + [8821].file = "net/wireless/sme.c",
85594 + [8821].name = "cfg80211_roamed",
85595 + [8821].param5 = 1,
85596 + [8821].param7 = 1,
85597 + [8833].file = "security/selinux/ss/services.c",
85598 + [8833].name = "security_context_to_sid",
85599 + [8833].param2 = 1,
85600 + [8838].file = "lib/mpi/mpi-bit.c",
85601 + [8838].name = "mpi_lshift_limbs",
85602 + [8838].param2 = 1,
85603 + [8851].file = "net/key/af_key.c",
85604 + [8851].name = "pfkey_sendmsg",
85605 + [8851].param4 = 1,
85606 + [8917].file = "net/can/raw.c",
85607 + [8917].name = "raw_setsockopt",
85608 + [8917].param5 = 1,
85609 + [8983].file = "include/linux/skbuff.h",
85610 + [8983].name = "alloc_skb",
85611 + [8983].param1 = 1,
85612 + [9117].file = "drivers/base/regmap/regcache-rbtree.c",
85613 + [9117].name = "regcache_rbtree_insert_to_block",
85614 + [9117].param5 = 1,
85615 + [9226].file = "mm/migrate.c",
85616 + [9226].name = "sys_move_pages",
85617 + [9226].param2 = 1,
85618 + [9304].file = "kernel/auditfilter.c",
85619 + [9304].name = "audit_init_entry",
85620 + [9304].param1 = 1,
85621 + [9317].file = "drivers/usb/wusbcore/wa-nep.c",
85622 + [9317].name = "wa_nep_queue",
85623 + [9317].param2 = 1,
85624 + [9341].file = "drivers/acpi/apei/erst-dbg.c",
85625 + [9341].name = "erst_dbg_write",
85626 + [9341].param3 = 1,
85627 + [9386].file = "fs/exofs/ore.c",
85628 + [9386].name = "_ore_get_io_state",
85629 + [9386].param3 = 1,
85630 + [9386].param4 = 1,
85631 + [9386].param5 = 1,
85632 + [9538].file = "crypto/blkcipher.c",
85633 + [9538].name = "blkcipher_copy_iv",
85634 + [9538].param3 = 1,
85635 + [9546].file = "drivers/video/fbmem.c",
85636 + [9546].name = "fb_write",
85637 + [9546].param3 = 1,
85638 + [9601].file = "kernel/kfifo.c",
85639 + [9601].name = "__kfifo_from_user",
85640 + [9601].param3 = 1,
85641 + [9618].file = "security/selinux/selinuxfs.c",
85642 + [9618].name = "sel_write_bool",
85643 + [9618].param3 = 1,
85644 + [9768].file = "drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c",
85645 + [9768].name = "vmw_execbuf_process",
85646 + [9768].param5 = 1,
85647 + [9828].file = "drivers/media/dvb/dvb-core/dmxdev.c",
85648 + [9828].name = "dvb_demux_do_ioctl",
85649 + [9828].param3 = 1,
85650 + [9870].file = "net/atm/addr.c",
85651 + [9870].name = "atm_get_addr",
85652 + [9870].param3 = 1,
85653 + [9977].file = "drivers/net/wireless/zd1211rw/zd_usb.c",
85654 + [9977].name = "zd_usb_iowrite16v_async",
85655 + [9977].param3 = 1,
85656 + [16344].collision = 1,
85657 + [307].collision = 1,
85658 + [31649].collision = 1,
85659 + [33040].collision = 1,
85660 + [45231].collision = 1,
85661 + [60651].collision = 1,
85662 +};
85663 diff --git a/tools/gcc/size_overflow_hash2.h b/tools/gcc/size_overflow_hash2.h
85664 new file mode 100644
85665 index 0000000..9ec45ae
85666 --- /dev/null
85667 +++ b/tools/gcc/size_overflow_hash2.h
85668 @@ -0,0 +1,35 @@
85669 +struct size_overflow_hash size_overflow_hash2[65536] = {
85670 + [22224].file = "fs/proc/vmcore.c",
85671 + [22224].name = "read_from_oldmem",
85672 + [22224].param2 = 1,
85673 + [2344].file = "fs/ecryptfs/crypto.c",
85674 + [2344].name = "ecryptfs_decode_and_decrypt_filename",
85675 + [2344].param5 = 1,
85676 + [2515].file = "fs/ecryptfs/crypto.c",
85677 + [2515].name = "ecryptfs_copy_filename",
85678 + [2515].param4 = 1,
85679 + [26518].file = "drivers/gpu/vga/vgaarb.c",
85680 + [26518].name = "vga_arb_read",
85681 + [26518].param3 = 1,
85682 + [30632].file = "drivers/ide/ide-proc.c",
85683 + [30632].name = "ide_driver_proc_write",
85684 + [30632].param3 = 1,
85685 + [39024].file = "lib/scatterlist.c",
85686 + [39024].name = "sg_kmalloc",
85687 + [39024].param1 = 1,
85688 + [50359].file = "kernel/sched/core.c",
85689 + [50359].name = "alloc_sched_domains",
85690 + [50359].param1 = 1,
85691 + [53262].file = "drivers/block/aoe/aoechr.c",
85692 + [53262].name = "revalidate",
85693 + [53262].param2 = 1,
85694 + [56432].file = "drivers/base/regmap/regmap-debugfs.c",
85695 + [56432].name = "regmap_map_read_file",
85696 + [56432].param3 = 1,
85697 + [57500].file = "drivers/spi/spidev.c",
85698 + [57500].name = "spidev_write",
85699 + [57500].param3 = 1,
85700 + [8155].file = "drivers/hv/channel.c",
85701 + [8155].name = "vmbus_establish_gpadl",
85702 + [8155].param3 = 1,
85703 +};
85704 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
85705 new file mode 100644
85706 index 0000000..4ec0934
85707 --- /dev/null
85708 +++ b/tools/gcc/size_overflow_plugin.c
85709 @@ -0,0 +1,1150 @@
85710 +/*
85711 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
85712 + * Licensed under the GPL v2, or (at your option) v3
85713 + *
85714 + * Homepage:
85715 + * http://www.grsecurity.net/~ephox/overflow_plugin/
85716 + *
85717 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
85718 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
85719 + * The recomputed argument is checked against INT_MAX and an event is logged on overflow and the triggering process is killed.
85720 + *
85721 + * Usage:
85722 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o size_overflow_plugin.so size_overflow_plugin.c
85723 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
85724 + */
85725 +
85726 +#include "gcc-plugin.h"
85727 +#include "config.h"
85728 +#include "system.h"
85729 +#include "coretypes.h"
85730 +#include "tree.h"
85731 +#include "tree-pass.h"
85732 +#include "intl.h"
85733 +#include "plugin-version.h"
85734 +#include "tm.h"
85735 +#include "toplev.h"
85736 +#include "function.h"
85737 +#include "tree-flow.h"
85738 +#include "plugin.h"
85739 +#include "gimple.h"
85740 +#include "c-common.h"
85741 +#include "diagnostic.h"
85742 +#include "cfgloop.h"
85743 +
85744 +struct size_overflow_hash {
85745 + const char *name;
85746 + const char *file;
85747 + unsigned short collision:1;
85748 + unsigned short param1:1;
85749 + unsigned short param2:1;
85750 + unsigned short param3:1;
85751 + unsigned short param4:1;
85752 + unsigned short param5:1;
85753 + unsigned short param6:1;
85754 + unsigned short param7:1;
85755 + unsigned short param8:1;
85756 + unsigned short param9:1;
85757 +};
85758 +
85759 +#include "size_overflow_hash1.h"
85760 +#include "size_overflow_hash2.h"
85761 +
85762 +#define __unused __attribute__((__unused__))
85763 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
85764 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
85765 +#define BEFORE_STMT true
85766 +#define AFTER_STMT false
85767 +#define CREATE_NEW_VAR NULL_TREE
85768 +
85769 +int plugin_is_GPL_compatible;
85770 +void debug_gimple_stmt(gimple gs);
85771 +
85772 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
85773 +static tree signed_size_overflow_type;
85774 +static tree unsigned_size_overflow_type;
85775 +static tree report_size_overflow_decl;
85776 +static tree const_char_ptr_type_node;
85777 +static unsigned int handle_function(void);
85778 +static bool file_match = true;
85779 +
85780 +static struct plugin_info size_overflow_plugin_info = {
85781 + .version = "20120502beta",
85782 + .help = "no-size_overflow\tturn off size overflow checking\n",
85783 +};
85784 +
85785 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
85786 +{
85787 + unsigned int arg_count = type_num_arguments(*node);
85788 +
85789 + for (; args; args = TREE_CHAIN(args)) {
85790 + tree position = TREE_VALUE(args);
85791 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
85792 + error("handle_size_overflow_attribute: overflow parameter outside range.");
85793 + *no_add_attrs = true;
85794 + }
85795 + }
85796 + return NULL_TREE;
85797 +}
85798 +
85799 +static struct attribute_spec no_size_overflow_attr = {
85800 + .name = "size_overflow",
85801 + .min_length = 1,
85802 + .max_length = -1,
85803 + .decl_required = false,
85804 + .type_required = true,
85805 + .function_type_required = true,
85806 + .handler = handle_size_overflow_attribute
85807 +};
85808 +
85809 +static void register_attributes(void __unused *event_data, void __unused *data)
85810 +{
85811 + register_attribute(&no_size_overflow_attr);
85812 +}
85813 +
85814 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
85815 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
85816 +{
85817 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
85818 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
85819 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
85820 +
85821 + const unsigned int m = 0x57559429;
85822 + const unsigned int n = 0x5052acdb;
85823 + const unsigned int *key4 = (const unsigned int *)key;
85824 + unsigned int h = len;
85825 + unsigned int k = len + seed + n;
85826 + unsigned long long p;
85827 +
85828 + while (len >= 8) {
85829 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
85830 + len -= 8;
85831 + }
85832 + if (len >= 4) {
85833 + cwmixb(key4[0]) key4 += 1;
85834 + len -= 4;
85835 + }
85836 + if (len)
85837 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
85838 + cwmixb(h ^ (k + n));
85839 + return k ^ h;
85840 +
85841 +#undef cwfold
85842 +#undef cwmixa
85843 +#undef cwmixb
85844 +}
85845 +
85846 +static inline unsigned int size_overflow_hash(const char *fndecl, unsigned int seed)
85847 +{
85848 + return CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
85849 +}
85850 +
85851 +static inline tree get_original_function_decl(tree fndecl)
85852 +{
85853 + if (DECL_ABSTRACT_ORIGIN(fndecl))
85854 + return DECL_ABSTRACT_ORIGIN(fndecl);
85855 + return fndecl;
85856 +}
85857 +
85858 +static inline gimple get_def_stmt(tree node)
85859 +{
85860 + gcc_assert(TREE_CODE(node) == SSA_NAME);
85861 + return SSA_NAME_DEF_STMT(node);
85862 +}
85863 +
85864 +static struct size_overflow_hash *get_function_hash(tree fndecl)
85865 +{
85866 + unsigned int hash;
85867 + const char *func = NAME(fndecl);
85868 +
85869 + hash = size_overflow_hash(func, 0);
85870 +
85871 + if (size_overflow_hash1[hash].collision) {
85872 + hash = size_overflow_hash(func, 23432);
85873 + return &size_overflow_hash2[hash];
85874 + }
85875 + return &size_overflow_hash1[hash];
85876 +}
85877 +
85878 +static void check_arg_type(tree var)
85879 +{
85880 + tree type = TREE_TYPE(var);
85881 + enum tree_code code = TREE_CODE(type);
85882 +
85883 + gcc_assert(code == INTEGER_TYPE ||
85884 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
85885 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
85886 +}
85887 +
85888 +static void check_missing_attribute(tree arg)
85889 +{
85890 + tree var, type, func = get_original_function_decl(current_function_decl);
85891 + const char *curfunc = NAME(func);
85892 + unsigned int new_hash, argnum = 1;
85893 + struct size_overflow_hash *hash;
85894 + location_t loc;
85895 + expanded_location xloc;
85896 + bool match = false;
85897 +
85898 + type = TREE_TYPE(arg);
85899 + // skip function pointers
85900 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
85901 + return;
85902 +
85903 + loc = DECL_SOURCE_LOCATION(func);
85904 + xloc = expand_location(loc);
85905 +
85906 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
85907 + return;
85908 +
85909 + hash = get_function_hash(func);
85910 + if (hash->name && !strcmp(hash->name, NAME(func)))
85911 + return;
85912 + if (file_match && hash->file && !strcmp(hash->file, xloc.file))
85913 + return;
85914 +
85915 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
85916 +
85917 + if (TREE_CODE(arg) == SSA_NAME)
85918 + arg = SSA_NAME_VAR(arg);
85919 +
85920 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
85921 + if (strcmp(NAME(arg), NAME(var))) {
85922 + argnum++;
85923 + continue;
85924 + }
85925 + check_arg_type(var);
85926 +
85927 + match = true;
85928 + if (!TYPE_UNSIGNED(TREE_TYPE(var)))
85929 + return;
85930 + break;
85931 + }
85932 + if (!match) {
85933 + warning(0, "check_missing_attribute: cannot find the %s argument in %s", NAME(arg), NAME(func));
85934 + return;
85935 + }
85936 +
85937 +#define check_param(num) \
85938 + if (num == argnum && hash->param##num) \
85939 + return;
85940 + check_param(1);
85941 + check_param(2);
85942 + check_param(3);
85943 + check_param(4);
85944 + check_param(5);
85945 + check_param(6);
85946 + check_param(7);
85947 + check_param(8);
85948 + check_param(9);
85949 +#undef check_param
85950 +
85951 + new_hash = size_overflow_hash(curfunc, 0);
85952 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+%s", curfunc, curfunc, argnum, new_hash, xloc.file);
85953 +}
85954 +
85955 +static tree create_new_var(tree type)
85956 +{
85957 + tree new_var = create_tmp_var(type, "cicus");
85958 +
85959 + add_referenced_var(new_var);
85960 + mark_sym_for_renaming(new_var);
85961 + return new_var;
85962 +}
85963 +
85964 +static bool is_bool(tree node)
85965 +{
85966 + tree type;
85967 +
85968 + if (node == NULL_TREE)
85969 + return false;
85970 +
85971 + type = TREE_TYPE(node);
85972 + if (!INTEGRAL_TYPE_P(type))
85973 + return false;
85974 + if (TREE_CODE(type) == BOOLEAN_TYPE)
85975 + return true;
85976 + if (TYPE_PRECISION(type) == 1)
85977 + return true;
85978 + return false;
85979 +}
85980 +
85981 +static tree cast_a_tree(tree type, tree var)
85982 +{
85983 + gcc_assert(fold_convertible_p(type, var));
85984 +
85985 + return fold_convert(type, var);
85986 +}
85987 +
85988 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
85989 +{
85990 + gimple assign;
85991 +
85992 + if (new_var == CREATE_NEW_VAR)
85993 + new_var = create_new_var(type);
85994 +
85995 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
85996 + gimple_set_location(assign, loc);
85997 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
85998 +
85999 + return assign;
86000 +}
86001 +
86002 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
86003 +{
86004 + tree oldstmt_rhs1;
86005 + enum tree_code code;
86006 + gimple stmt;
86007 + gimple_stmt_iterator gsi;
86008 +
86009 + if (!*potentionally_overflowed)
86010 + return NULL_TREE;
86011 +
86012 + if (rhs1 == NULL_TREE) {
86013 + debug_gimple_stmt(oldstmt);
86014 + error("create_assign: rhs1 is NULL_TREE");
86015 + gcc_unreachable();
86016 + }
86017 +
86018 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
86019 + code = TREE_CODE(oldstmt_rhs1);
86020 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
86021 + check_missing_attribute(oldstmt_rhs1);
86022 +
86023 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
86024 + gsi = gsi_for_stmt(oldstmt);
86025 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
86026 + basic_block next_bb, cur_bb;
86027 + edge e;
86028 +
86029 + gcc_assert(before == false);
86030 + gcc_assert(stmt_can_throw_internal(oldstmt));
86031 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
86032 + gcc_assert(!gsi_end_p(gsi));
86033 +
86034 + cur_bb = gimple_bb(oldstmt);
86035 + next_bb = cur_bb->next_bb;
86036 + e = find_edge(cur_bb, next_bb);
86037 + gcc_assert(e != NULL);
86038 + gcc_assert(e->flags & EDGE_FALLTHRU);
86039 +
86040 + gsi = gsi_after_labels(next_bb);
86041 + gcc_assert(!gsi_end_p(gsi));
86042 + before = true;
86043 + }
86044 + if (before)
86045 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
86046 + else
86047 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
86048 + update_stmt(stmt);
86049 + pointer_set_insert(visited, oldstmt);
86050 + return gimple_get_lhs(stmt);
86051 +}
86052 +
86053 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
86054 +{
86055 + tree new_var, lhs = gimple_get_lhs(oldstmt);
86056 + gimple stmt;
86057 + gimple_stmt_iterator gsi;
86058 +
86059 + if (!*potentionally_overflowed)
86060 + return NULL_TREE;
86061 +
86062 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
86063 + rhs1 = gimple_assign_rhs1(oldstmt);
86064 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
86065 + }
86066 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
86067 + rhs2 = gimple_assign_rhs2(oldstmt);
86068 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
86069 + }
86070 +
86071 + stmt = gimple_copy(oldstmt);
86072 + gimple_set_location(stmt, gimple_location(oldstmt));
86073 +
86074 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
86075 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
86076 +
86077 + if (is_bool(lhs))
86078 + new_var = SSA_NAME_VAR(lhs);
86079 + else
86080 + new_var = create_new_var(signed_size_overflow_type);
86081 + new_var = make_ssa_name(new_var, stmt);
86082 + gimple_set_lhs(stmt, new_var);
86083 +
86084 + if (rhs1 != NULL_TREE) {
86085 + if (!gimple_assign_cast_p(oldstmt))
86086 + rhs1 = cast_a_tree(signed_size_overflow_type, rhs1);
86087 + gimple_assign_set_rhs1(stmt, rhs1);
86088 + }
86089 +
86090 + if (rhs2 != NULL_TREE)
86091 + gimple_assign_set_rhs2(stmt, rhs2);
86092 +#if BUILDING_GCC_VERSION >= 4007
86093 + if (rhs3 != NULL_TREE)
86094 + gimple_assign_set_rhs3(stmt, rhs3);
86095 +#endif
86096 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
86097 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
86098 +
86099 + gsi = gsi_for_stmt(oldstmt);
86100 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
86101 + update_stmt(stmt);
86102 + pointer_set_insert(visited, oldstmt);
86103 + return gimple_get_lhs(stmt);
86104 +}
86105 +
86106 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
86107 +{
86108 + basic_block bb;
86109 + gimple phi;
86110 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
86111 +
86112 + bb = gsi_bb(gsi);
86113 +
86114 + phi = create_phi_node(var, bb);
86115 + gsi = gsi_last(phi_nodes(bb));
86116 + gsi_remove(&gsi, false);
86117 +
86118 + gsi = gsi_for_stmt(oldstmt);
86119 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
86120 + gimple_set_bb(phi, bb);
86121 + return phi;
86122 +}
86123 +
86124 +static tree signed_cast_constant(tree node)
86125 +{
86126 + gcc_assert(is_gimple_constant(node));
86127 +
86128 + return cast_a_tree(signed_size_overflow_type, node);
86129 +}
86130 +
86131 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
86132 +{
86133 + basic_block bb;
86134 + gimple newstmt, def_stmt;
86135 + gimple_stmt_iterator gsi;
86136 +
86137 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
86138 + if (TREE_CODE(arg) == SSA_NAME) {
86139 + def_stmt = get_def_stmt(arg);
86140 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
86141 + gsi = gsi_for_stmt(def_stmt);
86142 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
86143 + return newstmt;
86144 + }
86145 + }
86146 +
86147 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
86148 + gsi = gsi_after_labels(bb);
86149 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
86150 + return newstmt;
86151 +}
86152 +
86153 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
86154 +{
86155 + gimple newstmt;
86156 + gimple_stmt_iterator gsi;
86157 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
86158 + gimple def_newstmt = get_def_stmt(new_rhs);
86159 +
86160 + gsi_insert = gsi_insert_after;
86161 + gsi = gsi_for_stmt(def_newstmt);
86162 +
86163 + switch (gimple_code(get_def_stmt(arg))) {
86164 + case GIMPLE_PHI:
86165 + newstmt = gimple_build_assign(new_var, new_rhs);
86166 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
86167 + gsi_insert = gsi_insert_before;
86168 + break;
86169 + case GIMPLE_ASM:
86170 + case GIMPLE_CALL:
86171 + newstmt = gimple_build_assign(new_var, new_rhs);
86172 + break;
86173 + case GIMPLE_ASSIGN:
86174 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
86175 + break;
86176 + default:
86177 + /* unknown gimple_code (handle_build_new_phi_arg) */
86178 + gcc_unreachable();
86179 + }
86180 +
86181 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
86182 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
86183 + update_stmt(newstmt);
86184 + return newstmt;
86185 +}
86186 +
86187 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
86188 +{
86189 + gimple newstmt;
86190 + tree new_rhs;
86191 +
86192 + new_rhs = expand(visited, potentionally_overflowed, arg);
86193 +
86194 + if (new_rhs == NULL_TREE)
86195 + return NULL_TREE;
86196 +
86197 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
86198 + return gimple_get_lhs(newstmt);
86199 +}
86200 +
86201 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
86202 +{
86203 + gimple phi;
86204 + tree new_var = create_new_var(signed_size_overflow_type);
86205 + unsigned int i, n = gimple_phi_num_args(oldstmt);
86206 +
86207 + pointer_set_insert(visited, oldstmt);
86208 + phi = overflow_create_phi_node(oldstmt, new_var);
86209 + for (i = 0; i < n; i++) {
86210 + tree arg, lhs;
86211 +
86212 + arg = gimple_phi_arg_def(oldstmt, i);
86213 + if (is_gimple_constant(arg))
86214 + arg = signed_cast_constant(arg);
86215 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
86216 + if (lhs == NULL_TREE)
86217 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
86218 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
86219 + }
86220 +
86221 + update_stmt(phi);
86222 + return gimple_phi_result(phi);
86223 +}
86224 +
86225 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
86226 +{
86227 + gimple def_stmt = get_def_stmt(var);
86228 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
86229 +
86230 + *potentionally_overflowed = true;
86231 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
86232 + if (new_rhs1 == NULL_TREE) {
86233 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
86234 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
86235 + else
86236 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
86237 + }
86238 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
86239 +}
86240 +
86241 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
86242 +{
86243 + gimple def_stmt = get_def_stmt(var);
86244 + tree rhs1 = gimple_assign_rhs1(def_stmt);
86245 +
86246 + if (is_gimple_constant(rhs1))
86247 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast_constant(rhs1), NULL_TREE, NULL_TREE);
86248 +
86249 + switch (TREE_CODE(rhs1)) {
86250 + case SSA_NAME:
86251 + return handle_unary_rhs(visited, potentionally_overflowed, var);
86252 +
86253 + case ARRAY_REF:
86254 + case BIT_FIELD_REF:
86255 + case ADDR_EXPR:
86256 + case COMPONENT_REF:
86257 + case COND_EXPR:
86258 + case INDIRECT_REF:
86259 +#if BUILDING_GCC_VERSION >= 4006
86260 + case MEM_REF:
86261 +#endif
86262 + case PARM_DECL:
86263 + case TARGET_MEM_REF:
86264 + case VAR_DECL:
86265 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
86266 +
86267 + default:
86268 + debug_gimple_stmt(def_stmt);
86269 + debug_tree(rhs1);
86270 + gcc_unreachable();
86271 + }
86272 +}
86273 +
86274 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
86275 +{
86276 + gimple cond_stmt;
86277 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
86278 +
86279 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
86280 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
86281 + update_stmt(cond_stmt);
86282 +}
86283 +
86284 +static tree create_string_param(tree string)
86285 +{
86286 + tree i_type, a_type;
86287 + int length = TREE_STRING_LENGTH(string);
86288 +
86289 + gcc_assert(length > 0);
86290 +
86291 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
86292 + a_type = build_array_type(char_type_node, i_type);
86293 +
86294 + TREE_TYPE(string) = a_type;
86295 + TREE_CONSTANT(string) = 1;
86296 + TREE_READONLY(string) = 1;
86297 +
86298 + return build1(ADDR_EXPR, ptr_type_node, string);
86299 +}
86300 +
86301 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
86302 +{
86303 + gimple func_stmt, def_stmt;
86304 + tree current_func, loc_file, loc_line;
86305 + expanded_location xloc;
86306 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
86307 +
86308 + def_stmt = get_def_stmt(arg);
86309 + xloc = expand_location(gimple_location(def_stmt));
86310 +
86311 + if (!gimple_has_location(def_stmt)) {
86312 + xloc = expand_location(gimple_location(stmt));
86313 + if (!gimple_has_location(stmt))
86314 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
86315 + }
86316 +
86317 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
86318 +
86319 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
86320 + loc_file = create_string_param(loc_file);
86321 +
86322 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
86323 + current_func = create_string_param(current_func);
86324 +
86325 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
86326 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
86327 +
86328 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
86329 +}
86330 +
86331 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
86332 +{
86333 + basic_block cond_bb, join_bb, bb_true;
86334 + edge e;
86335 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
86336 +// location_t loc = gimple_location(stmt);
86337 +
86338 + cond_bb = gimple_bb(stmt);
86339 + gsi_prev(&gsi);
86340 + if (gsi_end_p(gsi))
86341 + e = split_block_after_labels(cond_bb);
86342 + else
86343 + e = split_block(cond_bb, gsi_stmt(gsi));
86344 + cond_bb = e->src;
86345 + join_bb = e->dest;
86346 + e->flags = EDGE_FALSE_VALUE;
86347 + e->probability = REG_BR_PROB_BASE;
86348 +
86349 + bb_true = create_empty_bb(cond_bb);
86350 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
86351 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
86352 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
86353 +
86354 + if (dom_info_available_p(CDI_DOMINATORS)) {
86355 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
86356 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
86357 + }
86358 +
86359 + if (current_loops != NULL) {
86360 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
86361 + add_bb_to_loop(bb_true, cond_bb->loop_father);
86362 + }
86363 +
86364 + insert_cond(cond_bb, arg, cond_code, type_value);
86365 + insert_cond_result(bb_true, stmt, arg);
86366 +
86367 +// inform(loc, "Integer size_overflow check applied here.");
86368 +}
86369 +
86370 +static tree get_type_for_check(tree rhs)
86371 +{
86372 + tree def_rhs;
86373 + gimple def_stmt = get_def_stmt(rhs);
86374 +
86375 + if (!gimple_assign_cast_p(def_stmt))
86376 + return TREE_TYPE(rhs);
86377 + def_rhs = gimple_assign_rhs1(def_stmt);
86378 + if (TREE_CODE(TREE_TYPE(def_rhs)) == INTEGER_TYPE)
86379 + return TREE_TYPE(def_rhs);
86380 + return TREE_TYPE(rhs);
86381 +}
86382 +
86383 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
86384 +{
86385 + gimple ucast_stmt;
86386 + gimple_stmt_iterator gsi;
86387 + location_t loc = gimple_location(stmt);
86388 +
86389 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
86390 + gsi = gsi_for_stmt(stmt);
86391 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
86392 + return ucast_stmt;
86393 +}
86394 +
86395 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
86396 +{
86397 + tree type_max, type_min, rhs_type;
86398 + gimple ucast_stmt;
86399 +
86400 + if (!*potentionally_overflowed)
86401 + return;
86402 +
86403 + rhs_type = get_type_for_check(rhs);
86404 +
86405 + if (TYPE_UNSIGNED(rhs_type)) {
86406 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
86407 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
86408 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
86409 + } else {
86410 + type_max = cast_a_tree(signed_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
86411 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
86412 +
86413 + type_min = cast_a_tree(signed_size_overflow_type, TYPE_MIN_VALUE(rhs_type));
86414 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
86415 + }
86416 +}
86417 +
86418 +static tree change_assign_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree orig_rhs)
86419 +{
86420 + gimple assign;
86421 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
86422 + tree new_rhs, origtype = TREE_TYPE(orig_rhs);
86423 +
86424 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
86425 +
86426 + new_rhs = expand(visited, potentionally_overflowed, orig_rhs);
86427 + if (new_rhs == NULL_TREE)
86428 + return NULL_TREE;
86429 +
86430 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
86431 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
86432 + update_stmt(assign);
86433 + return gimple_get_lhs(assign);
86434 +}
86435 +
86436 +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))
86437 +{
86438 + tree new_rhs, cast_rhs;
86439 +
86440 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
86441 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
86442 +
86443 + new_rhs = change_assign_rhs(visited, potentionally_overflowed, def_stmt, rhs);
86444 + if (new_rhs != NULL_TREE) {
86445 + gimple_assign_set_rhs(def_stmt, new_rhs);
86446 + update_stmt(def_stmt);
86447 +
86448 + cast_rhs = gimple_assign_rhs1(get_def_stmt(new_rhs));
86449 +
86450 + check_size_overflow(def_stmt, cast_rhs, rhs, potentionally_overflowed);
86451 + }
86452 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
86453 +}
86454 +
86455 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
86456 +{
86457 + tree rhs1, rhs2;
86458 + gimple def_stmt = get_def_stmt(var);
86459 + tree new_rhs1 = NULL_TREE;
86460 + tree new_rhs2 = NULL_TREE;
86461 +
86462 + rhs1 = gimple_assign_rhs1(def_stmt);
86463 + rhs2 = gimple_assign_rhs2(def_stmt);
86464 +
86465 + /* no DImode/TImode division in the 32/64 bit kernel */
86466 + switch (gimple_assign_rhs_code(def_stmt)) {
86467 + case RDIV_EXPR:
86468 + case TRUNC_DIV_EXPR:
86469 + case CEIL_DIV_EXPR:
86470 + case FLOOR_DIV_EXPR:
86471 + case ROUND_DIV_EXPR:
86472 + case TRUNC_MOD_EXPR:
86473 + case CEIL_MOD_EXPR:
86474 + case FLOOR_MOD_EXPR:
86475 + case ROUND_MOD_EXPR:
86476 + case EXACT_DIV_EXPR:
86477 + case POINTER_PLUS_EXPR:
86478 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
86479 + default:
86480 + break;
86481 + }
86482 +
86483 + *potentionally_overflowed = true;
86484 +
86485 + if (TREE_CODE(rhs1) == SSA_NAME)
86486 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
86487 + if (TREE_CODE(rhs2) == SSA_NAME)
86488 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
86489 +
86490 + if (is_gimple_constant(rhs2))
86491 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, signed_cast_constant(rhs2), &gimple_assign_set_rhs1);
86492 +
86493 + if (is_gimple_constant(rhs1))
86494 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, signed_cast_constant(rhs1), new_rhs2, &gimple_assign_set_rhs2);
86495 +
86496 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
86497 +}
86498 +
86499 +#if BUILDING_GCC_VERSION >= 4007
86500 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
86501 +{
86502 + if (is_gimple_constant(rhs))
86503 + return signed_cast_constant(rhs);
86504 + if (TREE_CODE(rhs) != SSA_NAME)
86505 + return NULL_TREE;
86506 + return expand(visited, potentionally_overflowed, rhs);
86507 +}
86508 +
86509 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
86510 +{
86511 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
86512 + gimple def_stmt = get_def_stmt(var);
86513 +
86514 + *potentionally_overflowed = true;
86515 +
86516 + rhs1 = gimple_assign_rhs1(def_stmt);
86517 + rhs2 = gimple_assign_rhs2(def_stmt);
86518 + rhs3 = gimple_assign_rhs3(def_stmt);
86519 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
86520 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
86521 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
86522 +
86523 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
86524 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
86525 + error("handle_ternary_ops: unknown rhs");
86526 + gcc_unreachable();
86527 +}
86528 +#endif
86529 +
86530 +static void set_size_overflow_type(tree node)
86531 +{
86532 + switch (TYPE_MODE(TREE_TYPE(node))) {
86533 + case SImode:
86534 + signed_size_overflow_type = intDI_type_node;
86535 + unsigned_size_overflow_type = unsigned_intDI_type_node;
86536 + break;
86537 + case DImode:
86538 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
86539 + signed_size_overflow_type = intDI_type_node;
86540 + unsigned_size_overflow_type = unsigned_intDI_type_node;
86541 + } else {
86542 + signed_size_overflow_type = intTI_type_node;
86543 + unsigned_size_overflow_type = unsigned_intTI_type_node;
86544 + }
86545 + break;
86546 + default:
86547 + error("set_size_overflow_type: unsupported gcc configuration.");
86548 + gcc_unreachable();
86549 + }
86550 +}
86551 +
86552 +static tree expand_visited(gimple def_stmt)
86553 +{
86554 + gimple tmp;
86555 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
86556 +
86557 + gsi_next(&gsi);
86558 + tmp = gsi_stmt(gsi);
86559 + switch (gimple_code(tmp)) {
86560 + case GIMPLE_ASSIGN:
86561 + return gimple_get_lhs(tmp);
86562 + case GIMPLE_PHI:
86563 + return gimple_phi_result(tmp);
86564 + case GIMPLE_CALL:
86565 + return gimple_call_lhs(tmp);
86566 + default:
86567 + return NULL_TREE;
86568 + }
86569 +}
86570 +
86571 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
86572 +{
86573 + gimple def_stmt;
86574 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
86575 +
86576 + if (is_gimple_constant(var))
86577 + return NULL_TREE;
86578 +
86579 + if (TREE_CODE(var) == ADDR_EXPR)
86580 + return NULL_TREE;
86581 +
86582 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE);
86583 + if (code != INTEGER_TYPE)
86584 + return NULL_TREE;
86585 +
86586 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
86587 + check_missing_attribute(var);
86588 + return NULL_TREE;
86589 + }
86590 +
86591 + def_stmt = get_def_stmt(var);
86592 +
86593 + if (!def_stmt)
86594 + return NULL_TREE;
86595 +
86596 + if (pointer_set_contains(visited, def_stmt))
86597 + return expand_visited(def_stmt);
86598 +
86599 + switch (gimple_code(def_stmt)) {
86600 + case GIMPLE_NOP:
86601 + check_missing_attribute(var);
86602 + return NULL_TREE;
86603 + case GIMPLE_PHI:
86604 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
86605 + case GIMPLE_CALL:
86606 + case GIMPLE_ASM:
86607 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
86608 + case GIMPLE_ASSIGN:
86609 + switch (gimple_num_ops(def_stmt)) {
86610 + case 2:
86611 + return handle_unary_ops(visited, potentionally_overflowed, var);
86612 + case 3:
86613 + return handle_binary_ops(visited, potentionally_overflowed, var);
86614 +#if BUILDING_GCC_VERSION >= 4007
86615 + case 4:
86616 + return handle_ternary_ops(visited, potentionally_overflowed, var);
86617 +#endif
86618 + }
86619 + default:
86620 + debug_gimple_stmt(def_stmt);
86621 + error("expand: unknown gimple code");
86622 + gcc_unreachable();
86623 + }
86624 +}
86625 +
86626 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
86627 +{
86628 + gimple assign;
86629 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
86630 + tree origtype = TREE_TYPE(origarg);
86631 +
86632 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
86633 +
86634 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
86635 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
86636 + update_stmt(assign);
86637 +
86638 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
86639 + update_stmt(stmt);
86640 +}
86641 +
86642 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
86643 +{
86644 + const char *origid;
86645 + tree arg, origarg;
86646 +
86647 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
86648 + gcc_assert(gimple_call_num_args(stmt) > argnum);
86649 + return gimple_call_arg(stmt, argnum);
86650 + }
86651 +
86652 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
86653 + while (origarg && argnum) {
86654 + argnum--;
86655 + origarg = TREE_CHAIN(origarg);
86656 + }
86657 +
86658 + gcc_assert(argnum == 0);
86659 +
86660 + gcc_assert(origarg != NULL_TREE);
86661 + origid = NAME(origarg);
86662 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
86663 + if (!strcmp(origid, NAME(arg)))
86664 + return arg;
86665 + }
86666 + return NULL_TREE;
86667 +}
86668 +
86669 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
86670 +{
86671 + struct pointer_set_t *visited;
86672 + tree arg, newarg, type_max;
86673 + gimple ucast_stmt;
86674 + bool potentionally_overflowed;
86675 +
86676 + arg = get_function_arg(argnum, stmt, fndecl);
86677 + if (arg == NULL_TREE)
86678 + return;
86679 +
86680 + if (is_gimple_constant(arg))
86681 + return;
86682 + if (TREE_CODE(arg) != SSA_NAME)
86683 + return;
86684 +
86685 + check_arg_type(arg);
86686 +
86687 + set_size_overflow_type(arg);
86688 +
86689 + visited = pointer_set_create();
86690 + potentionally_overflowed = false;
86691 + newarg = expand(visited, &potentionally_overflowed, arg);
86692 + pointer_set_destroy(visited);
86693 +
86694 + if (newarg == NULL_TREE || !potentionally_overflowed)
86695 + return;
86696 +
86697 + change_function_arg(stmt, arg, argnum, newarg);
86698 +
86699 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, newarg);
86700 +
86701 + type_max = build_int_cstu(unsigned_size_overflow_type, 0x7fffffff);
86702 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
86703 +}
86704 +
86705 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
86706 +{
86707 + tree p = TREE_VALUE(attr);
86708 + do {
86709 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
86710 + p = TREE_CHAIN(p);
86711 + } while (p);
86712 +}
86713 +
86714 +static void handle_function_by_hash(gimple stmt, tree fndecl)
86715 +{
86716 + struct size_overflow_hash *hash;
86717 + expanded_location xloc;
86718 +
86719 + hash = get_function_hash(fndecl);
86720 + xloc = expand_location(DECL_SOURCE_LOCATION(fndecl));
86721 +
86722 + fndecl = get_original_function_decl(fndecl);
86723 + if (!hash->name)
86724 + return;
86725 + if (file_match && !hash->file)
86726 + return;
86727 + if (strcmp(hash->name, NAME(fndecl)))
86728 + return;
86729 + if (file_match && strcmp(hash->file, xloc.file))
86730 + return;
86731 +
86732 +#define search_param(argnum) \
86733 + if (hash->param##argnum) \
86734 + handle_function_arg(stmt, fndecl, argnum - 1);
86735 +
86736 + search_param(1);
86737 + search_param(2);
86738 + search_param(3);
86739 + search_param(4);
86740 + search_param(5);
86741 + search_param(6);
86742 + search_param(7);
86743 + search_param(8);
86744 + search_param(9);
86745 +#undef search_param
86746 +}
86747 +
86748 +static unsigned int handle_function(void)
86749 +{
86750 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
86751 + int saved_last_basic_block = last_basic_block;
86752 +
86753 + do {
86754 + gimple_stmt_iterator gsi;
86755 + basic_block next = bb->next_bb;
86756 +
86757 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86758 + tree fndecl, attr;
86759 + gimple stmt = gsi_stmt(gsi);
86760 +
86761 + if (!(is_gimple_call(stmt)))
86762 + continue;
86763 + fndecl = gimple_call_fndecl(stmt);
86764 + if (fndecl == NULL_TREE)
86765 + continue;
86766 + if (gimple_call_num_args(stmt) == 0)
86767 + continue;
86768 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
86769 + if (!attr || !TREE_VALUE(attr))
86770 + handle_function_by_hash(stmt, fndecl);
86771 + else
86772 + handle_function_by_attribute(stmt, attr, fndecl);
86773 + gsi = gsi_for_stmt(stmt);
86774 + }
86775 + bb = next;
86776 + } while (bb && bb->index <= saved_last_basic_block);
86777 + return 0;
86778 +}
86779 +
86780 +static struct gimple_opt_pass size_overflow_pass = {
86781 + .pass = {
86782 + .type = GIMPLE_PASS,
86783 + .name = "size_overflow",
86784 + .gate = NULL,
86785 + .execute = handle_function,
86786 + .sub = NULL,
86787 + .next = NULL,
86788 + .static_pass_number = 0,
86789 + .tv_id = TV_NONE,
86790 + .properties_required = PROP_cfg | PROP_referenced_vars,
86791 + .properties_provided = 0,
86792 + .properties_destroyed = 0,
86793 + .todo_flags_start = 0,
86794 + .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
86795 + }
86796 +};
86797 +
86798 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
86799 +{
86800 + tree fntype;
86801 +
86802 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
86803 +
86804 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
86805 + fntype = build_function_type_list(void_type_node,
86806 + const_char_ptr_type_node,
86807 + unsigned_type_node,
86808 + const_char_ptr_type_node,
86809 + NULL_TREE);
86810 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
86811 +
86812 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
86813 + TREE_PUBLIC(report_size_overflow_decl) = 1;
86814 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
86815 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
86816 +}
86817 +
86818 +extern struct gimple_opt_pass pass_dce;
86819 +
86820 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86821 +{
86822 + int i;
86823 + const char * const plugin_name = plugin_info->base_name;
86824 + const int argc = plugin_info->argc;
86825 + const struct plugin_argument * const argv = plugin_info->argv;
86826 + bool enable = true;
86827 +
86828 + struct register_pass_info size_overflow_pass_info = {
86829 + .pass = &size_overflow_pass.pass,
86830 + .reference_pass_name = "ssa",
86831 + .ref_pass_instance_number = 1,
86832 + .pos_op = PASS_POS_INSERT_AFTER
86833 + };
86834 +
86835 + if (!plugin_default_version_check(version, &gcc_version)) {
86836 + error(G_("incompatible gcc/plugin versions"));
86837 + return 1;
86838 + }
86839 +
86840 + for (i = 0; i < argc; ++i) {
86841 + if (!strcmp(argv[i].key, "no-size-overflow")) {
86842 + enable = false;
86843 + continue;
86844 + } else if (!(strcmp(argv[i].key, "no-file-match"))) {
86845 + file_match = false;
86846 + continue;
86847 + }
86848 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86849 + }
86850 +
86851 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
86852 + if (enable) {
86853 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
86854 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
86855 + }
86856 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86857 +
86858 + return 0;
86859 +}
86860 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
86861 new file mode 100644
86862 index 0000000..b87ec9d
86863 --- /dev/null
86864 +++ b/tools/gcc/stackleak_plugin.c
86865 @@ -0,0 +1,313 @@
86866 +/*
86867 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
86868 + * Licensed under the GPL v2
86869 + *
86870 + * Note: the choice of the license means that the compilation process is
86871 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86872 + * but for the kernel it doesn't matter since it doesn't link against
86873 + * any of the gcc libraries
86874 + *
86875 + * gcc plugin to help implement various PaX features
86876 + *
86877 + * - track lowest stack pointer
86878 + *
86879 + * TODO:
86880 + * - initialize all local variables
86881 + *
86882 + * BUGS:
86883 + * - none known
86884 + */
86885 +#include "gcc-plugin.h"
86886 +#include "config.h"
86887 +#include "system.h"
86888 +#include "coretypes.h"
86889 +#include "tree.h"
86890 +#include "tree-pass.h"
86891 +#include "flags.h"
86892 +#include "intl.h"
86893 +#include "toplev.h"
86894 +#include "plugin.h"
86895 +//#include "expr.h" where are you...
86896 +#include "diagnostic.h"
86897 +#include "plugin-version.h"
86898 +#include "tm.h"
86899 +#include "function.h"
86900 +#include "basic-block.h"
86901 +#include "gimple.h"
86902 +#include "rtl.h"
86903 +#include "emit-rtl.h"
86904 +
86905 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86906 +
86907 +int plugin_is_GPL_compatible;
86908 +
86909 +static int track_frame_size = -1;
86910 +static const char track_function[] = "pax_track_stack";
86911 +static const char check_function[] = "pax_check_alloca";
86912 +static bool init_locals;
86913 +
86914 +static struct plugin_info stackleak_plugin_info = {
86915 + .version = "201203140940",
86916 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
86917 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
86918 +};
86919 +
86920 +static bool gate_stackleak_track_stack(void);
86921 +static unsigned int execute_stackleak_tree_instrument(void);
86922 +static unsigned int execute_stackleak_final(void);
86923 +
86924 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
86925 + .pass = {
86926 + .type = GIMPLE_PASS,
86927 + .name = "stackleak_tree_instrument",
86928 + .gate = gate_stackleak_track_stack,
86929 + .execute = execute_stackleak_tree_instrument,
86930 + .sub = NULL,
86931 + .next = NULL,
86932 + .static_pass_number = 0,
86933 + .tv_id = TV_NONE,
86934 + .properties_required = PROP_gimple_leh | PROP_cfg,
86935 + .properties_provided = 0,
86936 + .properties_destroyed = 0,
86937 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
86938 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
86939 + }
86940 +};
86941 +
86942 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
86943 + .pass = {
86944 + .type = RTL_PASS,
86945 + .name = "stackleak_final",
86946 + .gate = gate_stackleak_track_stack,
86947 + .execute = execute_stackleak_final,
86948 + .sub = NULL,
86949 + .next = NULL,
86950 + .static_pass_number = 0,
86951 + .tv_id = TV_NONE,
86952 + .properties_required = 0,
86953 + .properties_provided = 0,
86954 + .properties_destroyed = 0,
86955 + .todo_flags_start = 0,
86956 + .todo_flags_finish = TODO_dump_func
86957 + }
86958 +};
86959 +
86960 +static bool gate_stackleak_track_stack(void)
86961 +{
86962 + return track_frame_size >= 0;
86963 +}
86964 +
86965 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
86966 +{
86967 + gimple check_alloca;
86968 + tree fntype, fndecl, alloca_size;
86969 +
86970 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
86971 + fndecl = build_fn_decl(check_function, fntype);
86972 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
86973 +
86974 + // insert call to void pax_check_alloca(unsigned long size)
86975 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
86976 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
86977 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
86978 +}
86979 +
86980 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
86981 +{
86982 + gimple track_stack;
86983 + tree fntype, fndecl;
86984 +
86985 + fntype = build_function_type_list(void_type_node, NULL_TREE);
86986 + fndecl = build_fn_decl(track_function, fntype);
86987 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
86988 +
86989 + // insert call to void pax_track_stack(void)
86990 + track_stack = gimple_build_call(fndecl, 0);
86991 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
86992 +}
86993 +
86994 +#if BUILDING_GCC_VERSION == 4005
86995 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
86996 +{
86997 + tree fndecl;
86998 +
86999 + if (!is_gimple_call(stmt))
87000 + return false;
87001 + fndecl = gimple_call_fndecl(stmt);
87002 + if (!fndecl)
87003 + return false;
87004 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
87005 + return false;
87006 +// print_node(stderr, "pax", fndecl, 4);
87007 + return DECL_FUNCTION_CODE(fndecl) == code;
87008 +}
87009 +#endif
87010 +
87011 +static bool is_alloca(gimple stmt)
87012 +{
87013 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
87014 + return true;
87015 +
87016 +#if BUILDING_GCC_VERSION >= 4007
87017 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
87018 + return true;
87019 +#endif
87020 +
87021 + return false;
87022 +}
87023 +
87024 +static unsigned int execute_stackleak_tree_instrument(void)
87025 +{
87026 + basic_block bb, entry_bb;
87027 + bool prologue_instrumented = false, is_leaf = true;
87028 +
87029 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
87030 +
87031 + // 1. loop through BBs and GIMPLE statements
87032 + FOR_EACH_BB(bb) {
87033 + gimple_stmt_iterator gsi;
87034 +
87035 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
87036 + gimple stmt;
87037 +
87038 + stmt = gsi_stmt(gsi);
87039 +
87040 + if (is_gimple_call(stmt))
87041 + is_leaf = false;
87042 +
87043 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
87044 + if (!is_alloca(stmt))
87045 + continue;
87046 +
87047 + // 2. insert stack overflow check before each __builtin_alloca call
87048 + stackleak_check_alloca(&gsi);
87049 +
87050 + // 3. insert track call after each __builtin_alloca call
87051 + stackleak_add_instrumentation(&gsi);
87052 + if (bb == entry_bb)
87053 + prologue_instrumented = true;
87054 + }
87055 + }
87056 +
87057 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
87058 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
87059 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
87060 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
87061 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
87062 + return 0;
87063 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
87064 + return 0;
87065 +
87066 + // 4. insert track call at the beginning
87067 + if (!prologue_instrumented) {
87068 + gimple_stmt_iterator gsi;
87069 +
87070 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
87071 + if (dom_info_available_p(CDI_DOMINATORS))
87072 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
87073 + gsi = gsi_start_bb(bb);
87074 + stackleak_add_instrumentation(&gsi);
87075 + }
87076 +
87077 + return 0;
87078 +}
87079 +
87080 +static unsigned int execute_stackleak_final(void)
87081 +{
87082 + rtx insn;
87083 +
87084 + if (cfun->calls_alloca)
87085 + return 0;
87086 +
87087 + // keep calls only if function frame is big enough
87088 + if (get_frame_size() >= track_frame_size)
87089 + return 0;
87090 +
87091 + // 1. find pax_track_stack calls
87092 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
87093 + // 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))
87094 + rtx body;
87095 +
87096 + if (!CALL_P(insn))
87097 + continue;
87098 + body = PATTERN(insn);
87099 + if (GET_CODE(body) != CALL)
87100 + continue;
87101 + body = XEXP(body, 0);
87102 + if (GET_CODE(body) != MEM)
87103 + continue;
87104 + body = XEXP(body, 0);
87105 + if (GET_CODE(body) != SYMBOL_REF)
87106 + continue;
87107 + if (strcmp(XSTR(body, 0), track_function))
87108 + continue;
87109 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
87110 + // 2. delete call
87111 + insn = delete_insn_and_edges(insn);
87112 +#if BUILDING_GCC_VERSION >= 4007
87113 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
87114 + insn = delete_insn_and_edges(insn);
87115 +#endif
87116 + }
87117 +
87118 +// print_simple_rtl(stderr, get_insns());
87119 +// print_rtl(stderr, get_insns());
87120 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
87121 +
87122 + return 0;
87123 +}
87124 +
87125 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87126 +{
87127 + const char * const plugin_name = plugin_info->base_name;
87128 + const int argc = plugin_info->argc;
87129 + const struct plugin_argument * const argv = plugin_info->argv;
87130 + int i;
87131 + struct register_pass_info stackleak_tree_instrument_pass_info = {
87132 + .pass = &stackleak_tree_instrument_pass.pass,
87133 +// .reference_pass_name = "tree_profile",
87134 + .reference_pass_name = "optimized",
87135 + .ref_pass_instance_number = 0,
87136 + .pos_op = PASS_POS_INSERT_BEFORE
87137 + };
87138 + struct register_pass_info stackleak_final_pass_info = {
87139 + .pass = &stackleak_final_rtl_opt_pass.pass,
87140 + .reference_pass_name = "final",
87141 + .ref_pass_instance_number = 0,
87142 + .pos_op = PASS_POS_INSERT_BEFORE
87143 + };
87144 +
87145 + if (!plugin_default_version_check(version, &gcc_version)) {
87146 + error(G_("incompatible gcc/plugin versions"));
87147 + return 1;
87148 + }
87149 +
87150 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
87151 +
87152 + for (i = 0; i < argc; ++i) {
87153 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
87154 + if (!argv[i].value) {
87155 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87156 + continue;
87157 + }
87158 + track_frame_size = atoi(argv[i].value);
87159 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
87160 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
87161 + continue;
87162 + }
87163 + if (!strcmp(argv[i].key, "initialize-locals")) {
87164 + if (argv[i].value) {
87165 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
87166 + continue;
87167 + }
87168 + init_locals = true;
87169 + continue;
87170 + }
87171 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87172 + }
87173 +
87174 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
87175 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
87176 +
87177 + return 0;
87178 +}
87179 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
87180 index 6789d78..4afd019 100644
87181 --- a/tools/perf/util/include/asm/alternative-asm.h
87182 +++ b/tools/perf/util/include/asm/alternative-asm.h
87183 @@ -5,4 +5,7 @@
87184
87185 #define altinstruction_entry #
87186
87187 + .macro pax_force_retaddr rip=0, reload=0
87188 + .endm
87189 +
87190 #endif
87191 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
87192 index af0f22f..9a7d479 100644
87193 --- a/usr/gen_init_cpio.c
87194 +++ b/usr/gen_init_cpio.c
87195 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
87196 int retval;
87197 int rc = -1;
87198 int namesize;
87199 - int i;
87200 + unsigned int i;
87201
87202 mode |= S_IFREG;
87203
87204 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
87205 *env_var = *expanded = '\0';
87206 strncat(env_var, start + 2, end - start - 2);
87207 strncat(expanded, new_location, start - new_location);
87208 - strncat(expanded, getenv(env_var), PATH_MAX);
87209 - strncat(expanded, end + 1, PATH_MAX);
87210 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
87211 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
87212 strncpy(new_location, expanded, PATH_MAX);
87213 + new_location[PATH_MAX] = 0;
87214 } else
87215 break;
87216 }
87217 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
87218 index 7858228..2919715 100644
87219 --- a/virt/kvm/kvm_main.c
87220 +++ b/virt/kvm/kvm_main.c
87221 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
87222
87223 static cpumask_var_t cpus_hardware_enabled;
87224 static int kvm_usage_count = 0;
87225 -static atomic_t hardware_enable_failed;
87226 +static atomic_unchecked_t hardware_enable_failed;
87227
87228 struct kmem_cache *kvm_vcpu_cache;
87229 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
87230 @@ -2318,7 +2318,7 @@ static void hardware_enable_nolock(void *junk)
87231
87232 if (r) {
87233 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
87234 - atomic_inc(&hardware_enable_failed);
87235 + atomic_inc_unchecked(&hardware_enable_failed);
87236 printk(KERN_INFO "kvm: enabling virtualization on "
87237 "CPU%d failed\n", cpu);
87238 }
87239 @@ -2372,10 +2372,10 @@ static int hardware_enable_all(void)
87240
87241 kvm_usage_count++;
87242 if (kvm_usage_count == 1) {
87243 - atomic_set(&hardware_enable_failed, 0);
87244 + atomic_set_unchecked(&hardware_enable_failed, 0);
87245 on_each_cpu(hardware_enable_nolock, NULL, 1);
87246
87247 - if (atomic_read(&hardware_enable_failed)) {
87248 + if (atomic_read_unchecked(&hardware_enable_failed)) {
87249 hardware_disable_all_nolock();
87250 r = -EBUSY;
87251 }
87252 @@ -2738,7 +2738,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
87253 kvm_arch_vcpu_put(vcpu);
87254 }
87255
87256 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
87257 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
87258 struct module *module)
87259 {
87260 int r;
87261 @@ -2801,7 +2801,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
87262 if (!vcpu_align)
87263 vcpu_align = __alignof__(struct kvm_vcpu);
87264 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
87265 - 0, NULL);
87266 + SLAB_USERCOPY, NULL);
87267 if (!kvm_vcpu_cache) {
87268 r = -ENOMEM;
87269 goto out_free_3;
87270 @@ -2811,9 +2811,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
87271 if (r)
87272 goto out_free;
87273
87274 - kvm_chardev_ops.owner = module;
87275 - kvm_vm_fops.owner = module;
87276 - kvm_vcpu_fops.owner = module;
87277 + pax_open_kernel();
87278 + *(void **)&kvm_chardev_ops.owner = module;
87279 + *(void **)&kvm_vm_fops.owner = module;
87280 + *(void **)&kvm_vcpu_fops.owner = module;
87281 + pax_close_kernel();
87282
87283 r = misc_register(&kvm_dev);
87284 if (r) {